修复bug

This commit is contained in:
苏元皓
2024-09-05 14:06:57 +08:00
parent ee64bca6fd
commit 117ab31c00
4 changed files with 27 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ public class Comment implements Serializable {
private Long postId; private Long postId;
@TableField("tutorialId")
private Long tutorialId; // 新增字段 private Long tutorialId; // 新增字段
private String content; private String content;

View File

@@ -14,11 +14,11 @@ import org.apache.ibatis.annotations.Select;
public interface LikeMapper extends BaseMapper<Likee> { public interface LikeMapper extends BaseMapper<Likee> {
// 获取帖子获赞数 // 获取帖子获赞数
@Select("SELECT SUM(like_count) FROM posts WHERE user_openid = #{userOpenid}")
Long getPostLikeCount(@Param("userOpenid") String userOpenid); Long getPostLikeCount(@Param("userOpenid") String userOpenid);
// 获取评论获赞数 // 获取评论获赞数
@Select("SELECT SUM(like_count) FROM comments WHERE user_openid = #{userOpenid}")
Long getCommentLikeCount(@Param("userOpenid") String userOpenid); Long getCommentLikeCount(@Param("userOpenid") String userOpenid);
// 查询帖子被点赞的总数 // 查询帖子被点赞的总数

View File

@@ -5,20 +5,33 @@
<mapper namespace="com.ivmiku.tutorial.mapper.LikeMapper"> <mapper namespace="com.ivmiku.tutorial.mapper.LikeMapper">
<resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.Likee"> <resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.Likee">
<id property="id" column="id" jdbcType="BIGINT"/> <id property="id" column="id" jdbcType="BIGINT"/>
<result property="userOpenid" column="user_openid" jdbcType="VARCHAR"/> <result property="userOpenid" column="user_openid" jdbcType="VARCHAR"/>
<result property="postId" column="post_id" jdbcType="BIGINT"/> <result property="postId" column="post_id" jdbcType="BIGINT"/>
<result property="tutorialId" column="tutorialId" jdbcType="BIGINT"/> <result property="tutorialId" column="tutorial_id" jdbcType="BIGINT"/>
<result property="commentId" column="comment_id" jdbcType="BIGINT"/> <result property="commentId" column="comment_id" jdbcType="BIGINT"/>
<result property="isDeleted" column="is_deleted" jdbcType="TINYINT"/> <result property="isDeleted" column="is_deleted" jdbcType="TINYINT"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,user_openid,post_id,tutorialId, id, user_openid, post_id, tutorial_id, comment_id, is_deleted
comment_id,is_deleted
</sql> </sql>
<select id="getLikeCountByPostId" resultType="java.lang.Long">
SELECT COUNT(*) FROM likee <!-- 查询用户所有帖子的点赞总数 -->
WHERE post_id = #{postId} AND is_deleted = 0 <select id="getPostLikeCount" resultType="java.lang.Long">
SELECT COUNT(*)
FROM likee
WHERE user_openid = #{userOpenid}
AND post_id IS NOT NULL
AND is_deleted = 0;
</select>
<!-- 查询用户所有评论的点赞总数 -->
<select id="getCommentLikeCount" resultType="java.lang.Long">
SELECT COUNT(*)
FROM likee
WHERE user_openid = #{userOpenid}
AND comment_id IS NOT NULL
AND is_deleted = 0;
</select> </select>
</mapper> </mapper>

View File

@@ -86,7 +86,6 @@
SELECT title SELECT title
FROM post FROM post
WHERE is_deleted = 0 AND is_public = 1 WHERE is_deleted = 0 AND is_public = 1
ORDER BY view_count DESC, like_count DESC
LIMIT 9 LIMIT 9
</select> </select>
<select id="searchPosts" resultType="com.ivmiku.tutorial.entity.Post"> <select id="searchPosts" resultType="com.ivmiku.tutorial.entity.Post">