SecondGoodsInfoMapper.xml 11 KB

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