LifeUserDynamicsMapper.xml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.LifeUserDynamicsMapper">
  4. <select id="getDynamicsList" resultType="shop.alien.entity.store.vo.LifeUserDynamicsVo">
  5. select dyna1.*, COUNT(dyna1.id) AS fansCount from (
  6. select dyna.*,COUNT(sc.id) AS commentCount, COUNT(lm.id) AS transferNum from (
  7. with dynamice as(
  8. select
  9. CASE
  10. WHEN image_path REGEXP '.mp4|.avi|.flv|.mkv|.rmvb|.wmv|.3gp|.mov' THEN 2
  11. WHEN image_path REGEXP '.jpg|.jpeg|.png|.bmp|.webp|.gif|.svg' THEN 1
  12. ELSE 0
  13. END AS dynamicsType,id, title, phone_id phoneId, context, image_path, address,address_name,address_context, liulan_count, dianzan_count, type, created_time, substring_index(phone_id, '_', 1) userType, substring_index(phone_id, '_', -1) phone, draft , address_province, top_status, top_time, enable_status
  14. from life_user_dynamics
  15. where delete_flag = 0 and draft = 0 order by created_time desc
  16. )
  17. select dynamice.*, user.nick_name userName, user.head_img userImage, info.id storeUserId, user.id storeOrUserId, 0 isExpert
  18. from dynamice
  19. left join store_user user on dynamice.phone = user.phone and user.delete_flag = 0
  20. left join store_info info on info.id = user.store_id and info.delete_flag = 0
  21. left join store_img img on img.store_id = user.store_id and img.img_type = '10' and img.delete_flag = 0
  22. where dynamice.userType = 'store'
  23. union
  24. select dynamice.*, user.user_name userName, user.user_image userImage, user.id storeUserId, user.id storeOrUserId, IF(lue.expert_code IS NOT NULL , 1, 0) AS isExpert
  25. from dynamice
  26. join life_user user on dynamice.phone = user.user_phone and user.delete_flag = 0
  27. left join life_user_expert lue on lue.user_id = user.id and lue.delete_flag = 0
  28. where dynamice.userType = 'user') dyna
  29. left join life_comment lc on lc.dongtai_shequ_id = dyna.id
  30. left join store_comment sc on sc.business_id = dyna.id and sc.business_type = 2 and sc.delete_flag = 0
  31. left join life_message lm on lm.business_id = dyna.id
  32. GROUP BY dyna.id order by dyna.created_time desc) dyna1
  33. left join life_fans lf1 on lf1.followed_id = dyna1.phoneId
  34. where 1=1
  35. <if test="nickName != null and nickName != ''">
  36. AND dyna1.userName LIKE CONCAT('%', #{nickName}, '%')
  37. </if>
  38. <if test="userType != null and userType != ''">
  39. AND dyna1.userType = #{userType}
  40. </if>
  41. <if test="dynamicsType != null and dynamicsType != ''">
  42. AND dyna1.dynamicsType = #{dynamicsType}
  43. </if>
  44. <if test="releaseStartTime != null and releaseStartTime != ''">
  45. AND dyna1.created_time >= #{releaseStartTime}
  46. </if>
  47. <if test="releaseEndTime != null and releaseEndTime != ''">
  48. AND dyna1.created_time &lt;= #{releaseEndTime}
  49. </if>
  50. GROUP by dyna1.id order by dyna1.top_status desc, dyna1.top_time desc
  51. </select>
  52. <select id="getDynamicsDetail" resultType="shop.alien.entity.store.vo.LifeUserDynamicsVo">
  53. select dyna1.*, COUNT(dyna1.id) AS fansCount from (
  54. select dyna.*,COUNT(sc.id) AS commentCount, COUNT(lm.id) AS transferNum from (
  55. with dynamice as(
  56. select
  57. CASE
  58. WHEN image_path REGEXP '.mp4|.avi|.flv|.mkv|.rmvb|.wmv|.3gp|.mov' THEN 2
  59. WHEN image_path REGEXP '.jpg|.jpeg|.png|.bmp|.webp|.gif|.svg' THEN 1
  60. ELSE 0
  61. END AS dynamicsType, id, title, phone_id phoneId, context, image_path, address,address_name,address_context, liulan_count, dianzan_count, type, created_time, substring_index(phone_id, '_', 1) userType, substring_index(phone_id, '_', -1) phone, draft , address_province, top_status, top_time, enable_status
  62. from life_user_dynamics
  63. where id = #{id} and delete_flag = 0 and draft = 0 order by created_time desc
  64. )
  65. select dynamice.*, user.nick_name userName, user.head_img userImage, info.id storeUserId, user.id storeOrUserId, 0 isExpert
  66. from dynamice
  67. left join store_user user on dynamice.phone = user.phone and user.delete_flag = 0
  68. left join store_info info on info.id = user.store_id and info.delete_flag = 0
  69. left join store_img img on img.store_id = user.store_id and img.img_type = '10' and img.delete_flag = 0
  70. where dynamice.userType = 'store'
  71. union
  72. select dynamice.*, user.user_name userName, user.user_image userImage, user.id storeUserId, user.id storeOrUserId, IF(lue.expert_code IS NOT NULL , 1, 0) AS isExpert
  73. from dynamice
  74. join life_user user on dynamice.phone = user.user_phone and user.delete_flag = 0
  75. left join life_user_expert lue on lue.user_id = user.id and lue.delete_flag = 0
  76. where dynamice.userType = 'user') dyna
  77. left join life_comment lc on lc.dongtai_shequ_id = dyna.id
  78. left join store_comment sc on sc.business_id = dyna.id and sc.business_type = 2 and sc.delete_flag = 0
  79. left join life_message lm on lm.business_id = dyna.id
  80. GROUP BY dyna.id order by dyna.created_time desc) dyna1
  81. left join life_fans lf1 on lf1.followed_id = dyna1.phoneId
  82. GROUP by dyna1.id order by dyna1.top_status desc, dyna1.top_time desc
  83. </select>
  84. <select id="getExpertDynamicsDetail" resultType="shop.alien.entity.store.vo.LifeUserDynamicsVo">
  85. SELECT
  86. dy.*,
  87. info.score_avg as scoreAvg,
  88. info.store_name as storeName,
  89. info.id as storeId,
  90. info.business_section as businessSection,
  91. COUNT(comment.id) AS commentCount
  92. FROM
  93. life_user_dynamics AS dy
  94. INNER JOIN life_user_expert_order AS expertOrder
  95. ON dy.business_id = expertOrder.id
  96. AND expertOrder.delete_flag = 0
  97. INNER JOIN store_info AS info
  98. ON expertOrder.store_id = info.id
  99. AND info.delete_flag = 0
  100. LEFT JOIN store_comment AS comment
  101. ON comment.store_id = info.id
  102. AND comment.delete_flag = 0
  103. AND comment.business_type in ( 5 )
  104. WHERE
  105. dy.id = #{id}
  106. AND dy.delete_flag = 0
  107. </select>
  108. <select id="getStoreDynamicslist" resultType="shop.alien.entity.store.vo.LifeUserDynamicsVo">
  109. select
  110. dyna1.*,
  111. COUNT(dyna1.id) AS fansCount
  112. from
  113. (
  114. select
  115. dyna.*,
  116. COUNT(sc.id) AS commentCount,
  117. COUNT(lm.id) AS transferNum
  118. from
  119. (
  120. with dynamice as(
  121. select
  122. CASE
  123. WHEN image_path REGEXP '.mp4|.avi|.flv|.mkv|.rmvb|.wmv|.3gp|.mov' THEN 2
  124. WHEN image_path REGEXP '.jpg|.jpeg|.png|.bmp|.webp|.gif|.svg' THEN 1
  125. ELSE 0
  126. END AS dynamicsType, id, title, phone_id phoneId, context, image_path, address, address_name, address_context, liulan_count, dianzan_count, type, created_time, substring_index(phone_id, '_', 1) userType, substring_index(phone_id, '_', -1) phone, draft , address_province, top_status, top_time, enable_status,
  127. order_gmv,business_id
  128. from life_user_dynamics
  129. where phone_id = #{phoneId} and delete_flag = 0 and draft = 0 order by created_time desc
  130. )
  131. select
  132. dynamice.*,
  133. user.nick_name userName,
  134. user.head_img userImage,
  135. info.id storeUserId,
  136. user.id storeOrUserId,
  137. 0 isExpert,
  138. IF(llr.huifu_id IS NOT NULL or llr1.huifu_id IS NOT NULL, 1, 0) AS isLike
  139. from
  140. dynamice
  141. left join store_user user on
  142. dynamice.phone = user.phone
  143. and user.delete_flag = 0
  144. left join store_info info on
  145. info.id = user.store_id
  146. and info.delete_flag = 0
  147. left join store_img img on
  148. img.store_id = user.store_id
  149. and img.img_type = '10'
  150. and img.delete_flag = 0
  151. left join life_like_record llr on
  152. llr.huifu_id = dynamice.id
  153. and llr.delete_flag = 0
  154. and llr.dianzan_id = (
  155. select
  156. CONCAT('user_', lu1.user_phone)
  157. from
  158. life_user lu1
  159. where
  160. lu1.id = #{userId})
  161. left join life_like_record llr1 on
  162. llr1.huifu_id = dynamice.id
  163. and llr1.delete_flag = 0
  164. and llr1.dianzan_id = (
  165. select
  166. CONCAT('store_', lu2.phone)
  167. from
  168. store_user lu2
  169. where
  170. lu2.id = #{userId})
  171. where
  172. dynamice.userType = 'store') dyna
  173. left join life_comment lc on
  174. lc.dongtai_shequ_id = dyna.id
  175. left join store_comment sc on
  176. sc.business_id = dyna.id
  177. and sc.business_type = 2
  178. and sc.delete_flag = 0
  179. left join life_message lm on
  180. lm.business_id = dyna.id
  181. GROUP BY
  182. dyna.id
  183. order by
  184. dyna.created_time desc) dyna1
  185. left join life_fans lf1 on
  186. lf1.followed_id = dyna1.phoneId
  187. GROUP by
  188. dyna1.id
  189. order by
  190. dyna1.top_status desc,
  191. dyna1.top_time desc
  192. </select>
  193. </mapper>