GroupRelationMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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_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)
  52. and gt.available_num > 0
  53. and gt.status = 'validity'
  54. and gr.status = 'validity'
  55. and gr.user_id != 0
  56. and gr.expiry_time is not null
  57. group by gr.groups_id) s
  58. where s.minExpiryTime >= #{minExpiryTime}
  59. order by minExpiryTime desc limit 1
  60. </select>
  61. <select id="selectRelationByGoodsId" resultType="com.cyksj.model.manage.views.GroupsRelationView">
  62. select gr.*
  63. from groups_relation gr
  64. left join groups_trips gt on gr.groups_id = gt.id
  65. left join account a on a.id = gt.account_id
  66. left join user u on gr.user_id = u.id
  67. left join goods_don g on a.goods_id = g.id
  68. where g.id = #{goodsId}
  69. and gr.user_id = #{userId}
  70. and gt.status = 'validity'
  71. and gr.status = 'validity'
  72. and gr.yhs_id = #{yhsId}
  73. </select>
  74. <select id="getGroupRelationViewByUserIdAndRelationId"
  75. resultType="com.cyksj.model.manage.views.GroupsRelationView">
  76. select gr.*,
  77. a.account as tripsAccount,
  78. g.title
  79. from groups_relation gr
  80. left join groups_trips gt on gt.id = gr.groups_id
  81. left join account a on a.id = gt.account_id
  82. left join goods_don g on g.id = a.goods_id
  83. where gr.id = #{relationId} and gr.user_id = #{userId}
  84. </select>
  85. <select id="getBindPhoneByUserId" resultType="java.lang.String">
  86. select if(login_phone != '', login_phone,
  87. (select phone from user_bind_detail where user_id = #{userId} or email_user_id = #{userId} limit 1))
  88. from user
  89. where id = #{userId} limit 1
  90. </select>
  91. <select id="selectViewPwdCount" resultType="java.lang.Integer">
  92. select count(distinct relation_id)
  93. from (select id, user_id from `groups_relation` where groups_id = #{groupsId} and `status` = 'validity') s
  94. inner join ticket_pwd_view_record cr on cr.relation_id = s.id and s.user_id = cr.user_id
  95. </select>
  96. <select id="selectRandomOneRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  97. select *
  98. from groups_relation
  99. where groups_id = #{groupsId}
  100. and user_id = 0
  101. and status = 'none'
  102. order by rand() limit 1
  103. </select>
  104. <select id="selectExpiredRelationByCondition" resultType="com.cyksj.model.entity.GroupsRelation">
  105. select gr.*
  106. from groups_relation gr
  107. inner join groups_trips gt on gt.id = gr.groups_id
  108. where gt.sku_id not in
  109. <foreach collection="list" item="item" open="(" separator="," close=")">
  110. #{item}
  111. </foreach>
  112. and gr.expiry_time &lt;= #{now}
  113. </select>
  114. <select id="selectOutsideRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  115. select *
  116. from groups_relation
  117. where groups_id = #{groupsId}
  118. and user_id = 0
  119. and num > #{relationNum}
  120. and status = 'outside'
  121. order by rand() limit 1
  122. </select>
  123. <select id="selectExpiredChatGPTRelation" resultType="com.cyksj.model.entity.GroupsRelation">
  124. select gr.*
  125. from groups_relation gr
  126. inner join groups_trips gt on gt.id = gr.groups_id
  127. where gt.sku_id in
  128. <foreach collection="list" item="item" open="(" separator="," close=")">
  129. #{item}
  130. </foreach>
  131. and gr.expiry_time &lt;= #{nextBeginDay}
  132. </select>
  133. <select id="getUserRelationUserViews" resultType="com.cyksj.model.views.GroupsRelationUserView">
  134. select gr.*,
  135. u.nickname,
  136. u.headimgurl
  137. from (select * from (select id as relation_id,
  138. user_id,
  139. 1 as isSelf from groups_relation where id = #{relationId}
  140. and status in
  141. <foreach collection="status" item="item" open="(" separator="," close=")">
  142. #{item}
  143. </foreach>
  144. limit 1)s1
  145. union all
  146. select * from (select id as realtion_id,
  147. user_id,
  148. if(user_id = #{userId},true,false) as isSelf from groups_relation where id != #{relationId}
  149. and groups_id = #{groupsId}
  150. and status in
  151. <foreach collection="status" item="item" open="(" separator="," close=")">
  152. #{item}
  153. </foreach>
  154. limit 4)s2)gr inner join user u on u.id = gr.user_id
  155. </select>
  156. <select id="getTicketGoodsId" resultType="java.lang.Long">
  157. select distinct goods_id from (select sku.goods_id from (select * from `groups_relation` where status in
  158. <foreach collection="status" item="item" open="(" separator="," close=")">
  159. #{item}
  160. </foreach>
  161. and user_id in
  162. <foreach collection="list" item="item" open="(" separator="," close=")">
  163. #{item}
  164. </foreach>)gr left join groups_trips gt on gt.id = gr.groups_id
  165. left join goods_don_sku sku on sku.id = gt.sku_id
  166. union all
  167. select goods_id from order_don o where user_id in
  168. <foreach collection="list" item="item" open="(" separator="," close=")">
  169. #{item}
  170. </foreach>
  171. and relation_id = 0 and status not in ('close','noPayment','refund'))s
  172. </select>
  173. <select id="getRecommendGoodsViews" resultType="com.cyksj.model.views.UserRecommendGoodsFrontView">
  174. select * from (select
  175. id as goodsId,
  176. title,
  177. logo,
  178. img,
  179. tags,
  180. sort_by,
  181. `type`,
  182. min_months as months,
  183. min_days as days,
  184. min_price as price,
  185. (
  186. case when type = 2 and ${isPayNf} then 999
  187. when category = 1 then 888
  188. when category = 2 then 777
  189. when category = 3 then 755
  190. else 666 end
  191. ) as sorted
  192. from `goods_don` where id not in
  193. <foreach collection="list" item="item" open="(" separator="," close=")">
  194. #{item}
  195. </foreach>
  196. <if test="isPayNf">
  197. and type in (1,2)
  198. </if>
  199. <if test="!isPayNf">
  200. and type = 1
  201. </if>
  202. and deleted is true and status is true) s order by s.sorted desc,sort_by asc
  203. </select>
  204. <select id="getOutSideGroupsTripsRelationByGoodsId" resultType="java.lang.Long">
  205. select gt.id
  206. from `groups_trips` gt
  207. inner join account a on a.id = gt.account_id
  208. where gt.sku_id = #{skuId}
  209. and gt.status = 'validity'
  210. and a.expiry_time >= #{beginOfDay}
  211. and (select count(*)
  212. from groups_relation gr
  213. where gr.num > #{skuNum}
  214. and gr.num &lt;= #{maxNum}
  215. and gr.groups_id = gt.id
  216. and gr.user_id
  217. != 0)
  218. &lt; #{extraNum}
  219. and
  220. (
  221. select count(*)
  222. from groups_relation gr
  223. where gr.groups_id = gt.id
  224. and gr.user_id
  225. = #{userId}) = 0
  226. 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)
  227. order by RAND() limit 1
  228. </select>
  229. <select id="selectAvailableRelation" resultType="java.lang.Integer">
  230. select count(gr.id)
  231. from account a
  232. inner join `groups_trips` gt on gt.account_id = a.id
  233. and gt.`status` = 'validity'
  234. and gt.sku_id = #{skuId}
  235. inner join groups_relation gr on gr.groups_id = gt.id
  236. and gr.status in ('none', 'locking')
  237. and gt.available_parking_num = 0
  238. and gr.num &lt;= #{skuNum}
  239. </select>
  240. <select id="selectSpecialGroupsRelationAvailable" resultType="java.lang.Integer">
  241. select ifnull(sum(a1 + (#{extractNum} - t1)), 0)
  242. from (select gt.id,
  243. (select count(*)
  244. from groups_relation gr2
  245. where gr2.groups_id = gt.id
  246. and num > #{skuNum}
  247. and num &lt;= #{maxNum}) t1,
  248. (select count(*)
  249. from groups_relation gr2
  250. where gr2.groups_id = gt.id
  251. and num > #{skuNum}
  252. and num &lt;= #{maxNum}
  253. and (gr2.user_id = 0 or gr2.status = 'locking')) a1
  254. from account a
  255. inner join `groups_trips` gt on gt.account_id = a.id
  256. and gt.`status` = 'validity'
  257. and gt.available_parking_num = 0
  258. and gt.sku_id = #{skuId}
  259. and a.expiry_time >= #{tenExpiry}) s
  260. where (t1 = #{extractNum} and a1 = 0) = 0
  261. </select>
  262. <select id="selectNumWaitingGroups" resultType="java.lang.Integer">
  263. select count(gr.id)
  264. from `groups_trips` gt
  265. inner join groups_relation gr on gr.groups_id = gt.id
  266. and gt.`status` = 'waiting'
  267. and gt.sku_id = #{skuId}
  268. and gr.user_id != 0
  269. and gr.status in ('validity','outside')
  270. </select>
  271. <select id="selectLimitAvailableNum" resultType="java.lang.Integer">
  272. select sum(s1 - s2)
  273. from (select available_parking_num as s1,
  274. (select count(*)
  275. from groups_relation gr
  276. where gr.groups_id = gt.id
  277. and gr.status in ('validity', 'outside')
  278. and gr.num &lt;= #{maxNum}) as s2
  279. from groups_trips gt
  280. where gt.sku_id = #{skuId}
  281. and gt.status = 'validity'
  282. and gt.available_parking_num != 0) t
  283. where t.s1 >= s2
  284. </select>
  285. <select id="getGroupRelationAccountView" resultType="com.cyksj.model.manage.views.GroupsRelationBackView">
  286. select s.account, a.account as tripsAccount
  287. from (select groups_id, account from groups_relation where id = #{relationId} limit 1) s
  288. inner join groups_trips gt on gt.id = s.groups_id
  289. left join account a on a.id = gt.account_id
  290. </select>
  291. <select id="getAreaPhoneByUserId" resultType="com.cyksj.model.entity.PhoneCode">
  292. select s.phone, pc.cid
  293. from (select if(login_phone != '', login_phone,
  294. (select phone
  295. from user_bind_detail
  296. where user_id = u.id
  297. or email_user_id = u.id limit 1)) as phone
  298. from user u
  299. where id = #{userId} limit 1) s
  300. left join phone_code pc on pc.phone = s.phone
  301. </select>
  302. <select id="getUserHasPayGoods" resultType="com.cyksj.model.views.RenewalView">
  303. select g.id as goods_id,g.title,g.logo from (select distinct groups_id from groups_relation where status in
  304. ('validity', 'outside') and (expiry_time is null
  305. or
  306. expiry_time > #{now}) and user_id != 0 and user_id in <foreach
  307. collection="list" item="item" open="(" separator="," close=")">
  308. #{item}
  309. </foreach> ) gr inner join groups_trips gt on gt.id = gr.groups_id
  310. inner join goods_don_sku sku on sku.id = gt.sku_id inner join goods_don g on g.id = sku.goods_id
  311. group by g.id,g.title,g.logo
  312. order by goods_id
  313. </select>
  314. </mapper>