feat(comment): Implement comment module foundation

This commit is contained in:
2025-04-10 02:02:02 +08:00
parent 27dd1409f6
commit 449f5418b2
34 changed files with 2624 additions and 13 deletions
@@ -0,0 +1,22 @@
<?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.nuaa.video.comment.mapper.CommentLikeMapper">
<!-- 检查用户是否已点赞 -->
<select id="checkUserLiked" resultType="long">
SELECT COUNT(1)
FROM comment_like
WHERE comment_id = #{commentId}
AND user_id = #{userId}
AND type = #{type}
</select>
<!-- 统计视频评论点赞数 -->
<select id="countVideoCommentLikes" resultType="int">
SELECT COUNT(1)
FROM comment_like cl
LEFT JOIN comment c ON cl.comment_id = c.id AND cl.type = 1
LEFT JOIN comment_reply cr ON cl.comment_id = cr.id AND cl.type = 2
WHERE (c.video_id = #{videoId} OR cr.video_id = #{videoId})
</select>
</mapper>
@@ -0,0 +1,52 @@
<?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.nuaa.video.comment.mapper.CommentMapper">
<!-- 分页查询评论列表 -->
<select id="selectCommentList" resultType="com.nuaa.video.comment.entity.Comment">
SELECT *
FROM comment
<where>
status = 1
<if test="query.videoId != null">
AND video_id = #{query.videoId}
</if>
<if test="query.userId != null">
AND user_id = #{query.userId}
</if>
</where>
<choose>
<when test="query.orderBy != null and query.orderBy != ''">
ORDER BY top_status DESC, ${query.orderBy}
<if test="query.orderDirection != null and query.orderDirection != ''">
${query.orderDirection}
</if>
</when>
<otherwise>
ORDER BY top_status DESC, create_time DESC
</otherwise>
</choose>
</select>
<!-- 增加点赞数 -->
<update id="increaseLikeCount">
UPDATE comment
SET like_count = like_count + #{count}
WHERE id = #{commentId}
</update>
<!-- 增加回复数 -->
<update id="increaseReplyCount">
UPDATE comment
SET reply_count = reply_count + #{count}
WHERE id = #{commentId}
</update>
<!-- 统计视频评论数 -->
<select id="countVideoComments" resultType="int">
SELECT COUNT(1)
FROM comment
WHERE video_id = #{videoId}
AND status = 1
</select>
</mapper>
@@ -0,0 +1,38 @@
<?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.nuaa.video.comment.mapper.CommentReplyMapper">
<!-- 查询评论的回复列表 -->
<select id="selectCommentReplyList" resultType="com.nuaa.video.comment.entity.CommentReply">
SELECT *
FROM comment_reply
WHERE comment_id = #{commentId}
AND status = 1
ORDER BY create_time ASC
</select>
<!-- 获取评论的热门回复 -->
<select id="selectHotReplies" resultType="com.nuaa.video.comment.entity.CommentReply">
SELECT *
FROM comment_reply
WHERE comment_id = #{commentId}
AND status = 1
ORDER BY like_count DESC, create_time ASC
LIMIT #{limit}
</select>
<!-- 增加点赞数 -->
<update id="increaseLikeCount">
UPDATE comment_reply
SET like_count = like_count + #{count}
WHERE id = #{replyId}
</update>
<!-- 统计视频回复数 -->
<select id="countVideoReplies" resultType="int">
SELECT COUNT(1)
FROM comment_reply
WHERE video_id = #{videoId}
AND status = 1
</select>
</mapper>