GroupRelationMapper.xml 9.9 KB

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