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

Merge remote-tracking branch 'origin/dev' into dev

fangqing 5 місяців тому
батько
коміт
5f24c65491

+ 2 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -96,7 +96,7 @@ public class CommonController {
 
             if ("image".equalsIgnoreCase(fileType)) {
                 //获取用户名
-                String username = SecurityUtils.getUsername();
+                String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
                 // 原始文件
                 if (fileName.contains("/profile/upload")) {
                     fileName = fileName.replace("/profile/upload", "");
@@ -107,7 +107,7 @@ public class CommonController {
                 String watermarkFileName = "watermark_" + fileName;
                 File destFile = new File(filePath + fileName);
                 // 加水印
-                ImageUtils.addWatermark(sourceFile, destFile, "@" + username, "次元时代-ACG爱好者社区");
+                ImageUtils.addWatermark(sourceFile, destFile, "@" + nickName, "次元时代-ACG爱好者社区");
                 fileName = watermarkFileName;
             }
 

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java

@@ -64,7 +64,7 @@ public class UserConstants
     public final static String USER_PREFIX = "冒险家-";
 
     /** 用户默认头像 */
-    public final static String USER_AVATAR = "http://47.122.10.161:8084/profile/upload/2024/10/20/默认头像_20241020145455A002.jpg";
+    public final static String USER_AVATAR = "/profile/upload/2024/12/31/默认头像_20241231160922A037.png";
 
     /** 校验是否唯一的返回标识 */
     public final static boolean UNIQUE = true;

+ 22 - 1
ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java

@@ -9,9 +9,11 @@ import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
 
+import java.util.concurrent.ExecutionException;
+
 /**
  * 获取地址类
- * 
+ *
  * @author ruoyi
  */
 public class AddressUtils
@@ -53,4 +55,23 @@ public class AddressUtils
         }
         return UNKNOWN;
     }
+
+    public static String getAddress() throws ExecutionException, InterruptedException {
+
+        //IP地址从当前登录用户的表里拿
+        String ipAddr = IpUtils.getIpAddr();
+        String address = "未知";
+        String  realAddressByIP = getRealAddressByIP(ipAddr);
+        if (realAddressByIP.isEmpty() || realAddressByIP.equals("内网IP")){
+            return address;
+        }
+
+        String[] parts = realAddressByIP.split(" ", 2); // 这里的2表示只分割一次
+        address = parts[0].replace("市", "").replace("省", "");
+        return address;
+    }
+
+
+
+
 }

+ 23 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -8,6 +8,7 @@ import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.ip.AddressUtils;
 import com.ruoyi.generator.domain.Community.CommunityArticleComment;
 import com.ruoyi.generator.domain.Community.CommunityCommentLike;
 import com.ruoyi.generator.domain.Community.CommunityCommentReply;
@@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.text.ParseException;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
 /**
@@ -83,6 +85,10 @@ public class CommunityCommentController extends BaseController {
             CommunityArticleCommentVo commentVo = null;
 
             for (CommunityArticleComment record : records) {
+                if (record.getAddress() == null){
+                    record.setAddress("未知");
+                }
+
                 commentVo = new CommunityArticleCommentVo();
                 BeanUtils.copyProperties(record, commentVo);
                 commentVos.add(commentVo);
@@ -157,6 +163,9 @@ public class CommunityCommentController extends BaseController {
 
             for (final CommunityCommentReply reply : replies) {
                 replyVo = new CommunityCommentReplyVo();
+                if (reply.getAddress() == null){
+                    reply.setAddress("未知");
+                }
                 SysUser sysUser = sysUserService.selectUserById(reply.getUserId());
                 final Long parentReplyId = reply.getParentReplyId();
                 BeanUtils.copyProperties(reply, replyVo);
@@ -175,6 +184,8 @@ public class CommunityCommentController extends BaseController {
                         .eq("reply_id", replyVo.getId()));
                 replyVo.setLikeCount(commentLikes.size());
                 replyVo.setLike(commentLikes.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
+
+
                 replyVos.add(replyVo);
             }
         } catch (Exception e) {
@@ -208,7 +219,19 @@ public class CommunityCommentController extends BaseController {
             communityCommentReply.setDelete(false);
             communityCommentReply.setCreateBy(userId);
             communityCommentReply.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            String address = null;
+            try {
+                address = AddressUtils.getAddress();
+            } catch (ExecutionException e) {
+                throw new RuntimeException(e);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+            communityCommentReply.setAddress(address);
             communityCommentReplyService.save(communityCommentReply);
+
+
+
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleComment.java

@@ -73,4 +73,11 @@ public class CommunityArticleComment implements Serializable {
     @ApiModelProperty("图片地址")
     private String imageUrl;
 
+    /**
+     * 用户地址
+     */
+    @ApiModelProperty("用户地址")
+    private String address;
+
+
 }

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

@@ -89,4 +89,10 @@ public class CommunityCommentReply implements Serializable {
     @ApiModelProperty("图片地址")
     private String imageUrl;
 
+    /**
+     * 用户地址
+     */
+    @ApiModelProperty("用户地址")
+    private String address;
+
 }

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

@@ -2,9 +2,12 @@ package com.ruoyi.generator.mapper.community;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.generator.domain.Community.CommunityArticleComment;
+import io.swagger.models.auth.In;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 @Mapper
 public interface CommunityArticleCommentMapper extends BaseMapper<CommunityArticleComment> {
 
@@ -14,4 +17,38 @@ public interface CommunityArticleCommentMapper extends BaseMapper<CommunityArtic
      * @return 总数
      */
     Integer queryCommentCount(@Param("articleId") Long articleId);
+
+    /**
+     * 获取用户所有文章具体评论文章的数量
+     * @param articleIds
+     * @return
+     */
+    Integer queryCommentReplyCount (@Param("articleIds")  List<Long> articleIds);
+
+    /**
+     * 获取所有文章具体评论文章的数量  以及 用户文章数量的排名
+     * @param commentSum
+     * @return
+     */
+    Integer queryCommentReplyCountPerson (@Param("commentSum")  int commentSum);
+
+
+    /**
+     * 获取用户所有文章和评论被喜欢的数量的数量  跟下面sql一样后期优化
+     * @param userId
+     * @return
+     */
+    Integer queryCommentReplyLikeCount (@Param("userId") Long userId);
+
+    /**
+     * 获取所有喜欢数量的排名
+     * @param likeSum
+     * @return
+     */
+    Integer queryCommentReplyLikeCountPerson (@Param("likeSum")  int likeSum);
+
+
+
+
+
 }

+ 106 - 40
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityAccompanyImpl.java

@@ -2,10 +2,10 @@ package com.ruoyi.generator.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ruoyi.common.core.domain.entity.SysUser;
-import com.ruoyi.generator.domain.Community.CommunityAccompany;
-import com.ruoyi.generator.domain.Community.CommunityArticle;
-import com.ruoyi.generator.domain.Community.CommunityUserLike;
+import com.ruoyi.generator.domain.Community.*;
+import com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper;
 import com.ruoyi.generator.mapper.community.CommunityArticleMapper;
+import com.ruoyi.generator.mapper.community.CommunityCommentReplyMapper;
 import com.ruoyi.generator.mapper.community.CommunityUserLikeMapper;
 import com.ruoyi.generator.vo.CommunityUserLikeVo;
 import com.ruoyi.system.mapper.SysUserMapper;
@@ -20,6 +20,7 @@ import java.time.temporal.Temporal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author fangqing
@@ -38,6 +39,12 @@ public class CommunityAccompanyImpl implements ICommunityAccompanyService {
     @Autowired
     private CommunityUserLikeMapper communityUserLikeMapper;
 
+    @Autowired
+    private CommunityArticleCommentMapper communityArticleCommentMapper;
+
+    @Autowired
+    private CommunityCommentReplyMapper communityCommentReplyMapper;
+
     @Override
     public CommunityAccompany selectCommunityAccompanyById(Long userId) {
         DecimalFormat df = new DecimalFormat("#.00");
@@ -70,36 +77,49 @@ public class CommunityAccompanyImpl implements ICommunityAccompanyService {
             //设置用户创作数
             communityAccompany.setCreationCount((long) communityArticles.size());
 
-            //查询当前用户下文章的数量
-            List<CommunityArticle> communityArticlesTotal = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+            //计算小于自己粉丝的有多少人
+            List<CommunityArticle> communityArticlesLess = new ArrayList<>(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .select("user_id", "COUNT(1) as count")
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })
+                    .groupBy("user_id")
+                    .having("COUNT(*) <= {0}", (long) communityArticles.size())
+                    .orderByDesc("count"))) ;
+
+            //计算所有文章的数量
+            List<CommunityArticle> communityArticlesTotal = new ArrayList<>(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .select("user_id", "COUNT(1) as count")
                     .and((wrapper) -> {
                         wrapper.ne("is_delete", true).or().isNull("is_delete");
-                    }));
-            //获取文章总数
-            long articles = communityArticlesTotal.size();
-            //计算百分比
-            //计算创作数的百分比 防止总数取0
-            if (articles != 0) {
-                Double CreationCountPercent = Double.valueOf(df.format((double) communityArticles.size() / articles * 100));
-                communityAccompany.setCreationCountPercent(CreationCountPercent);
-            }
-
-            //获取用户阅览量
+                    })
+                    .groupBy("user_id")
+                    .orderByDesc("count")));
+
+            //计算创作数的百分比 计算百分比
+            Double CreationCountPercent = Double.valueOf(df.format((double) communityArticlesLess.size() / communityArticlesTotal.size() * 100));
+            communityAccompany.setCreationCountPercent(CreationCountPercent);
+
+
+            //计算用户阅览量
             long read = communityArticles.stream()
                     .mapToLong(article -> article.getPageViews()).sum();
+            communityAccompany.setRead(read);
 
-            if (read != 0  ){
-                communityAccompany.setRead(read);
-            }
 
-            //阅览量百分比
-            long readSUm = communityArticlesTotal.stream()
-                    .mapToLong(article -> article.getPageViews()).sum();
+            //计算阅览量百分比
+            List<CommunityArticle> communityArticlesReadSumLess = new ArrayList<>(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .select("user_id","sum(page_views) page_views","COUNT(1) as count")
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })
+                    .groupBy("user_id")
+                    .having("page_views <= {0}", read )
+                    .orderByDesc("count"))) ;
+
+            Double ReadPercent = Double.valueOf(df.format((double)  communityArticlesReadSumLess.size() / communityArticlesTotal.size() * 100));
+            communityAccompany.setReadPercent(ReadPercent);
 
-            if (readSUm != 0){
-                Double ReadPercent = Double.valueOf(df.format((double)  read / readSUm * 100));
-                communityAccompany.setReadPercent(ReadPercent);
-            }
         }
 
 
@@ -107,22 +127,68 @@ public class CommunityAccompanyImpl implements ICommunityAccompanyService {
         Long fans = communityUserLikeMapper.selectCount(new QueryWrapper<CommunityUserLike>()
                 .eq("like_user_id", userId));
 
-        if (fans != 0 ){
-            communityAccompany.setFan(fans);
-            //粉丝数占比
-            List<CommunityUserLike> userLikeFan = new ArrayList<>(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
-                    .select("like_user_id", "COUNT(1) as count")
-                    .groupBy("like_user_id")
-                    .having("COUNT(*) <= {0}", fans)
-                    .orderByDesc("count"))) ;
 
-            //计算总人数
-            List<CommunityUserLike> userLikeFans = new ArrayList<>(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
-                    .select("like_user_id", "COUNT(1) as count")
-                    .groupBy("like_user_id")));
-            Double  ReadPercent = Double.valueOf(df.format((double) userLikeFan.size() / userLikeFans.size() * 100));
-            communityAccompany.setFanPercent(ReadPercent);
+        communityAccompany.setFan(fans);
+        //计算小于自己粉丝的有多少人
+        List<CommunityUserLike> userLikeFan = new ArrayList<>(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
+                .select("like_user_id", "COUNT(1) as count")
+                .groupBy("like_user_id")
+                .having("COUNT(*) <= {0}", fans)
+                .orderByDesc("count"))) ;
+
+        //计算总人数
+        List<CommunityUserLike> userLikeFans = new ArrayList<>(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
+                .select("like_user_id", "COUNT(1) as count")
+                .groupBy("like_user_id")));
+        //粉丝数占比
+        Double  ReadPercent = Double.valueOf(df.format((double) userLikeFan.size() / userLikeFans.size() * 100));
+        communityAccompany.setFanPercent(ReadPercent);
+
+
+        //查询评论数
+        /*//一级评论
+        Long comment = communityArticleCommentMapper.selectCount(new QueryWrapper<CommunityArticleComment>()
+                .eq("user_id", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                })
+        );
+        //二级评论
+        Long commentReply = communityCommentReplyMapper.selectCount(new QueryWrapper<CommunityCommentReply>()
+                .eq("user_id", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                })
+        );*/
+        //查询哪几篇文章是我发布的
+        List<Long> articleIds = communityArticles.stream().map(item -> item.getId()).collect(Collectors.toList());
+        System.out.println(articleIds);
+        Integer commentSum = 0;
+        //查询评论数 别人评论我的数量 首先自己得有文章才能有评论
+        if (articleIds.size() > 0 ) {
+            commentSum = communityArticleCommentMapper.queryCommentReplyCount(articleIds);
+        }
+        communityAccompany.setComment(Long.valueOf(commentSum));
+
+        //评论数占比
+        if (commentSum > 0 ){
+            Integer commentless = communityArticleCommentMapper.queryCommentReplyCountPerson(commentSum);
+            Integer commentCount = communityArticleCommentMapper.queryCommentReplyCountPerson(0);
+            Double  commentPercent = Double.valueOf(df.format((double) commentless / commentCount * 100));
+            communityAccompany.setCommentPercent(commentPercent);
+        }
+
+        //用户文章 和 评论收货多少点赞
+        Integer likeCount = communityArticleCommentMapper.queryCommentReplyLikeCount(userId);
+        communityAccompany.setLike(Long.valueOf(likeCount));
+
+        if (likeCount >0 ){
+            Integer likeless = communityArticleCommentMapper.queryCommentReplyLikeCountPerson(likeCount);
+            Integer likesCount = communityArticleCommentMapper.queryCommentReplyLikeCountPerson(0);
+            Double likePercent = Double.valueOf(df.format((double) likeless / likesCount * 100));
+            communityAccompany.setLikePercent(likePercent);
         }
+        //
 
         return communityAccompany;
     }

+ 14 - 8
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -384,6 +384,17 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleComment.setDelete(false);
+        String address = null;
+        try {
+            address = AddressUtils.getAddress();
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+
+        communityArticleComment.setAddress(address);
+
         communityArticleCommentMapper.insert(communityArticleComment);
     }
 
@@ -563,20 +574,15 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityUserInfoVo.setCompanionCount(0);
 
 
-        String truncatedString = null;
+        String address = null;
         try {
-            String ip = IpUtils.get();
-            String address = AddressUtils.getRealAddressByIP(ip);
-            // 使用空格分割字符串
-            String[] parts = address.split(" ", 2); // 这里的2表示只分割一次
-            truncatedString = parts[0].replace("市", "").replace("省", "");
+            address = AddressUtils.getAddress();
         } catch (ExecutionException e) {
             throw new RuntimeException(e);
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
-
-        communityUserInfoVo.setAddress(truncatedString);
+        communityUserInfoVo.setAddress(address);
         //设置是否被当前登录的用户关注
         communityUserInfoVo.setLike(false);
         Long loginUserId = SecurityUtils.getLoginUser().getUserId();

+ 5 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityArticleCommentVo.java

@@ -100,4 +100,9 @@ public class CommunityArticleCommentVo extends BaseEntity implements Serializabl
     @ApiModelProperty("图片地址")
     private String imageUrl;
 
+    /**
+     * 用户地址
+     */
+    @ApiModelProperty("用户地址")
+    private String address;
 }

+ 6 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityCommentReplyVo.java

@@ -122,4 +122,10 @@ public class CommunityCommentReplyVo implements Serializable {
      */
     @ApiModelProperty("图片地址")
     private String imageUrl;
+
+    /**
+     * 用户地址
+     */
+    @ApiModelProperty("用户地址")
+    private String address;
 }

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

@@ -14,4 +14,161 @@
               from community_article_comment c
               where c.article_id = #{articleId}) as d
     </select>
-</mapper>
+
+    <select id="queryCommentReplyCount" resultType="java.lang.Integer">
+        select  d.commentCount + d.replyCount from  (
+                                                        select
+                                                            count(1) as   commentCount,
+                                                            (select
+                                                                 count(*)  count
+                                                        from
+                                                            community_article_comment   a
+                                                            left join community_comment_reply b on a.id = b.comment_id
+    <where>
+          <if test=" articleIds != null and articleIds.size > 0">
+            AND article_id in
+            <foreach collection="articleIds" item="articleId" index="index" open="(" close=")" separator=",">
+                #{articleId}
+            </foreach>
+          </if>
+          and b.id is not null
+          and (a.is_delete != 1 or a.is_delete is null)
+          and (b.is_delete != 1 or b.is_delete is null)
+    </where>
+            ) as replyCount
+            from community_article_comment c
+    <where>
+        <if test="articleIds  != null and articleIds.size > 0">
+            AND c.article_id in
+            <foreach collection="articleIds" item="articleId" index="index" open="(" close=")" separator=",">
+                #{articleId}
+            </foreach>
+        </if>
+        and (c.is_delete != 1 or c.is_delete is null)
+    </where>
+        )  as d
+    </select>
+
+
+    <select id="queryCommentReplyCountPerson" resultType="java.lang.Integer">
+        select count(1)  count  from (
+            select
+            f.user_id,sum(g.commentSum)  sum
+            from (
+            select
+            a.user_id,b.id   as  article_id
+            from sys_user a
+            left join community_article b on a.user_id = b. user_id
+            where  (a.status != 1 or a.status is null) and  (b.is_delete != 1 or b.is_delete is null)
+            and b.id is not null ) f
+            left join (select
+            d.article_id, d.commentCount + COALESCE(e.replyCount, 0) as commentSum
+            from (
+            select
+            c.article_id,
+            count(1) as   commentCount
+            from community_article_comment c
+            where (c.is_delete != 1 or c.is_delete is null)
+            group by c.article_id ) d
+            left join (select
+            a.article_id,count(1) replyCount
+            from
+            community_article_comment   a
+            left join community_comment_reply b on a.id = b.comment_id
+            where b.id is not null
+            and (a.is_delete != 1 or a.is_delete is null)
+            and (b.is_delete != 1 or b.is_delete is null)
+            group by a.article_id) e
+            on d.article_id = e.article_id ) g
+            on f.article_id = g.article_id
+            group by  f.user_id
+                <if test="commentSum  != null and commentSum > 0">
+                HAVING sum &lt;= #{commentSum}
+                </if>
+            ) h
+    </select>
+    <select id="queryCommentReplyLikeCount" resultType="java.lang.Integer">
+        select sum(count) sum  from (
+            select
+            a.user_id, count(1) count
+            from community_article a
+            left join  community_like b
+            on a.id = b.article_id
+            where  (a.is_delete != 1 or a.is_delete is null)
+            and b.id is not null
+            and a.user_id = #{userId}
+
+            GROUP BY a.user_id
+            union ALL
+            select
+            a.user_id,count(1) count
+            from
+            community_article_comment a
+            left join community_comment_like b
+            on a.id = b.comment_id
+            where  (a.is_delete != 1 or a.is_delete is null)
+            and b.id is not null  	and  EXISTS (select distinct id  from community_article z where a.article_id = z.id and  (z.is_delete != 1 or z.is_delete is null))
+            and  a.user_id = #{userId}
+            group by  a.user_id
+            union all
+            select
+            b.user_id,count(1) count
+            from
+            community_article_comment   a
+            left join community_comment_reply b on a.id = b.comment_id
+            left join community_comment_like c on b.id = c.reply_id
+            where
+            b.user_id = #{userId}
+            and b.id is not null
+            and c.id is not null
+            and (a.is_delete != 1 or a.is_delete is null)
+            and (b.is_delete != 1 or b.is_delete is null)
+            and  EXISTS (select distinct id  from community_article z where a.article_id = z.id and  (z.is_delete != 1 or z.is_delete is null))
+            group by b.user_id ) AA
+        group by user_id
+    </select>
+
+    <select id="queryCommentReplyLikeCountPerson" resultType="java.lang.Integer">
+        select count(*)  from (
+                                 select user_id,sum(count) counts  from (
+                                     select
+                                     a.user_id, count(1) count
+                                     from community_article a
+                                     left join  community_like b
+                                     on a.id = b.article_id
+                                     where  (a.is_delete != 1 or a.is_delete is null)
+                                     and b.id is not null
+                                     GROUP BY a.user_id
+                                     union ALL
+                                     select
+                                     a.user_id,count(1) count
+                                     from
+                                     community_article_comment a
+                                     left join community_comment_like b
+                                     on a.id = b.comment_id
+                                     where  (a.is_delete != 1 or a.is_delete is null)
+                                     and b.id is not null  	and  EXISTS (select distinct id  from community_article z where a.article_id = z.id and  (z.is_delete != 1 or z.is_delete is null))
+                                     group by  a.user_id
+                                     union all
+                                     select
+                                     b.user_id,count(1) count
+                                     from
+                                     community_article_comment   a
+                                     left join community_comment_reply b on a.id = b.comment_id
+                                     left join community_comment_like c on b.id = c.reply_id
+                                     where
+                                     b.id is not null
+                                     and c.id is not null
+                                     and (a.is_delete != 1 or a.is_delete is null)
+                                     and (b.is_delete != 1 or b.is_delete is null)
+                                     and  EXISTS (select distinct id  from community_article z where a.article_id = z.id and  (z.is_delete != 1 or z.is_delete is null))
+                                     group by b.user_id ) AA
+                                 group by user_id
+        <if test="likeSum  != null and likeSum > 0">
+            HAVING counts &lt;= #{likeSum}
+        </if>
+
+        ) BB
+
+    </select>
+</mapper>