Переглянути джерело

获取当前用户的评论和回复 @接口优化

fangqing 1 місяць тому
батько
коміт
8936a293e1

+ 19 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -106,6 +106,8 @@ public class CommunityCommentController extends BaseController {
     @Autowired
     private CommunityReportController communityReportController;
 
+    @Autowired
+    private CommunityCommentController communityCommentController;
     /**
      * 获取文章评论
      */
@@ -588,7 +590,23 @@ public class CommunityCommentController extends BaseController {
         int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
         int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 1);
         int offset = (pageNum - 1) * pageSize;
-        return success(communityArticleCommentService.getCommentInfoByUserId(userId,offset,pageSize,searchType));
+
+        List<CommentVo> commentInfoByUserId  = new ArrayList<>();
+        try {
+            commentInfoByUserId = communityArticleCommentService.getCommentInfoByUserId(userId, offset, pageSize, searchType);
+            for (CommentVo commentVo : commentInfoByUserId) {
+                String type = String.valueOf(commentVo.getType());
+                String id = String.valueOf(commentVo.getId());
+                if (!commentVo.isRead()){
+                    communityCommentController.updateMsgRead(type,id);
+                }
+            }
+        }catch (Exception e) {
+            //e.printStackTrace();
+            System.out.println(e.getMessage());
+            throw new ProjectException();
+        }
+        return success(commentInfoByUserId);
     }
 
     /**

+ 2 - 1
ruoyi-generator/src/main/resources/mapper/community/CommunityArticleCommentMapper.xml

@@ -232,7 +232,7 @@
             c.is_read,
             c.isLike
         FROM (
-                 SELECT
+            SELECT
                      cac.id,
                      cac.id as joinId,
                      cac.id  as parentReplyId,
@@ -255,6 +255,7 @@
           AND (ca.is_delete IS NULL OR ca.is_delete != 1)
           AND (cac.is_delete IS NULL OR cac.is_delete != 1)
           AND (cac.is_notice != 1 or cac.is_notice is null)
+          AND cac.ID  not in ( select comment_id from community_article_at  caa  where peer_id = #{userId})
 
         UNION ALL