SecondGoodsInfoMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.second.SecondRecommendMapper">
  4. <resultMap id="BaseResultMap" type="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  5. <!--@mbggenerated-->
  6. <id column="id" property="id" jdbcType="INTEGER"/>
  7. <result column="user_id" property="userId" jdbcType="INTEGER"/>
  8. <result column="title" property="title" jdbcType="VARCHAR"/>
  9. <result column="description" property="description" jdbcType="VARCHAR"/>
  10. <result column="price" property="price" jdbcType="DECIMAL"/>
  11. <result column="amount" property="amount" jdbcType="DECIMAL"/>
  12. <result column="position" property="position" jdbcType="VARCHAR"/>
  13. <result column="like_count" property="likeCount" jdbcType="INTEGER"/>
  14. <result column="collect_count" property="collectCount" jdbcType="INTEGER"/>
  15. <result column="category_one_id" property="categoryOneId" jdbcType="INTEGER"/>
  16. <result column="category_two_id" property="categoryTwoId" jdbcType="INTEGER"/>
  17. <result column="label" property="label" jdbcType="VARCHAR"/>
  18. <result column="topic" property="topic" jdbcType="VARCHAR"/>
  19. <result column="trade_id" property="tradeId" jdbcType="INTEGER"/>
  20. <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
  21. <result column="created_user_id" property="createdUserId" jdbcType="INTEGER"/>
  22. <result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP"/>
  23. <result column="updated_user_id" property="updatedUserId" jdbcType="INTEGER"/>
  24. <result column="user_name" property="userName" jdbcType="VARCHAR"/>
  25. <result column="user_image" property="userImage" jdbcType="VARCHAR"/>
  26. <result column="goods_status" property="goodsStatus" jdbcType="INTEGER"/>
  27. <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
  28. <result column="dist" property="dist" jdbcType="VARCHAR"/>
  29. <result column="isLike" property="isLike" jdbcType="VARCHAR"/>
  30. <result column="home_image" property="homeImage" jdbcType="VARCHAR"/>
  31. <result column="user_phone" property="userPhone" jdbcType="VARCHAR"/>
  32. <result column="release_time" property="releaseTime" jdbcType="VARCHAR"/>
  33. <result column="video_first_frame" property="videoFirstFrame" jdbcType="VARCHAR"/>
  34. </resultMap>
  35. <!-- 分页查询推荐数据 -->
  36. <select id="getSecondRecommendByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  37. with shieldUser as (
  38. select g.id from life_blacklist lb inner join second_goods g
  39. on lb.blocked_id = g.user_id and g.delete_flag = '0' and g.goods_status = '3'
  40. where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
  41. and lb.blocker_id = #{userId}
  42. )
  43. SELECT * FROM (
  44. SELECT
  45. g.id,
  46. g.user_id,
  47. g.title,
  48. g.description,
  49. g.price,
  50. g.price as amount,
  51. g.position,
  52. g.like_count,
  53. g.collect_count,
  54. g.category_one_id,
  55. g.category_two_id,
  56. g.label,
  57. g.topic,
  58. g.trade_id,
  59. g.created_time,
  60. g.created_user_id,
  61. g.updated_time,
  62. g.updated_user_id,
  63. u.user_name,
  64. u.user_image,
  65. g.goods_status,
  66. g.delete_flag,
  67. g.release_time,
  68. g.video_first_frame,
  69. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  70. case when llr.id is null then '0' else '1' end likeStatus,
  71. g.home_image,
  72. CONCAT('user_', u.user_phone) as user_phone
  73. FROM
  74. second_goods g inner join life_user u on u.id = g.user_id and u.delete_flag = 0
  75. left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
  76. where g.delete_flag = 0
  77. <if test="typeId != null and typeId != '' ">
  78. and (g.category_one_id = #{typeId} or g.category_two_id =#{typeId} )
  79. </if>
  80. and not exists (select 1 from shieldUser s where s.id = g.id)
  81. and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
  82. and g.goods_status = 3
  83. and g.position != '' and g.position is not null
  84. order by dist, like_count desc, release_time desc
  85. ) a where a.dist &lt; #{radiusKm}
  86. </select>
  87. <!-- 分页查询关注数据concern -->
  88. <select id="querySecondConcernByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  89. with shieldUser as (
  90. select g.id from life_blacklist lb inner join second_goods g
  91. on lb.blocked_id = g.user_id and g.delete_flag = '0' and g.goods_status = '3'
  92. where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
  93. and lb.blocker_id = #{userId}
  94. )
  95. select
  96. g.id,
  97. g.user_id,
  98. g.title,
  99. g.description,
  100. g.price,
  101. g.price as amount,
  102. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  103. g.like_count,
  104. g.collect_count,
  105. g.label,
  106. g.topic,
  107. g.trade_id,
  108. g.created_time,
  109. g.created_user_id,
  110. g.updated_time,
  111. g.updated_user_id,
  112. g.release_time,
  113. u.user_name,
  114. u.user_image,
  115. CONCAT('user_', u.user_phone) as user_phone,
  116. g.goods_status,
  117. g.home_image,
  118. g.video_first_frame,
  119. case when llr.id is null then '0' else '1' end likeStatus,
  120. case when lc.id is null then '0' else '1' end collectStatus,
  121. (select count(1) from (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 UNION ALL
  122. SELECT t.id FROM store_comment t INNER JOIN (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0) d ON t.reply_id = d.id and business_type = 6 and delete_flag = 0) a ) as commentCount
  123. <!-- (SELECT count(1) FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 ) as commentCount-->
  124. from
  125. life_fans f inner join life_user u on
  126. f.followed_id = CONCAT('user_', u.user_phone) and u.delete_flag = 0
  127. inner join second_goods g on
  128. u.id = g.user_id
  129. and g.goods_status = 3
  130. and g.delete_flag = 0
  131. left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
  132. left join life_collect lc on lc.business_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0 and lc.business_type = 1
  133. where
  134. f.fans_id = #{phoneId} and f.delete_flag = 0
  135. and not exists (select 1 from shieldUser s where s.id = g.id)
  136. and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
  137. and g.position != '' and g.position is not null
  138. order by g.release_time desc
  139. </select>
  140. <select id="querySecondCommentInfo" resultType="shop.alien.entity.second.vo.SecondCommentVo">
  141. select
  142. business_id,
  143. comment_content,
  144. created_time,
  145. user_name,
  146. user_image,
  147. rn
  148. from (
  149. select
  150. c.business_id,
  151. c.comment_content,
  152. c.created_time,
  153. u.user_name,
  154. u.user_image,
  155. row_number() over (partition by c.business_id order by c.created_time desc) as rn
  156. from
  157. store_comment c inner join life_user u on c.user_id = u.id and u.delete_flag = 0
  158. where c.delete_flag = 0 and c.business_type = 7
  159. and business_id in
  160. <foreach collection="ids" item="id" open="(" separator="," close=")">
  161. ${id}
  162. </foreach>
  163. ) a where rn <![CDATA[ <= ]]> 2
  164. </select>
  165. <!-- 分页查询新发数据 -->
  166. <select id="querySecondNewGoodsByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  167. with shieldUser as (
  168. select g.id from life_blacklist lb inner join second_goods g
  169. on lb.blocked_id = g.user_id and g.delete_flag = '0' and g.goods_status = '3'
  170. where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
  171. and lb.blocker_id = #{userId}
  172. )
  173. SELECT * FROM (
  174. SELECT
  175. g.id,
  176. g.user_id,
  177. g.title,
  178. g.description,
  179. g.price,
  180. g.price as amount,
  181. g.position,
  182. g.like_count,
  183. g.collect_count,
  184. g.category_one_id,
  185. g.category_two_id,
  186. g.label,
  187. g.topic,
  188. g.trade_id,
  189. g.created_time,
  190. g.created_user_id,
  191. g.updated_time,
  192. g.updated_user_id,
  193. g.release_time,
  194. u.user_name,
  195. u.user_image,
  196. CONCAT('user_', u.user_phone) as user_phone,
  197. g.goods_status,
  198. g.delete_flag,
  199. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  200. g.home_image,
  201. g.video_first_frame,
  202. case when llr.id is null then '0' else '1' end likeStatus,
  203. case when lc.id is null then '0' else '1' end collectStatus,
  204. (select count(1) from (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 UNION ALL
  205. SELECT t.id FROM store_comment t INNER JOIN (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0) d ON t.reply_id = d.id and business_type = 6 and delete_flag = 0) a ) as commentCount
  206. <!-- (SELECT count(1) FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 ) as commentCount-->
  207. FROM
  208. second_goods g inner join life_user u on u.id = g.user_id
  209. left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
  210. left join life_collect lc on lc.business_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0 and lc.business_type = 1
  211. where g.delete_flag = 0
  212. and not exists (select 1 from shieldUser s where s.id = g.id)
  213. and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
  214. and g.goods_status = 3
  215. and g.position != '' and g.position is not null
  216. <choose>
  217. <when test="timeRange == 1">
  218. and g.release_time &gt;= DATE_SUB(NOW(), INTERVAL 12 HOUR)
  219. </when>
  220. <when test="timeRange == 2">
  221. and g.release_time &gt;= DATE_SUB(NOW(), INTERVAL 24 HOUR)
  222. </when>
  223. <when test="timeRange == 3">
  224. and g.release_time &gt;= DATE_SUB(NOW(), INTERVAL 48 HOUR)
  225. </when>
  226. <when test="timeRange == 4">
  227. and g.release_time &gt;= DATE_SUB(NOW(), INTERVAL 72 HOUR)
  228. </when>
  229. </choose>
  230. order by g.release_time desc
  231. ) a where a.dist &lt; #{radiusKm}
  232. </select>
  233. <select id="querySecondGoodsDetail" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  234. select
  235. g.id,
  236. g.user_id,
  237. g.title,
  238. g.description,
  239. g.price as amount,
  240. g.position,
  241. g.like_count,
  242. g.collect_count,
  243. g.category_one_id,
  244. g.category_two_id,
  245. g.label,
  246. g.topic,
  247. g.home_image,
  248. g.release_time,
  249. g.video_first_frame,
  250. lu.user_name,
  251. CONCAT('user_', lu.user_phone) as user_phone,
  252. lu.user_image,
  253. goods_status,
  254. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  255. case when llr.id is null then '0' else '1' end likeStatus,
  256. case when lc.id is null then '0' else '1' end collectStatus
  257. from second_goods g inner join life_user lu on g.user_id = lu.id and lu.delete_flag = 0
  258. left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
  259. left join life_collect lc on lc.business_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0 and lc.business_type = 1
  260. where g.id = #{goodsId} and g.delete_flag = 0
  261. and g.position != '' and g.position is not null
  262. </select>
  263. </mapper>