GroupRelationMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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="com.cyksj.mapper.GroupsRelationMapper">
  4. <update id="updateExpiryTime">
  5. update groups_relation
  6. set start_time = null,
  7. expiry_time = null,
  8. status = #{entity.status},
  9. renew_status = #{entity.renewStatus},
  10. is_handle = #{entity.isHandle},
  11. user_id = #{entity.userId},
  12. account = null,
  13. customer_service = null,
  14. verify_code = null,
  15. password = null,
  16. recharge_status = null,
  17. send_time = null,
  18. submit_time = null,
  19. operator = null,
  20. yhs_id = 0
  21. where id = #{entity.id}
  22. <if test="expireTime != null">
  23. and expiry_time = #{expireTime}
  24. </if>
  25. </update>
  26. <select id="getAccountIdsByUserIdOrNickNameOrSubmitAccount" resultType="java.lang.Long">
  27. select gr.groups_id
  28. from groups_relation gr,
  29. `user` u
  30. where gr.user_id = u.id
  31. <if test="nickName != null and nickName != ''">
  32. and u.nickname like '%${nickName}%'
  33. </if>
  34. <if test="userId != null">
  35. and u.id = #{userId,jdbcType=BIGINT}
  36. </if>
  37. <if test="submitAccount != null and submitAccount != ''">
  38. and gr.account = #{submitAccount,jdbcType=VARCHAR}
  39. </if>
  40. group by gr.groups_id
  41. </select>
  42. <select id="getGroupTripsSkuIdByRelationId" resultType="java.lang.Long">
  43. select gt.sku_id from `groups_trips` gt left join `groups_relation` gr on gr.groups_id = gt.id where gr.id = #{relationId} limit 1
  44. </select>
  45. <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
  46. select s.id
  47. from (select gt.id, min(gr.expiry_time) minExpiryTime
  48. from `groups_trips` gt
  49. left join `groups_relation` gr on gr.groups_id = gt.id
  50. where gt.sku_id = #{skuId}
  51. and gt.available_num > 0
  52. and gt.status = 'validity'
  53. and gr.status = 'validity'
  54. and gr.user_id != 0
  55. and gr.expiry_time is not null
  56. group by gr.groups_id) s
  57. where s.minExpiryTime >= #{minExpiryTime}
  58. order by minExpiryTime desc limit 1
  59. </select>
  60. <select id="selectRelationByGoodsId" resultType="com.cyksj.model.manage.views.GroupsRelationView">
  61. select gr.*
  62. from groups_relation gr
  63. left join groups_trips gt on gr.groups_id = gt.id
  64. left join account a on a.id = gt.account_id
  65. left join user u on gr.user_id = u.id
  66. left join goods_don g on a.goods_id = g.id
  67. where g.id = #{goodsId}
  68. and gr.user_id = #{userId}
  69. and gt.status = 'validity'
  70. and gr.status = 'validity'
  71. and gr.yhs_id = #{yhsId}
  72. </select>
  73. <select id="getGroupRelationViewByUserIdAndRelationId"
  74. resultType="com.cyksj.model.manage.views.GroupsRelationView">
  75. select gr.*,
  76. a.account as tripsAccount,
  77. g.title
  78. from groups_relation gr
  79. left join groups_trips gt on gt.id = gr.groups_id
  80. left join account a on a.id = gt.account_id
  81. left join goods_don g on g.id = a.goods_id
  82. where gr.id = #{relationId} and gr.user_id = #{userId}
  83. </select>
  84. <select id="getBindPhoneByUserId" resultType="java.lang.String">
  85. select if(login_phone = '',ud.phone,login_phone) as phone from (select id,login_phone from user where id = #{userId} limit 1) u left join user_bind_detail ud
  86. on ud.user_id = u.id
  87. </select>
  88. <select id="selectViewPwdCount" resultType="java.lang.Integer">
  89. select count(distinct relation_id)
  90. from (select id, user_id from `groups_relation` where groups_id = #{groupsId} and `status` = 'validity') s
  91. inner join chat_gpt_pwd_view_record cr on cr.relation_id = s.id and s.user_id = cr.user_id
  92. </select>
  93. <select id="selectRandomOneRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  94. select *
  95. from groups_relation
  96. where groups_id = #{groupsId}
  97. and user_id = 0
  98. and status = 'none'
  99. order by rand() limit 1
  100. </select>
  101. <select id="selectExpiredRelationByCondition" resultType="com.cyksj.model.entity.GroupsRelation">
  102. select gr.*
  103. from groups_relation gr
  104. inner join groups_trips gt on gt.id = gr.groups_id
  105. where gt.sku_id not in
  106. <foreach collection="list" item="item" open="(" separator="," close=")">
  107. #{item}
  108. </foreach>
  109. and gr.expiry_time &lt;= #{now}
  110. </select>
  111. <select id="selectOutsideRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  112. select *
  113. from groups_relation
  114. where groups_id = #{groupsId}
  115. and user_id = 0
  116. and num > #{relationNum}
  117. and status = 'outside'
  118. order by rand() limit 1
  119. </select>
  120. <select id="selectExpiredChatGPTRelation" resultType="com.cyksj.model.entity.GroupsRelation">
  121. select gr.*
  122. from groups_relation gr
  123. inner join groups_trips gt on gt.id = gr.groups_id
  124. where gt.sku_id in
  125. <foreach collection="list" item="item" open="(" separator="," close=")">
  126. #{item}
  127. </foreach>
  128. and gr.expiry_time &lt;= #{nextBeginDay}
  129. </select>
  130. <select id="getUserRelationUserViews" resultType="com.cyksj.model.views.GroupsRelationUserView">
  131. select gr.*,
  132. u.nickname,
  133. u.headimgurl
  134. from (select * from (select id as relation_id,
  135. user_id,
  136. 1 as isSelf from groups_relation where id = #{relationId}
  137. and status in
  138. <foreach collection="status" item="item" open="(" separator="," close=")">
  139. #{item}
  140. </foreach>
  141. limit 1)s1
  142. union all
  143. select * from (select id as realtion_id,
  144. user_id,
  145. if(user_id = #{userId},true,false) as isSelf from groups_relation where id != #{relationId}
  146. and groups_id = #{groupsId}
  147. and status in
  148. <foreach collection="status" item="item" open="(" separator="," close=")">
  149. #{item}
  150. </foreach>
  151. limit 4)s2)gr inner join user u on u.id = gr.user_id
  152. </select>
  153. <select id="getTicketGoodsId" resultType="java.lang.Long">
  154. select distinct goods_id from (select sku.goods_id from (select * from `groups_relation` where status in
  155. <foreach collection="status" item="item" open="(" separator="," close=")">
  156. #{item}
  157. </foreach>
  158. and user_id in
  159. <foreach collection="list" item="item" open="(" separator="," close=")">
  160. #{item}
  161. </foreach>)gr left join groups_trips gt on gt.id = gr.groups_id
  162. left join goods_don_sku sku on sku.id = gt.sku_id
  163. union all
  164. select goods_id from order_don o where user_id in
  165. <foreach collection="list" item="item" open="(" separator="," close=")">
  166. #{item}
  167. </foreach>
  168. and relation_id = 0 and status not in ('close','noPayment','refund'))s
  169. </select>
  170. <select id="getRecommendGoodsViews" resultType="com.cyksj.model.views.UserRecommendGoodsFrontView">
  171. select * from (select
  172. id as goodsId,
  173. title,
  174. logo,
  175. img,
  176. tags,
  177. sort_by,
  178. `type`,
  179. min_months as months,
  180. min_days as days,
  181. min_price as price,
  182. (
  183. case when type = 2 and ${isPayNf} then 999
  184. when category = 1 then 888
  185. when category = 2 then 777
  186. when category = 3 then 755
  187. else 666 end
  188. ) as sorted
  189. from `goods_don` where id not in
  190. <foreach collection="list" item="item" open="(" separator="," close=")">
  191. #{item}
  192. </foreach>
  193. <if test="isPayNf">
  194. and type in (1,2)
  195. </if>
  196. <if test="!isPayNf">
  197. and type = 1
  198. </if>
  199. and deleted is true and status is true) s order by s.sorted desc,sort_by asc
  200. </select>
  201. <select id="getOutSideGroupsTripsRelationByGoodsId" resultType="java.lang.Long">
  202. select gt.id
  203. from `groups_trips` gt
  204. inner join account a on a.id = gt.account_id
  205. where gt.sku_id = #{skuId}
  206. and gt.status = 'validity'
  207. and a.expiry_time >= #{beginOfDay}
  208. and (select count(*)
  209. from groups_relation gr
  210. where gr.num > #{skuNum}
  211. and gr.groups_id = gt.id
  212. and gr.user_id
  213. != 0)
  214. &lt; #{extraNum}
  215. and
  216. (
  217. select count(*)
  218. from groups_relation gr
  219. where gr.groups_id = gt.id
  220. and gr.user_id
  221. = #{userId}) = 0
  222. order by RAND() limit 1
  223. </select>
  224. <select id="selectAvailableRelation" resultType="java.lang.Integer">
  225. select count(gr.id)
  226. from account a
  227. inner join `groups_trips` gt on gt.account_id = a.id
  228. and gt.`status` = 'validity'
  229. and gt.sku_id = #{skuId}
  230. inner join groups_relation gr on gr.groups_id = gt.id
  231. and gr.status in ('none','locking')
  232. and gr.num &lt;= #{skuNum}
  233. </select>
  234. <select id="selectSpecialGroupsRelationAvailable" resultType="java.lang.Integer">
  235. select ifnull(sum(a1 + (#{extractNum} - t1)), 0)
  236. from (select gt.id,
  237. (select count(*)
  238. from groups_relation gr2
  239. where gr2.groups_id = gt.id
  240. and num > #{skuNum}
  241. and num &lt;= #{maxNum}) t1,
  242. (select count(*)
  243. from groups_relation gr2
  244. where gr2.groups_id = gt.id
  245. and num > #{skuNum}
  246. and num &lt;= #{maxNum}
  247. and (gr2.user_id = 0 or gr2.status = 'locking')) a1
  248. from account a
  249. inner join `groups_trips` gt on gt.account_id = a.id
  250. and gt.`status` = 'validity'
  251. and gt.sku_id = #{skuId}
  252. and a.expiry_time >= #{tenExpiry}) s
  253. where (t1 = 5 and a1 = 0) = 0
  254. </select>
  255. <select id="selectNumWaitingGroups" resultType="java.lang.Integer">
  256. select count(gr.id)
  257. from `groups_trips` gt
  258. inner join groups_relation gr on gr.groups_id = gt.id
  259. and gt.`status` = 'waiting'
  260. and gt.sku_id = #{skuId}
  261. and gr.user_id != 0
  262. and gr.status in ('validity','outside')
  263. </select>
  264. </mapper>