Browse Source

个人中心代码优化

fangqing 5 months ago
parent
commit
e2b17282bb

+ 21 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityArticleCommentMapper.java

@@ -19,17 +19,36 @@ public interface CommunityArticleCommentMapper extends BaseMapper<CommunityArtic
     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);
 
+
+    /**
+     * 获取用户所有文章和评论被喜欢的数量   的数量
+     * @param userId
+     * @return
+     */
+    Integer queryCommentReplyLikeCount (@Param("userId") Long userId);
+
+    /**
+     * 获取所有喜欢数量的排名
+     * @param likeSum
+     * @return
+     */
+    Integer queryCommentReplyLikeCountPerson (@Param("likeSum")  int likeSum);
+
+
+
+
+
 }

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

@@ -178,8 +178,17 @@ public class CommunityAccompanyImpl implements ICommunityAccompanyService {
             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;
     }

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

@@ -85,4 +85,88 @@
                 </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>