| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?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="shop.alien.mapper.CommentReplyMapper">
- <!-- 回复列表查询结果映射 -->
- <resultMap id="CommentReplyVoResultMap" type="shop.alien.entity.store.vo.CommentReplyVo">
- <id column="id" property="id" />
- <result column="comment_id" property="commentId" />
- <result column="user_id" property="userId" />
- <result column="user_name" property="userName" />
- <result column="user_avatar" property="userAvatar" />
- <result column="reply_to_user_id" property="replyToUserId" />
- <result column="reply_to_user_name" property="replyToUserName" />
- <result column="parent_reply_id" property="parentReplyId" />
- <result column="reply_content" property="replyContent" />
- <result column="like_count" property="likeCount" />
- <result column="is_liked" property="isLiked" />
- <result column="reply_count" property="replyCount" />
- <result column="created_time" property="createdTime" />
- </resultMap>
- <!-- 根据评论ID查询回复列表(包含用户信息) -->
- <select id="getReplyListByCommentId" resultMap="CommentReplyVoResultMap">
- SELECT
- cr.id,
- cr.comment_id,
- cr.user_id,
- lu.user_name AS user_name,
- lu.user_image AS user_avatar,
- cr.reply_to_user_id,
- lu2.user_name AS reply_to_user_name,
- cr.parent_reply_id,
- cr.reply_content,
- cr.like_count,
- CASE
- WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
- ELSE 0
- END AS is_liked,
- (SELECT COUNT(*) FROM comment_reply cr2
- WHERE cr2.parent_reply_id = cr.id AND cr2.delete_flag = 0) AS reply_count,
- cr.created_time
- FROM comment_reply cr
- LEFT JOIN life_user lu ON lu.id = cr.user_id AND lu.delete_flag = 0
- LEFT JOIN life_user lu2 ON lu2.id = cr.reply_to_user_id AND lu2.delete_flag = 0
- LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(cr.id, CHAR)
- AND llr.type = '9'
- AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
- AND llr.delete_flag = 0
- WHERE cr.delete_flag = 0
- AND cr.comment_id = #{commentId}
- AND cr.parent_reply_id = 0
- ORDER BY cr.created_time ASC
- </select>
- <!-- 根据父回复ID查询子回复列表(包含用户信息) -->
- <select id="getChildReplyListByParentId" resultMap="CommentReplyVoResultMap">
- SELECT
- cr.id,
- cr.comment_id,
- cr.user_id,
- lu.user_name AS user_name,
- lu.user_image AS user_avatar,
- cr.reply_to_user_id,
- lu2.user_name AS reply_to_user_name,
- cr.parent_reply_id,
- cr.reply_content,
- cr.like_count,
- CASE
- WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
- ELSE 0
- END AS is_liked,
- 0 AS reply_count,
- cr.created_time
- FROM comment_reply cr
- LEFT JOIN life_user lu ON lu.id = cr.user_id AND lu.delete_flag = 0
- LEFT JOIN life_user lu2 ON lu2.id = cr.reply_to_user_id AND lu2.delete_flag = 0
- LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(cr.id, CHAR)
- AND llr.type = '9'
- AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
- AND llr.delete_flag = 0
- WHERE cr.delete_flag = 0
- AND cr.parent_reply_id = #{parentReplyId}
- ORDER BY cr.created_time ASC
- </select>
- <!-- 根据评论ID查询回复数量 -->
- <select id="getReplyCountByCommentId" resultType="java.lang.Integer">
- SELECT COUNT(*)
- FROM comment_reply
- WHERE delete_flag = 0
- AND comment_id = #{commentId}
- </select>
- <!-- 根据评论ID删除所有回复(逻辑删除) -->
- <update id="deleteRepliesByCommentId">
- UPDATE comment_reply
- SET delete_flag = 1,
- updated_time = NOW()
- WHERE delete_flag = 0
- AND comment_id = #{commentId}
- </update>
- </mapper>
|