GroupRelationMapper.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 = #{entity.account},
  13. customer_service = null,
  14. verify_code = null
  15. where id = #{entity.id}
  16. <if test="expireTime != null">
  17. and expiry_time = #{expireTime}
  18. </if>
  19. </update>
  20. <select id="getAccountIdsByUserIdOrNickNameOrSubmitAccount" resultType="java.lang.Long">
  21. select gr.groups_id
  22. from groups_relation gr,
  23. `user` u
  24. where gr.user_id = u.id
  25. <if test="nickName != null and nickName != ''">
  26. and u.nickname like '%${nickName}%'
  27. </if>
  28. <if test="userId != null">
  29. and u.id = #{userId,jdbcType=BIGINT}
  30. </if>
  31. <if test="submitAccount != null and submitAccount != ''">
  32. and gr.account = #{submitAccount,jdbcType=VARCHAR}
  33. </if>
  34. group by gr.groups_id
  35. </select>
  36. <select id="getGroupTripsSkuIdByRelationId" resultType="java.lang.Long">
  37. 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
  38. </select>
  39. <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
  40. select s.id
  41. from (select gt.id, min(gr.expiry_time) minExpiryTime
  42. from `groups_trips` gt
  43. left join `groups_relation` gr on gr.groups_id = gt.id
  44. where gt.sku_id = #{skuId}
  45. and gt.available_num > 0
  46. and gt.status = 'validity'
  47. and gr.status = 'validity'
  48. and gr.user_id != 0
  49. and gr.expiry_time is not null
  50. group by gr.groups_id) s
  51. where s.minExpiryTime >= #{minExpiryTime}
  52. order by minExpiryTime desc limit 1
  53. </select>
  54. <select id="selectRelationByGoodsId" resultType="com.cyksj.model.manage.views.GroupsRelationView">
  55. select gr.*
  56. from groups_relation gr
  57. left join groups_trips gt on gr.groups_id = gt.id
  58. left join account a on a.id = gt.account_id
  59. left join user u on gr.user_id = u.id
  60. left join goods_don g on a.goods_id = g.id
  61. where g.id = #{goodsId}
  62. and gr.user_id = #{userId}
  63. and gt.status = 'validity'
  64. and gr.status = 'validity'
  65. </select>
  66. <select id="getGroupRelationViewByUserIdAndRelationId"
  67. resultType="com.cyksj.model.manage.views.GroupsRelationView">
  68. select gr.*,
  69. a.account as tripsAccount,
  70. g.title
  71. from groups_relation gr
  72. left join groups_trips gt on gt.id = gr.groups_id
  73. left join account a on a.id = gt.account_id
  74. left join goods_don g on g.id = a.goods_id
  75. where gr.id = #{relationId} and gr.user_id = #{userId}
  76. </select>
  77. <select id="getBindPhoneByUserId" resultType="java.lang.String">
  78. 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
  79. on ud.user_id = u.id
  80. </select>
  81. <select id="selectViewPwdCount" resultType="java.lang.Integer">
  82. select count(distinct relation_id)
  83. from (select id, user_id from `groups_relation` where groups_id = #{groupsId} and `status` = 'validity') s
  84. inner join chat_gpt_pwd_view_record cr on cr.relation_id = s.id and s.user_id = cr.user_id
  85. </select>
  86. <select id="selectRandomOneRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  87. select *
  88. from groups_relation
  89. where groups_id = #{groupsId}
  90. and user_id = 0
  91. and status = 'none'
  92. order by rand() limit 1
  93. </select>
  94. <select id="selectExpiredRelationByCondition" resultType="com.cyksj.model.entity.GroupsRelation">
  95. select gr.*
  96. from groups_relation gr
  97. inner join groups_trips gt on gt.id = gr.groups_id
  98. where gt.sku_id not in
  99. <foreach collection="list" item="item" open="(" separator="," close=")">
  100. #{item}
  101. </foreach>
  102. and gr.expiry_time &lt;= #{now}
  103. </select>
  104. <select id="selectOutsideRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  105. select *
  106. from groups_relation
  107. where groups_id = #{groupsId}
  108. and user_id = 0
  109. and num > #{relationNum}
  110. and status = 'outside'
  111. order by rand() limit 1
  112. </select>
  113. <select id="selectExpiredChatGPTRelation" resultType="com.cyksj.model.entity.GroupsRelation">
  114. select gr.*
  115. from groups_relation gr
  116. inner join groups_trips gt on gt.id = gr.groups_id
  117. where gt.sku_id in
  118. <foreach collection="list" item="item" open="(" separator="," close=")">
  119. #{item}
  120. </foreach>
  121. and gr.expiry_time &lt;= #{nextBeginDay}
  122. </select>
  123. <select id="getUserRelationUserViews" resultType="com.cyksj.model.views.GroupsRelationUserView">
  124. select gr.*,
  125. u.nickname,
  126. u.headimgurl
  127. from (select * from (select id as relation_id,
  128. user_id,
  129. 1 as isSelf from groups_relation where id = #{relationId}
  130. and status in
  131. <foreach collection="status" item="item" open="(" separator="," close=")">
  132. #{item}
  133. </foreach>
  134. limit 1)s1
  135. union all
  136. select * from (select id as realtion_id,
  137. user_id,
  138. if(user_id = #{userId},true,false) as isSelf from groups_relation where id != #{relationId}
  139. and groups_id = #{groupsId}
  140. and status in
  141. <foreach collection="status" item="item" open="(" separator="," close=")">
  142. #{item}
  143. </foreach>
  144. limit 4)s2)gr inner join user u on u.id = gr.user_id
  145. </select>
  146. <select id="getTicketGoodsId" resultType="java.lang.Long">
  147. select sku.goods_id from (select * from `groups_relation` where status in
  148. <foreach collection="status" item="item" open="(" separator="," close=")">
  149. #{item}
  150. </foreach>
  151. and user_id in
  152. <foreach collection="list" item="item" open="(" separator="," close=")">
  153. #{item}
  154. </foreach>)gr left join groups_trips gt on gt.id = gr.groups_id
  155. left join goods_don_sku sku on sku.id = gt.sku_id
  156. </select>
  157. <select id="getRecommendGoodsViews" resultType="com.cyksj.model.views.UserRecommendGoodsFrontView">
  158. select * from (select
  159. id as goodsId,
  160. title,
  161. logo,
  162. img,
  163. tags,
  164. sort_by,
  165. min_months as months,
  166. min_days as days,
  167. min_price as price,
  168. (
  169. case when type = 2 and ${isPayNf} then 999
  170. when type = 2 and !${isPayNf} then 666
  171. when category = 1 then 888
  172. when category = 2 then 777
  173. else 666 end
  174. ) as sorted
  175. from `goods_don` where id not in
  176. <foreach collection="list" item="item" open="(" separator="," close=")">
  177. #{item}
  178. </foreach>
  179. and type in (1,2)
  180. and deleted is true and status is true) s order by s.sorted desc,sort_by desc
  181. </select>
  182. </mapper>