瀏覽代碼

代码优化

fangzhen 5 月之前
父節點
當前提交
0e76aba60f

+ 6 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticle.java

@@ -36,6 +36,12 @@ public class CommunityArticle implements Serializable {
     @ApiModelProperty("文章id")
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
+
+    /**
+     * 文章ids
+     */
+    @TableField(exist = false)
+    private List<Long> articleIds;
     /**
      * 创建人id
      */

+ 10 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -122,6 +122,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         //找出板块下的分类
         List<Long> classIds = communityArticle.getClassIds();
         Long id = communityArticle.getId();
+        List<Long> articleIds = communityArticle.getArticleIds();
         Long userId = SecurityUtils.getUserId();
         List<CommunityArticleVo> communityArticleVos = null;
         if (Objects.nonNull(id)) {
@@ -131,6 +132,15 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             communityArticleMapper.updateById(article);
         }
 
+        if (!articleIds.isEmpty()) {
+            for (Long articleId : articleIds) {
+                //获取指定文章详细内容,文章浏览量+1
+                CommunityArticle article = communityArticleMapper.selectById(articleId);
+                article.setPageViews(article.getPageViews() + 1);
+                communityArticleMapper.updateById(article);
+            }
+        }
+
         //根据分类查找文章
         int offset = (pageNum - 1) * pageSize;
         communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType);

+ 2 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityCollectionServiceImpl.java

@@ -154,7 +154,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
                         }));
 
         if (articleIdsObj.isEmpty()) {
-            return null;
+            return new JSONArray();
         }
 
         //转换object为long
@@ -261,7 +261,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         for (CommunityCollectionVo communityCollectionVo : communityCollectionVos) {
             JSONArray objects = selectArticleInfoInCollection(communityCollectionVo.getId(), 1L);
             Long articleNumber =  0L;
-            if (objects != null){
+            if (!objects.isEmpty()){
                 articleNumber =  objects.getJSONObject(0).getLong("articleNumber");
             }
             communityCollectionVo.setArticleCount(articleNumber);

+ 7 - 0
ruoyi-generator/src/main/resources/mapper/community/ArticleMapper.xml

@@ -197,6 +197,13 @@
                 </foreach>
             </if>
 
+            <if test="communityArticle.articleIds != null and communityArticle.articleIds.size > 0">
+                AND a.id in
+                <foreach collection="communityArticle.articleIds" item="articleId" index="index" open="(" close=")" separator=",">
+                    #{articleId}
+                </foreach>
+            </if>
+
             and (is_delete != 1 or is_delete is null)
         </where>
         group by a.id,a.create_time