|
|
@@ -8,8 +8,10 @@
|
|
|
<result column="review_id" property="reviewId" />
|
|
|
<result column="send_user_id" property="sendUserId" />
|
|
|
<result column="receive_user_id" property="receiveUserId" />
|
|
|
- <result column="user_name" property="sendUserName" />
|
|
|
+ <!-- send_user_name: 发送用户名称(根据 send_user_id 和 send_user_type 查询) -->
|
|
|
+ <result column="send_user_name" property="sendUserName" />
|
|
|
<result column="user_avatar" property="userAvatar" />
|
|
|
+ <!-- receive_user_name: 接收用户名称(根据 receive_user_id 和 receive_user_type 查询) -->
|
|
|
<result column="receive_user_name" property="receiveUserName" />
|
|
|
<result column="send_user_type" property="sendUserType" />
|
|
|
<result column="receive_user_type" property="receiveUserType" />
|
|
|
@@ -23,15 +25,35 @@
|
|
|
</resultMap>
|
|
|
|
|
|
<!-- 根据评价ID查询评论列表(包含用户信息) -->
|
|
|
+ <!-- 评论列表中的 sendUserName 和 receiveUserName 根据 sendUserType 和 receiveUserType 分别从对应的表中查询 -->
|
|
|
<select id="getCommentListByReviewId" resultMap="ReviewCommentVoResultMap">
|
|
|
SELECT
|
|
|
rc.id,
|
|
|
rc.review_id,
|
|
|
rc.send_user_id,
|
|
|
rc.receive_user_id,
|
|
|
- lu.user_name AS user_name,
|
|
|
- lu.user_image AS user_avatar,
|
|
|
- lu2.user_name AS receive_user_name,
|
|
|
+ -- 发送用户名称:根据 sendUserType 分别查询普通用户表和律师表
|
|
|
+ -- sendUserType = 2(律师):优先从 lawyer_user 表查询,如果没有则从 life_user 表查询
|
|
|
+ -- sendUserType = 1 或 NULL(普通用户):优先从 life_user 表查询,如果没有则从 lawyer_user 表查询
|
|
|
+ CASE
|
|
|
+ WHEN rc.send_user_type = 2 THEN COALESCE(lu_lawyer.name, lu_user.user_name)
|
|
|
+ WHEN rc.send_user_type = 1 OR rc.send_user_type IS NULL THEN COALESCE(lu_user.user_name, lu_lawyer.name)
|
|
|
+ ELSE COALESCE(lu_user.user_name, lu_lawyer.name)
|
|
|
+ END AS send_user_name,
|
|
|
+ -- 发送用户头像:根据 sendUserType 分别查询普通用户表和律师表
|
|
|
+ CASE
|
|
|
+ WHEN rc.send_user_type = 2 THEN COALESCE(lu_lawyer.head_img, lu_user.user_image)
|
|
|
+ WHEN rc.send_user_type = 1 OR rc.send_user_type IS NULL THEN COALESCE(lu_user.user_image, lu_lawyer.head_img)
|
|
|
+ ELSE COALESCE(lu_user.user_image, lu_lawyer.head_img)
|
|
|
+ END AS user_avatar,
|
|
|
+ -- 接收用户名称:根据 receiveUserType 严格从对应的表中查询
|
|
|
+ -- receiveUserType = 2(律师):只从 lawyer_user 表查询
|
|
|
+ -- receiveUserType = 1 或 NULL(普通用户):只从 life_user 表查询
|
|
|
+ CASE
|
|
|
+ WHEN rc.receive_user_type = 2 THEN lu_lawyer2.name
|
|
|
+ WHEN rc.receive_user_type = 1 OR rc.receive_user_type IS NULL THEN lu_user2.user_name
|
|
|
+ ELSE NULL
|
|
|
+ END AS receive_user_name,
|
|
|
rc.send_user_type,
|
|
|
rc.receive_user_type,
|
|
|
rc.comment_content,
|
|
|
@@ -45,8 +67,25 @@
|
|
|
END AS is_liked,
|
|
|
rc.created_time
|
|
|
FROM lawyer_review_comment rc
|
|
|
- LEFT JOIN life_user lu ON lu.id = rc.send_user_id AND lu.delete_flag = 0
|
|
|
- LEFT JOIN life_user lu2 ON lu2.id = rc.receive_user_id AND lu2.delete_flag = 0
|
|
|
+ -- 发送用户:普通用户表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN life_user lu_user ON lu_user.id = rc.send_user_id
|
|
|
+ AND lu_user.delete_flag = 0
|
|
|
+ -- 发送用户:律师表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN lawyer_user lu_lawyer ON lu_lawyer.id = rc.send_user_id
|
|
|
+ AND lu_lawyer.delete_flag = 0
|
|
|
+ -- 接收用户:普通用户表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN life_user lu_user2 ON lu_user2.id = rc.receive_user_id
|
|
|
+ AND lu_user2.delete_flag = 0
|
|
|
+ -- 接收用户:律师表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN lawyer_user lu_lawyer2 ON lu_lawyer2.id = rc.receive_user_id
|
|
|
+ AND lu_lawyer2.delete_flag = 0
|
|
|
+ -- 如果 receive_user_id 在用户表中查询不到,尝试从评论表查询(处理 receive_user_id 可能是评论 ID 的情况)
|
|
|
+ LEFT JOIN lawyer_review_comment rc_comment ON rc_comment.id = rc.receive_user_id
|
|
|
+ AND rc_comment.delete_flag = 0
|
|
|
+ LEFT JOIN life_user lu_user_comment ON lu_user_comment.id = rc_comment.send_user_id
|
|
|
+ AND lu_user_comment.delete_flag = 0
|
|
|
+ LEFT JOIN lawyer_user lu_lawyer_comment ON lu_lawyer_comment.id = rc_comment.send_user_id
|
|
|
+ AND lu_lawyer_comment.delete_flag = 0
|
|
|
LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(rc.id, CHAR)
|
|
|
AND llr.type = '8'
|
|
|
AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
|
|
|
@@ -58,15 +97,35 @@
|
|
|
</select>
|
|
|
|
|
|
<!-- 根据首评ID查询回复列表(包含用户信息) -->
|
|
|
+ <!-- 回复列表中的 sendUserName 和 receiveUserName 根据 sendUserType 和 receiveUserType 分别从对应的表中查询 -->
|
|
|
<select id="getReplyListByHeadId" resultMap="ReviewCommentVoResultMap">
|
|
|
SELECT
|
|
|
rc.id,
|
|
|
rc.review_id,
|
|
|
rc.send_user_id,
|
|
|
rc.receive_user_id,
|
|
|
- lu.user_name AS user_name,
|
|
|
- lu.user_image AS user_avatar,
|
|
|
- lu2.user_name AS receive_user_name,
|
|
|
+ -- 发送用户名称:根据 sendUserType 分别查询普通用户表和律师表
|
|
|
+ -- sendUserType = 2(律师):优先从 lawyer_user 表查询,如果没有则从 life_user 表查询
|
|
|
+ -- sendUserType = 1 或 NULL(普通用户):优先从 life_user 表查询,如果没有则从 lawyer_user 表查询
|
|
|
+ CASE
|
|
|
+ WHEN rc.send_user_type = 2 THEN COALESCE(lu_lawyer.name, lu_user.user_name)
|
|
|
+ WHEN rc.send_user_type = 1 OR rc.send_user_type IS NULL THEN COALESCE(lu_user.user_name, lu_lawyer.name)
|
|
|
+ ELSE COALESCE(lu_user.user_name, lu_lawyer.name)
|
|
|
+ END AS send_user_name,
|
|
|
+ -- 发送用户头像:根据 sendUserType 分别查询普通用户表和律师表
|
|
|
+ CASE
|
|
|
+ WHEN rc.send_user_type = 2 THEN COALESCE(lu_lawyer.head_img, lu_user.user_image)
|
|
|
+ WHEN rc.send_user_type = 1 OR rc.send_user_type IS NULL THEN COALESCE(lu_user.user_image, lu_lawyer.head_img)
|
|
|
+ ELSE COALESCE(lu_user.user_image, lu_lawyer.head_img)
|
|
|
+ END AS user_avatar,
|
|
|
+ -- 接收用户名称:根据 receiveUserType 严格从对应的表中查询
|
|
|
+ -- receiveUserType = 2(律师):只从 lawyer_user 表查询
|
|
|
+ -- receiveUserType = 1 或 NULL(普通用户):只从 life_user 表查询
|
|
|
+ CASE
|
|
|
+ WHEN rc.receive_user_type = 2 THEN lu_lawyer2.name
|
|
|
+ WHEN rc.receive_user_type = 1 OR rc.receive_user_type IS NULL THEN lu_user2.user_name
|
|
|
+ ELSE NULL
|
|
|
+ END AS receive_user_name,
|
|
|
rc.send_user_type,
|
|
|
rc.receive_user_type,
|
|
|
rc.comment_content,
|
|
|
@@ -80,8 +139,25 @@
|
|
|
END AS is_liked,
|
|
|
rc.created_time
|
|
|
FROM lawyer_review_comment rc
|
|
|
- LEFT JOIN life_user lu ON lu.id = rc.send_user_id AND lu.delete_flag = 0
|
|
|
- LEFT JOIN life_user lu2 ON lu2.id = rc.receive_user_id AND lu2.delete_flag = 0
|
|
|
+ -- 发送用户:普通用户表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN life_user lu_user ON lu_user.id = rc.send_user_id
|
|
|
+ AND lu_user.delete_flag = 0
|
|
|
+ -- 发送用户:律师表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN lawyer_user lu_lawyer ON lu_lawyer.id = rc.send_user_id
|
|
|
+ AND lu_lawyer.delete_flag = 0
|
|
|
+ -- 接收用户:普通用户表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN life_user lu_user2 ON lu_user2.id = rc.receive_user_id
|
|
|
+ AND lu_user2.delete_flag = 0
|
|
|
+ -- 接收用户:律师表(先 JOIN,不限制类型)
|
|
|
+ LEFT JOIN lawyer_user lu_lawyer2 ON lu_lawyer2.id = rc.receive_user_id
|
|
|
+ AND lu_lawyer2.delete_flag = 0
|
|
|
+ -- 如果 receive_user_id 在用户表中查询不到,尝试从评论表查询(处理 receive_user_id 可能是评论 ID 的情况)
|
|
|
+ LEFT JOIN lawyer_review_comment rc_comment ON rc_comment.id = rc.receive_user_id
|
|
|
+ AND rc_comment.delete_flag = 0
|
|
|
+ LEFT JOIN life_user lu_user_comment ON lu_user_comment.id = rc_comment.send_user_id
|
|
|
+ AND lu_user_comment.delete_flag = 0
|
|
|
+ LEFT JOIN lawyer_user lu_lawyer_comment ON lu_lawyer_comment.id = rc_comment.send_user_id
|
|
|
+ AND lu_lawyer_comment.delete_flag = 0
|
|
|
LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(rc.id, CHAR)
|
|
|
AND llr.type = '8'
|
|
|
AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
|