LifeUserDynamicsMapper.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.id,
  87. dy.phone_id,
  88. dy.title,
  89. dy.context,
  90. dy.image_path,
  91. dy.address,
  92. dy.liulan_count,
  93. dy.dianzan_count,
  94. dy.type,
  95. dy.draft,
  96. dy.delete_flag,
  97. dy.created_time,
  98. dy.created_user_id,
  99. dy.updated_time,
  100. dy.updated_user_id,
  101. dy.address_name,
  102. dy.address_context,
  103. dy.address_province,
  104. dy.top_status,
  105. dy.top_time,
  106. dy.enable_status,
  107. dy.business_id,
  108. dy.expert_id,
  109. dy.transfer_count,
  110. dy.reality_count,
  111. info.score_avg as scoreAvg,
  112. info.store_name as storeName,
  113. info.id as storeId,
  114. info.business_section as businessSection,
  115. COUNT(comment.id) AS commentCount,
  116. works.id as workId
  117. FROM
  118. life_user_dynamics AS dy
  119. INNER JOIN
  120. life_user_expert_order AS expertOrder
  121. ON dy.business_id = expertOrder.id
  122. AND expertOrder.delete_flag = 0
  123. INNER JOIN
  124. store_info AS info
  125. ON expertOrder.store_id = info.id
  126. AND info.delete_flag = 0
  127. LEFT JOIN
  128. store_comment AS comment
  129. ON comment.store_id = info.id
  130. AND comment.delete_flag = 0
  131. AND comment.business_type in ( 5 )
  132. LEFT JOIN
  133. life_user_expert_works AS works
  134. ON dy.id = works.dynamics_id
  135. WHERE
  136. dy.id = #{id}
  137. AND dy.delete_flag = 0
  138. </select>
  139. <select id="getStoreDynamicslist" resultType="shop.alien.entity.store.vo.LifeUserDynamicsVo">
  140. select
  141. dyna1.*,
  142. COUNT(dyna1.id) AS fansCount
  143. from
  144. (
  145. select
  146. dyna.*,
  147. COUNT(sc.id) AS commentCount,
  148. COUNT(lm.id) AS transferNum
  149. from
  150. (
  151. with dynamice as(
  152. select
  153. CASE
  154. WHEN image_path REGEXP '.mp4|.avi|.flv|.mkv|.rmvb|.wmv|.3gp|.mov' THEN 2
  155. WHEN image_path REGEXP '.jpg|.jpeg|.png|.bmp|.webp|.gif|.svg' THEN 1
  156. ELSE 0
  157. 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,
  158. business_id
  159. from life_user_dynamics
  160. where phone_id = #{phoneId} and delete_flag = 0 and draft = 0 order by created_time desc
  161. )
  162. select
  163. dynamice.*,
  164. user.nick_name userName,
  165. user.head_img userImage,
  166. info.id storeUserId,
  167. info.store_name storeName,
  168. user.id storeOrUserId,
  169. 0 isExpert,
  170. IF(llr.huifu_id IS NOT NULL or llr1.huifu_id IS NOT NULL, 1, 0) AS isLike
  171. from
  172. dynamice
  173. left join store_user user on
  174. dynamice.phone = user.phone
  175. and user.delete_flag = 0
  176. left join store_info info on
  177. info.id = user.store_id
  178. and info.delete_flag = 0
  179. left join store_img img on
  180. img.store_id = user.store_id
  181. and img.img_type = '10'
  182. and img.delete_flag = 0
  183. left join life_like_record llr on
  184. llr.huifu_id = dynamice.id
  185. and llr.delete_flag = 0
  186. and llr.dianzan_id = (
  187. select
  188. CONCAT('user_', lu1.user_phone)
  189. from
  190. life_user lu1
  191. where
  192. lu1.id = #{userId})
  193. left join life_like_record llr1 on
  194. llr1.huifu_id = dynamice.id
  195. and llr1.delete_flag = 0
  196. and llr1.dianzan_id = (
  197. select
  198. CONCAT('store_', lu2.phone)
  199. from
  200. store_user lu2
  201. where
  202. lu2.id = #{userId})
  203. where
  204. dynamice.userType = 'store') dyna
  205. left join life_comment lc on
  206. lc.dongtai_shequ_id = dyna.id
  207. left join store_comment sc on
  208. sc.business_id = dyna.id
  209. and sc.business_type = 2
  210. and sc.delete_flag = 0
  211. left join life_message lm on
  212. lm.business_id = dyna.id
  213. GROUP BY
  214. dyna.id
  215. order by
  216. dyna.created_time desc) dyna1
  217. left join life_fans lf1 on
  218. lf1.followed_id = dyna1.phoneId
  219. GROUP by
  220. dyna1.id
  221. order by
  222. dyna1.top_status desc,
  223. dyna1.top_time desc
  224. </select>
  225. </mapper>