Browse Source

1.2.8信息中心根据时间排序查询功能开发

JiangChongBo 2 years ago
parent
commit
46ad0e92fa

+ 2 - 2
src/main/java/com/caimei365/commodity/controller/SearchQueryApi.java

@@ -147,10 +147,10 @@ public class SearchQueryApi {
         @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
     })
     @GetMapping("/article")
-    public ResponseJson<String> queryArticleByKeyword(String keyword,
+    public ResponseJson<String> queryArticleByKeyword(String keyword,Integer status,String startDate,String endDate,
                                            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
-        return searchQueryService.queryArticleByKeyword(keyword, pageNum, pageSize);
+        return searchQueryService.queryArticleByKeyword(keyword, pageNum, pageSize,status,startDate,endDate);
     }
 
     /**

+ 10 - 0
src/main/java/com/caimei365/commodity/mapper/SearchMapper.java

@@ -206,6 +206,16 @@ public interface SearchMapper {
      */
     List<ArticleListVo> queryArticle(@Param("keyword") String keyword, @Param("articleId") Integer articleId, @Param("typeId") Integer typeId, @Param("labelText") String labelText);
 
+    /**
+     * v1.2.8
+     * 根据时间排序
+     * 获取数据库文章
+     *
+     * @param keyword 关键词
+     * @return list
+     */
+    List<ArticleListVo> queryArticleByProDate(@Param("keyword") String keyword, @Param("articleId") Integer articleId, @Param("typeId") Integer typeId, @Param("labelText") String labelText, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
     /**
      * 根据用户ID查找历史记录
      */

+ 1 - 1
src/main/java/com/caimei365/commodity/service/SearchQueryService.java

@@ -74,7 +74,7 @@ public interface SearchQueryService {
      * @param pageSize  每页数量
      * @return JsonStr(list)
      */
-    ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize);
+    ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize,Integer status,String startDate,String endDate);
 
     /**
      * 根据文章ID搜索文章

+ 58 - 2
src/main/java/com/caimei365/commodity/service/impl/SearchQueryServiceImpl.java

@@ -329,7 +329,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
      * @return JsonStr(list)
      */
     @Override
-    public ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize) {
+    public ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize,Integer status,String startDate,String endDate) {
         String queryStr = "article:'" + keyword + "'";
         if (StringUtils.isEmpty(keyword)) {
             queryStr = "a_all:'1'";
@@ -350,7 +350,15 @@ public class SearchQueryServiceImpl implements SearchQueryService {
             return result;
         } else {
             // 阿里云搜索失败,再次从数据库搜索
-            return queryArticleFromDatabase(pageNum, pageSize, keyword, null, null, null);
+            //1.2.8版本新加根据时间排序
+            if(status==1){
+                //综合排序
+                return queryArticleFromDatabase(pageNum, pageSize, keyword, null, null, null);
+            }else {
+                //根据时间排序
+                return queryArticleFromDatabaseByProDate(pageNum, pageSize, keyword, null, null, null,startDate,endDate);
+            }
+
         }
     }
 
@@ -464,6 +472,54 @@ public class SearchQueryServiceImpl implements SearchQueryService {
             return ResponseJson.error("未查询到文档记录(数据库)", null);
         }
     }
+    /**1.2.8新加发布时间排序
+     * 文章查询(数据库)
+     *
+     * @param keyword       关键词
+     * @param articleId     文章Id
+     * @param typeId        分类Id
+     * @param labelId       标签Id
+     * @param num           页码
+     * @param size          每页数量
+     * @param startDate     开始时间
+     * @param endDate       结束时间
+     */
+    private ResponseJson<String> queryArticleFromDatabaseByProDate(int num, int size, String keyword, Integer articleId, Integer typeId, Integer labelId,String startDate,String endDate) {
+        String labelText = null;
+        if (null != labelId){
+            labelText = searchMapper.findLabelNameById(labelId);
+        }
+        PageHelper.startPage(num, size);
+        List<ArticleListVo> articleList = searchMapper.queryArticleByProDate(keyword, articleId, typeId, labelText,startDate,endDate);
+        articleList.forEach(article -> {
+            String imagePath = ImageUtils.getImageURL("", article.getImage(), 0, domain);
+            article.setImage(imagePath);
+            // 搜索供应商文档数据
+            String[] labelTexts = article.getLabelText().split(",");
+            if(labelTexts.length > 0){
+                boolean notEmpty = StringUtil.isNotEmpty(labelTexts[0]);
+                if(notEmpty){
+                    List<Integer> labelIdList = searchMapper.findLabelIdsByName(labelTexts);
+                    StringBuilder labelIds = new StringBuilder();
+                    labelIdList.forEach(id -> {
+                        labelIds.append(",").append(id);
+                    });
+                    article.setLabelIds(labelIds.toString().replaceFirst(",",""));
+                }
+            }
+        });
+        PaginationVo<ArticleListVo> pageData = new PaginationVo<>(articleList);
+        int total = pageData.getTotalRecord();
+        JSONObject pageObj = new JSONObject();
+        pageObj.put("total", total);
+        pageObj.put("items", articleList);
+        log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
+        if (articleList.size()>0) {
+            return ResponseJson.success(pageObj.toString());
+        } else {
+            return ResponseJson.error("未查询到文档记录(数据库)", null);
+        }
+    }
 
     /**
      * 文章查询

+ 39 - 0
src/main/resources/mapper/SearchMapper.xml

@@ -431,6 +431,45 @@
             </otherwise>
         </choose>
     </select>
+    <!-- 搜索容错 文章列表 v1.2.8新加根据时间排序-->
+    <select id="queryArticleByProDate" resultType="com.caimei365.commodity.model.search.ArticleListVo">
+        select
+        a.id as articleId,
+        a.title as title,
+        a.guidanceImage as image,
+        a.publisher as publisher,
+        a.pubdate as publishDate,
+        a.recommendContent as intro,
+        (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
+        a.typeId as typeId,
+        b.name as typeText,
+        a.label as labelText
+        from info as a
+        left join info_type b on a.typeId = b.id
+        left join info_praise c on a.id = c.infoId
+        <where>
+            a.enabledStatus = 1
+            and a.auditStatus = 2
+            <if test="articleId != null">
+                and a.id = #{articleId}
+            </if>
+            <if test="typeId != null">
+                and a.typeId = #{typeId}
+            </if>
+            <if test="keyword != null and keyword != ''">
+                and a.title like concat ('%',#{keyword},'%')
+            </if>
+            <if test="labelText != null">
+                and a.label like concat ('%',#{labelText},'%')
+            </if>
+            <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
+                AND a.pubdate &gt;= #{startDate}  AND a.pubdate &lt;= #{endDate}
+            </if>
+        </where>
+
+         order by a.pubdate desc
+
+    </select>
     <select id="getHistoryList" resultType="com.caimei365.commodity.model.po.SearchHistoryPo">
         select id, userId, searchWord, searchDate, delFlag
         from user_search_history