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

获取文章漂亮回复添加总数据量

fangzhen 6 місяців тому
батько
коміт
9ab8483e6a

+ 8 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityArticleCommentMapper.java

@@ -3,7 +3,15 @@ package com.ruoyi.generator.mapper.community;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.generator.domain.Community.CommunityArticleComment;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 @Mapper
 public interface CommunityArticleCommentMapper extends BaseMapper<CommunityArticleComment> {
+
+    /**
+     * 获取文章评论回复总数
+     * @param articleId 文章id
+     * @return 总数
+     */
+    Integer queryCommentCount(@Param("articleId") Long articleId);
 }

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

@@ -164,6 +164,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             }
             articleVo.setVideoList(videoList);
 
+            //设置评论回复数量
+            articleVo.setCommentCount(communityArticleCommentMapper.queryCommentCount(articleVo.getId()));
             //设置文章的点赞数量
             articleVo.setLikeCount(communityLikeMapper.selectList(new QueryWrapper<CommunityLike>().eq("article_id", articleVo.getId())).size());
             //设置文章的收藏数量
@@ -540,6 +542,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
     /**
      * 根据账户或者用户名称,搜索用户
+     *
      * @param SearchValue
      * @return 用户
      */

+ 4 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityArticleVo.java

@@ -117,6 +117,10 @@ public class CommunityArticleVo extends BaseEntity implements Serializable {
     @TableField("comments")
     private List<Map<String, Object>> comments;
 
+    @ApiModelProperty("评论数量")
+    @TableField("comments")
+    private Integer commentCount;
+
     @ApiModelProperty("文章标签")
     private List<CommunityTag> tags;
 }

+ 17 - 0
ruoyi-generator/src/main/resources/mapper/community/CommunityArticleCommentMapper.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper">
+    <select id="queryCommentCount" resultType="java.lang.Integer">
+        select d.commentCount + d.replyCount
+        from (select c.article_id,
+                     count(1)                            as commentCount,
+                     (select count(1) as replyCount
+                      from community_article_comment a
+                               left join community_comment_reply b on a.id = b.comment_id
+                      where a.article_id = #{articleId}) as replyCount
+              from community_article_comment c
+              where c.article_id = #{articleId}) as d
+    </select>
+</mapper>