SecondGoodsInfoMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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
  44. g.id,
  45. g.user_id,
  46. g.title,
  47. g.description,
  48. g.price,
  49. g.price as amount,
  50. g.position,
  51. g.like_count,
  52. g.collect_count,
  53. g.category_one_id,
  54. g.category_two_id,
  55. g.label,
  56. g.topic,
  57. g.trade_id,
  58. g.created_time,
  59. g.created_user_id,
  60. g.updated_time,
  61. g.updated_user_id,
  62. u.user_name,
  63. u.user_image,
  64. g.goods_status,
  65. g.delete_flag,
  66. g.release_time,
  67. g.video_first_frame,
  68. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  69. case when llr.id is null then '0' else '1' end likeStatus,
  70. g.home_image,
  71. CONCAT('user_', u.user_phone) as user_phone
  72. FROM
  73. second_goods g inner join life_user u on u.id = g.user_id and u.delete_flag = 0
  74. 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
  75. where g.delete_flag = 0
  76. <if test="typeId != null and typeId != '' ">
  77. and (g.category_one_id = #{typeId} or g.category_two_id =#{typeId} )
  78. </if>
  79. and not exists (select 1 from shieldUser s where s.id = g.id)
  80. 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)
  81. and g.goods_status = 3
  82. and g.position != '' and g.position is not null
  83. order by dist, like_count desc, release_time desc
  84. </select>
  85. <!-- 分页查询关注数据concern -->
  86. <select id="querySecondConcernByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  87. with shieldUser as (
  88. select g.id from life_blacklist lb inner join second_goods g
  89. on lb.blocked_id = g.user_id and g.delete_flag = '0' and g.goods_status = '3'
  90. where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
  91. and lb.blocker_id = #{userId}
  92. )
  93. select
  94. g.id,
  95. g.user_id,
  96. g.title,
  97. g.description,
  98. g.price,
  99. g.price as amount,
  100. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  101. g.like_count,
  102. g.collect_count,
  103. g.label,
  104. g.topic,
  105. g.trade_id,
  106. g.created_time,
  107. g.created_user_id,
  108. g.updated_time,
  109. g.updated_user_id,
  110. g.release_time,
  111. u.user_name,
  112. u.user_image,
  113. CONCAT('user_', u.user_phone) as user_phone,
  114. g.goods_status,
  115. g.home_image,
  116. g.video_first_frame,
  117. case when llr.id is null then '0' else '1' end likeStatus,
  118. case when lc.id is null then '0' else '1' end collectStatus,
  119. (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
  120. 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
  121. <!-- (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-->
  122. from
  123. life_fans f inner join life_user u on
  124. f.followed_id = CONCAT('user_', u.user_phone) and u.delete_flag = 0
  125. inner join second_goods g on
  126. u.id = g.user_id
  127. and g.goods_status = 3
  128. and g.delete_flag = 0
  129. 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
  130. 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
  131. where
  132. f.fans_id = #{phoneId} and f.delete_flag = 0
  133. and not exists (select 1 from shieldUser s where s.id = g.id)
  134. 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)
  135. and g.position != '' and g.position is not null
  136. order by g.release_time desc
  137. </select>
  138. <select id="querySecondCommentInfo" resultType="shop.alien.entity.second.vo.SecondCommentVo">
  139. select
  140. business_id,
  141. comment_content,
  142. created_time,
  143. user_name,
  144. user_image,
  145. rn
  146. from (
  147. select
  148. c.business_id,
  149. c.comment_content,
  150. c.created_time,
  151. u.user_name,
  152. u.user_image,
  153. row_number() over (partition by c.business_id order by c.created_time desc) as rn
  154. from
  155. store_comment c inner join life_user u on c.user_id = u.id and u.delete_flag = 0
  156. where c.delete_flag = 0 and c.business_type = 7
  157. and business_id in
  158. <foreach collection="ids" item="id" open="(" separator="," close=")">
  159. ${id}
  160. </foreach>
  161. ) a where rn <![CDATA[ <= ]]> 2
  162. </select>
  163. <!-- 分页查询新发数据 -->
  164. <select id="querySecondNewGoodsByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  165. with shieldUser as (
  166. select g.id from life_blacklist lb inner join second_goods g
  167. on lb.blocked_id = g.user_id and g.delete_flag = '0' and g.goods_status = '3'
  168. where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
  169. and lb.blocker_id = #{userId}
  170. )
  171. SELECT
  172. g.id,
  173. g.user_id,
  174. g.title,
  175. g.description,
  176. g.price,
  177. g.price as amount,
  178. g.position,
  179. g.like_count,
  180. g.collect_count,
  181. g.category_one_id,
  182. g.category_two_id,
  183. g.label,
  184. g.topic,
  185. g.trade_id,
  186. g.created_time,
  187. g.created_user_id,
  188. g.updated_time,
  189. g.updated_user_id,
  190. g.release_time,
  191. u.user_name,
  192. u.user_image,
  193. CONCAT('user_', u.user_phone) as user_phone,
  194. g.goods_status,
  195. g.delete_flag,
  196. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  197. g.home_image,
  198. g.video_first_frame,
  199. case when llr.id is null then '0' else '1' end likeStatus,
  200. case when lc.id is null then '0' else '1' end collectStatus,
  201. (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
  202. 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
  203. <!-- (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-->
  204. FROM
  205. second_goods g inner join life_user u on u.id = g.user_id
  206. 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
  207. 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
  208. where g.delete_flag = 0
  209. and not exists (select 1 from shieldUser s where s.id = g.id)
  210. 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)
  211. and g.goods_status = 3
  212. and g.position != '' and g.position is not null
  213. order by g.release_time desc
  214. </select>
  215. <select id="querySecondGoodsDetail" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
  216. select
  217. g.id,
  218. g.user_id,
  219. g.title,
  220. g.description,
  221. g.price as amount,
  222. g.position,
  223. g.like_count,
  224. g.collect_count,
  225. g.category_one_id,
  226. g.category_two_id,
  227. g.label,
  228. g.topic,
  229. g.home_image,
  230. g.release_time,
  231. g.video_first_frame,
  232. lu.user_name,
  233. CONCAT('user_', lu.user_phone) as user_phone,
  234. lu.user_image,
  235. goods_status,
  236. ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
  237. case when llr.id is null then '0' else '1' end likeStatus,
  238. case when lc.id is null then '0' else '1' end collectStatus
  239. from second_goods g inner join life_user lu on g.user_id = lu.id and lu.delete_flag = 0
  240. 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
  241. 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
  242. where g.id = #{goodsId} and g.delete_flag = 0
  243. and g.position != '' and g.position is not null
  244. </select>
  245. </mapper>