CommentReplyMapper.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="shop.alien.mapper.CommentReplyMapper">
  4. <!-- 回复列表查询结果映射 -->
  5. <resultMap id="CommentReplyVoResultMap" type="shop.alien.entity.store.vo.CommentReplyVo">
  6. <id column="id" property="id" />
  7. <result column="comment_id" property="commentId" />
  8. <result column="user_id" property="userId" />
  9. <result column="user_name" property="userName" />
  10. <result column="user_avatar" property="userAvatar" />
  11. <result column="reply_to_user_id" property="replyToUserId" />
  12. <result column="reply_to_user_name" property="replyToUserName" />
  13. <result column="parent_reply_id" property="parentReplyId" />
  14. <result column="reply_content" property="replyContent" />
  15. <result column="like_count" property="likeCount" />
  16. <result column="is_liked" property="isLiked" />
  17. <result column="reply_count" property="replyCount" />
  18. <result column="created_time" property="createdTime" />
  19. </resultMap>
  20. <!-- 根据评论ID查询回复列表(包含用户信息) -->
  21. <select id="getReplyListByCommentId" resultMap="CommentReplyVoResultMap">
  22. SELECT
  23. cr.id,
  24. cr.comment_id,
  25. cr.user_id,
  26. lu.user_name AS user_name,
  27. lu.user_image AS user_avatar,
  28. cr.reply_to_user_id,
  29. lu2.user_name AS reply_to_user_name,
  30. cr.parent_reply_id,
  31. cr.reply_content,
  32. cr.like_count,
  33. CASE
  34. WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
  35. ELSE 0
  36. END AS is_liked,
  37. (SELECT COUNT(*) FROM comment_reply cr2
  38. WHERE cr2.parent_reply_id = cr.id AND cr2.delete_flag = 0) AS reply_count,
  39. cr.created_time
  40. FROM comment_reply cr
  41. LEFT JOIN life_user lu ON lu.id = cr.user_id AND lu.delete_flag = 0
  42. LEFT JOIN life_user lu2 ON lu2.id = cr.reply_to_user_id AND lu2.delete_flag = 0
  43. LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(cr.id, CHAR)
  44. AND llr.type = '9'
  45. AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
  46. AND llr.delete_flag = 0
  47. WHERE cr.delete_flag = 0
  48. AND cr.comment_id = #{commentId}
  49. AND cr.parent_reply_id = 0
  50. ORDER BY cr.created_time ASC
  51. </select>
  52. <!-- 根据父回复ID查询子回复列表(包含用户信息) -->
  53. <select id="getChildReplyListByParentId" resultMap="CommentReplyVoResultMap">
  54. SELECT
  55. cr.id,
  56. cr.comment_id,
  57. cr.user_id,
  58. lu.user_name AS user_name,
  59. lu.user_image AS user_avatar,
  60. cr.reply_to_user_id,
  61. lu2.user_name AS reply_to_user_name,
  62. cr.parent_reply_id,
  63. cr.reply_content,
  64. cr.like_count,
  65. CASE
  66. WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
  67. ELSE 0
  68. END AS is_liked,
  69. 0 AS reply_count,
  70. cr.created_time
  71. FROM comment_reply cr
  72. LEFT JOIN life_user lu ON lu.id = cr.user_id AND lu.delete_flag = 0
  73. LEFT JOIN life_user lu2 ON lu2.id = cr.reply_to_user_id AND lu2.delete_flag = 0
  74. LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(cr.id, CHAR)
  75. AND llr.type = '9'
  76. AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
  77. AND llr.delete_flag = 0
  78. WHERE cr.delete_flag = 0
  79. AND cr.parent_reply_id = #{parentReplyId}
  80. ORDER BY cr.created_time ASC
  81. </select>
  82. <!-- 根据评论ID查询回复数量 -->
  83. <select id="getReplyCountByCommentId" resultType="java.lang.Integer">
  84. SELECT COUNT(*)
  85. FROM comment_reply
  86. WHERE delete_flag = 0
  87. AND comment_id = #{commentId}
  88. </select>
  89. <!-- 根据评论ID删除所有回复(逻辑删除) -->
  90. <update id="deleteRepliesByCommentId">
  91. UPDATE comment_reply
  92. SET delete_flag = 1,
  93. updated_time = NOW()
  94. WHERE delete_flag = 0
  95. AND comment_id = #{commentId}
  96. </update>
  97. </mapper>