From 117ab31c000653531faff436a688477108ea2e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=85=83=E7=9A=93?= Date: Thu, 5 Sep 2024 14:06:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ivmiku/tutorial/entity/Comment.java | 1 + .../ivmiku/tutorial/mapper/LikeMapper.java | 4 +-- .../src/main/resources/mapper/LikeMapper.xml | 35 +++++++++++++------ .../src/main/resources/mapper/PostMapper.xml | 1 - 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/community-8073/src/main/java/com/ivmiku/tutorial/entity/Comment.java b/community-8073/src/main/java/com/ivmiku/tutorial/entity/Comment.java index 0cad272..2cbfc9c 100644 --- a/community-8073/src/main/java/com/ivmiku/tutorial/entity/Comment.java +++ b/community-8073/src/main/java/com/ivmiku/tutorial/entity/Comment.java @@ -21,6 +21,7 @@ public class Comment implements Serializable { private Long postId; + @TableField("tutorialId") private Long tutorialId; // 新增字段 private String content; diff --git a/community-8073/src/main/java/com/ivmiku/tutorial/mapper/LikeMapper.java b/community-8073/src/main/java/com/ivmiku/tutorial/mapper/LikeMapper.java index c990419..4bcca60 100644 --- a/community-8073/src/main/java/com/ivmiku/tutorial/mapper/LikeMapper.java +++ b/community-8073/src/main/java/com/ivmiku/tutorial/mapper/LikeMapper.java @@ -14,11 +14,11 @@ import org.apache.ibatis.annotations.Select; public interface LikeMapper extends BaseMapper { // 获取帖子获赞数 - @Select("SELECT SUM(like_count) FROM posts WHERE user_openid = #{userOpenid}") + Long getPostLikeCount(@Param("userOpenid") String userOpenid); // 获取评论获赞数 - @Select("SELECT SUM(like_count) FROM comments WHERE user_openid = #{userOpenid}") + Long getCommentLikeCount(@Param("userOpenid") String userOpenid); // 查询帖子被点赞的总数 diff --git a/community-8073/src/main/resources/mapper/LikeMapper.xml b/community-8073/src/main/resources/mapper/LikeMapper.xml index 3609f2d..bb86670 100644 --- a/community-8073/src/main/resources/mapper/LikeMapper.xml +++ b/community-8073/src/main/resources/mapper/LikeMapper.xml @@ -5,20 +5,33 @@ - - - - - - + + + + + + - id,user_openid,post_id,tutorialId, - comment_id,is_deleted + id, user_openid, post_id, tutorial_id, comment_id, is_deleted - + SELECT COUNT(*) + FROM likee + WHERE user_openid = #{userOpenid} + AND post_id IS NOT NULL + AND is_deleted = 0; + + + + diff --git a/community-8073/src/main/resources/mapper/PostMapper.xml b/community-8073/src/main/resources/mapper/PostMapper.xml index ac56366..375e75c 100644 --- a/community-8073/src/main/resources/mapper/PostMapper.xml +++ b/community-8073/src/main/resources/mapper/PostMapper.xml @@ -86,7 +86,6 @@ SELECT title FROM post WHERE is_deleted = 0 AND is_public = 1 - ORDER BY view_count DESC, like_count DESC LIMIT 9