OrderReviewMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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.OrderReviewMapper">
  4. <!-- 评价列表查询结果映射 -->
  5. <resultMap id="OrderReviewVoResultMap" type="shop.alien.entity.store.vo.OrderReviewVo">
  6. <id column="id" property="id" />
  7. <result column="order_id" property="orderId" />
  8. <result column="order_number" property="orderNumber" />
  9. <result column="user_id" property="userId" />
  10. <result column="user_name" property="userName" />
  11. <result column="user_avatar" property="userAvatar" />
  12. <result column="lawyer_user_id" property="lawyerUserId" />
  13. <result column="lawyer_name" property="lawyerName" />
  14. <result column="lawyer_avatar" property="lawyerAvatar" />
  15. <result column="law_firm_name" property="lawFirmName" />
  16. <result column="overall_rating" property="overallRating" />
  17. <result column="service_attitude_rating" property="serviceAttitudeRating" />
  18. <result column="response_time_rating" property="responseTimeRating" />
  19. <result column="professional_ability_rating" property="professionalAbilityRating" />
  20. <result column="review_content" property="reviewContent" />
  21. <result column="review_images" property="reviewImagesJson" />
  22. <result column="is_anonymous" property="isAnonymous" />
  23. <result column="like_count" property="likeCount" />
  24. <result column="comment_count" property="commentCount" />
  25. <result column="is_liked" property="isLiked" />
  26. <result column="created_time" property="createdTime" />
  27. </resultMap>
  28. <!-- 分页查询评价列表(包含用户和律师信息) -->
  29. <select id="getReviewListWithUser" resultMap="OrderReviewVoResultMap">
  30. SELECT
  31. orv.id,
  32. orv.order_id,
  33. orv.order_number,
  34. orv.user_id,
  35. CASE
  36. WHEN orv.is_anonymous = 1 THEN '匿名用户'
  37. ELSE lu.user_name
  38. END AS user_name,
  39. CASE
  40. WHEN orv.is_anonymous = 1 THEN NULL
  41. ELSE lu.user_image
  42. END AS user_avatar,
  43. orv.lawyer_user_id,
  44. lu2.name AS lawyer_name,
  45. lu2.head_img AS lawyer_avatar,
  46. lf.firm_name AS law_firm_name,
  47. orv.overall_rating,
  48. orv.service_attitude_rating,
  49. orv.response_time_rating,
  50. orv.professional_ability_rating,
  51. orv.review_content,
  52. orv.is_anonymous,
  53. orv.like_count,
  54. orv.comment_count,
  55. orv.review_images,
  56. CASE
  57. WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
  58. ELSE 0
  59. END AS is_liked,
  60. orv.created_time
  61. FROM lawyer_order_review orv
  62. LEFT JOIN life_user lu ON lu.id = orv.user_id AND lu.delete_flag = 0
  63. LEFT JOIN lawyer_user lu2 ON lu2.id = orv.lawyer_user_id AND lu2.delete_flag = 0
  64. LEFT JOIN law_firm lf ON lf.id = lu2.firm_id AND lf.delete_flag = 0
  65. LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(orv.id, CHAR)
  66. AND llr.type = '7'
  67. AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
  68. AND llr.delete_flag = 0
  69. WHERE orv.delete_flag = 0
  70. <if test="orderId != null">
  71. AND orv.order_id = #{orderId}
  72. </if>
  73. <if test="lawyerUserId != null">
  74. AND orv.lawyer_user_id = #{lawyerUserId}
  75. </if>
  76. <if test="userId != null">
  77. AND orv.user_id = #{userId}
  78. </if>
  79. ORDER BY orv.created_time DESC
  80. </select>
  81. <!-- 根据订单ID查询评价 -->
  82. <select id="getReviewByOrderId" resultMap="OrderReviewVoResultMap">
  83. SELECT
  84. orv.id,
  85. orv.order_id,
  86. orv.order_number,
  87. orv.user_id,
  88. CASE
  89. WHEN orv.is_anonymous = 1 THEN '匿名用户'
  90. ELSE lu.user_name
  91. END AS user_name,
  92. CASE
  93. WHEN orv.is_anonymous = 1 THEN NULL
  94. ELSE lu.user_image
  95. END AS user_avatar,
  96. orv.lawyer_user_id,
  97. lu2.name AS lawyer_name,
  98. lu2.head_img AS lawyer_avatar,
  99. lf.firm_name AS law_firm_name,
  100. orv.overall_rating,
  101. orv.service_attitude_rating,
  102. orv.response_time_rating,
  103. orv.professional_ability_rating,
  104. orv.review_content,
  105. orv.is_anonymous,
  106. orv.like_count,
  107. orv.comment_count,
  108. CASE
  109. WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
  110. ELSE 0
  111. END AS is_liked,
  112. orv.created_time
  113. FROM lawyer_order_review orv
  114. LEFT JOIN life_user lu ON lu.id = orv.user_id AND lu.delete_flag = 0
  115. LEFT JOIN lawyer_user lu2 ON lu2.id = orv.lawyer_user_id AND lu2.delete_flag = 0
  116. LEFT JOIN law_firm lf ON lf.id = lu2.firm_id AND lf.delete_flag = 0
  117. LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(orv.id, CHAR)
  118. AND llr.type = '7'
  119. AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
  120. AND llr.delete_flag = 0
  121. WHERE orv.delete_flag = 0
  122. AND orv.order_id = #{orderId}
  123. LIMIT 1
  124. </select>
  125. <!-- 根据评价ID查询评价详情(包含用户和律师信息) -->
  126. <select id="getReviewDetailById" resultMap="OrderReviewVoResultMap">
  127. SELECT
  128. orv.id,
  129. orv.order_id,
  130. orv.order_number,
  131. orv.user_id,
  132. CASE
  133. WHEN orv.is_anonymous = 1 THEN '匿名用户'
  134. ELSE lu.user_name
  135. END AS user_name,
  136. CASE
  137. WHEN orv.is_anonymous = 1 THEN NULL
  138. ELSE lu.user_image
  139. END AS user_avatar,
  140. orv.lawyer_user_id,
  141. lu2.name AS lawyer_name,
  142. lu2.head_img AS lawyer_avatar,
  143. lf.firm_name AS law_firm_name,
  144. orv.overall_rating,
  145. orv.service_attitude_rating,
  146. orv.response_time_rating,
  147. orv.professional_ability_rating,
  148. orv.review_content,
  149. orv.review_images,
  150. orv.is_anonymous,
  151. COALESCE((
  152. SELECT COUNT(1)
  153. FROM life_like_record llr_count
  154. WHERE CONVERT(llr_count.huifu_id, CHAR) = CONVERT(orv.id, CHAR)
  155. AND llr_count.type = '7'
  156. AND llr_count.delete_flag = 0
  157. ), 0) AS like_count,
  158. orv.comment_count,
  159. CASE
  160. WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
  161. ELSE 0
  162. END AS is_liked,
  163. orv.created_time
  164. FROM lawyer_order_review orv
  165. LEFT JOIN life_user lu ON lu.id = orv.user_id AND lu.delete_flag = 0
  166. LEFT JOIN lawyer_user lu2 ON lu2.id = orv.lawyer_user_id AND lu2.delete_flag = 0
  167. LEFT JOIN law_firm lf ON lf.id = lu2.firm_id AND lf.delete_flag = 0
  168. LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(orv.id, CHAR)
  169. AND llr.type = '7'
  170. AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
  171. AND llr.delete_flag = 0
  172. WHERE orv.delete_flag = 0
  173. AND orv.id = #{reviewId}
  174. </select>
  175. <!-- 评价列表结果映射 -->
  176. <resultMap id="PendingReviewVoResultMap" type="shop.alien.entity.store.vo.PendingReviewVo">
  177. <result column="order_id" property="orderId" />
  178. <result column="order_number" property="orderNumber" />
  179. <result column="lawyer_user_id" property="lawyerUserId" />
  180. <result column="lawyer_name" property="lawyerName" />
  181. <result column="lawyer_avatar" property="lawyerAvatar" />
  182. <result column="law_firm_name" property="lawFirmName" />
  183. <result column="overall_rating" property="overallRating" />
  184. <result column="review_content" property="reviewContent" />
  185. <result column="created_time" property="createdTime" />
  186. <result column="completed_time" property="completedTime" />
  187. </resultMap>
  188. <!-- 分页查询待评价列表(查询用户已完成但未评价的订单对应的律师信息) -->
  189. <select id="getPendingReviewList" resultMap="PendingReviewVoResultMap">
  190. SELECT
  191. lco.id AS order_id,
  192. lco.order_number,
  193. lco.lawyer_user_id,
  194. lu.name AS lawyer_name,
  195. lu.head_img AS lawyer_avatar,
  196. lf.firm_name AS law_firm_name,
  197. NULL AS overall_rating,
  198. NULL AS review_content,
  199. lco.end_time AS created_time,
  200. lco.end_time AS completed_time
  201. FROM lawyer_consultation_order lco
  202. LEFT JOIN lawyer_user lu ON lu.id = lco.lawyer_user_id AND lu.delete_flag = 0
  203. LEFT JOIN law_firm lf ON lf.id = lu.firm_id AND lf.delete_flag = 0
  204. LEFT JOIN lawyer_order_review orv ON orv.order_id = lco.id AND orv.delete_flag = 0
  205. WHERE lco.delete_flag = 0
  206. AND lco.order_status = 3
  207. AND lco.client_user_id = #{userId}
  208. AND orv.id IS NULL
  209. ORDER BY lco.end_time DESC
  210. </select>
  211. <!-- 统计律师的好评数(4.5-5分) -->
  212. <select id="getGoodReviewCountByLawyerUserId" resultType="java.lang.Integer">
  213. <![CDATA[
  214. SELECT COUNT(*)
  215. FROM lawyer_order_review
  216. WHERE lawyer_user_id = #{lawyerUserId}
  217. AND delete_flag = 0
  218. AND overall_rating IS NOT NULL
  219. AND overall_rating >= 4.5
  220. AND overall_rating <= 5
  221. ]]>
  222. </select>
  223. <!-- 统计律师的中评数(3-4分) -->
  224. <select id="getMediumReviewCountByLawyerUserId" resultType="java.lang.Integer">
  225. <![CDATA[
  226. SELECT COUNT(*)
  227. FROM lawyer_order_review
  228. WHERE lawyer_user_id = #{lawyerUserId}
  229. AND delete_flag = 0
  230. AND overall_rating IS NOT NULL
  231. AND overall_rating >= 3
  232. AND overall_rating < 4.5
  233. ]]>
  234. </select>
  235. <!-- 统计律师的差评数(0-2.5分,包含2.5) -->
  236. <select id="getBadReviewCountByLawyerUserId" resultType="java.lang.Integer">
  237. <![CDATA[
  238. SELECT COUNT(*)
  239. FROM lawyer_order_review
  240. WHERE lawyer_user_id = #{lawyerUserId}
  241. AND delete_flag = 0
  242. AND overall_rating IS NOT NULL
  243. AND overall_rating >= 0
  244. AND overall_rating < 3
  245. ]]>
  246. </select>
  247. <!-- 根据律师ID和类型分页查询评价列表(包含用户和律师信息) -->
  248. <select id="getReviewListByLawyerAndType" resultMap="OrderReviewVoResultMap">
  249. SELECT
  250. orv.id,
  251. orv.order_id,
  252. orv.order_number,
  253. orv.user_id,
  254. CASE
  255. WHEN orv.is_anonymous = 1 THEN '匿名用户'
  256. ELSE lu.user_name
  257. END AS user_name,
  258. CASE
  259. WHEN orv.is_anonymous = 1 THEN NULL
  260. ELSE lu.user_image
  261. END AS user_avatar,
  262. orv.lawyer_user_id,
  263. lu2.name AS lawyer_name,
  264. lu2.head_img AS lawyer_avatar,
  265. lf.firm_name AS law_firm_name,
  266. orv.overall_rating,
  267. orv.service_attitude_rating,
  268. orv.response_time_rating,
  269. orv.professional_ability_rating,
  270. orv.review_content,
  271. orv.is_anonymous,
  272. COALESCE((
  273. SELECT COUNT(1)
  274. FROM life_like_record llr_count
  275. WHERE CONVERT(llr_count.huifu_id, CHAR) = CONVERT(orv.id, CHAR)
  276. AND llr_count.type = '7'
  277. AND llr_count.delete_flag = 0
  278. ), 0) AS like_count,
  279. orv.comment_count,
  280. orv.review_images,
  281. CASE
  282. WHEN #{currentUserId} IS NOT NULL AND llr.id IS NOT NULL THEN 1
  283. ELSE 0
  284. END AS is_liked,
  285. orv.created_time
  286. FROM lawyer_order_review orv
  287. LEFT JOIN life_user lu ON lu.id = orv.user_id AND lu.delete_flag = 0
  288. LEFT JOIN lawyer_user lu2 ON lu2.id = orv.lawyer_user_id AND lu2.delete_flag = 0
  289. LEFT JOIN law_firm lf ON lf.id = lu2.firm_id AND lf.delete_flag = 0
  290. LEFT JOIN life_like_record llr ON CONVERT(llr.huifu_id, CHAR) = CONVERT(orv.id, CHAR)
  291. AND llr.type = '7'
  292. AND CONVERT(llr.dianzan_id, CHAR) = CONVERT(#{currentUserId}, CHAR)
  293. AND llr.delete_flag = 0
  294. WHERE orv.delete_flag = 0
  295. AND orv.lawyer_user_id = #{lawyerUserId}
  296. <if test="type != null">
  297. <choose>
  298. <when test="type == 1">
  299. <![CDATA[
  300. AND orv.overall_rating >= 4.5
  301. AND orv.overall_rating <= 5
  302. ]]>
  303. </when>
  304. <when test="type == 2">
  305. <![CDATA[
  306. AND orv.overall_rating >= 3
  307. AND orv.overall_rating < 4.5
  308. ]]>
  309. </when>
  310. <when test="type == 3">
  311. <![CDATA[
  312. AND orv.overall_rating >= 0
  313. AND orv.overall_rating < 3
  314. ]]>
  315. </when>
  316. <when test="type == 4">
  317. AND orv.review_images IS NOT NULL
  318. AND orv.review_images != ''
  319. AND TRIM(orv.review_images) != ''
  320. </when>
  321. </choose>
  322. </if>
  323. ORDER BY orv.created_time DESC
  324. </select>
  325. </mapper>