UserSubscribeMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zhongzheng.modules.user.mapper.UserSubscribeMapper">
  6. <resultMap type="com.zhongzheng.modules.user.domain.UserSubscribe" id="UserSubscribeResult">
  7. <result property="subscribeId" column="subscribe_id"/>
  8. <result property="goodsId" column="goods_id"/>
  9. <result property="userId" column="user_id"/>
  10. <result property="subscribeStatus" column="subscribe_status"/>
  11. <result property="beforeStatus" column="before_status"/>
  12. <result property="examStatus" column="exam_status"/>
  13. <result property="performance" column="performance"/>
  14. <result property="result" column="result"/>
  15. <result property="certificateCode" column="certificate_code"/>
  16. <result property="applyId" column="apply_id"/>
  17. <result property="studentType" column="student_type"/>
  18. <result property="examExpend" column="exam_expend"/>
  19. <result property="beforeExpend" column="before_expend"/>
  20. <result property="createTime" column="create_time"/>
  21. <result property="updateTime" column="update_time"/>
  22. </resultMap>
  23. <resultMap type="com.zhongzheng.modules.user.vo.UserSubscribeVo" id="UserSubscribeVo">
  24. <result property="subscribeId" column="subscribe_id"/>
  25. <result property="goodsId" column="goods_id"/>
  26. <result property="userId" column="user_id"/>
  27. <result property="subscribeStatus" column="subscribe_status"/>
  28. <result property="beforeStatus" column="before_status"/>
  29. <result property="examStatus" column="exam_status"/>
  30. <result property="performance" column="performance"/>
  31. <result property="result" column="result"/>
  32. <result property="certificateCode" column="certificate_code"/>
  33. <result property="applyId" column="apply_id"/>
  34. <result property="studentType" column="student_type"/>
  35. <result property="examExpend" column="exam_expend"/>
  36. <result property="beforeExpend" column="before_expend"/>
  37. <result property="createTime" column="create_time"/>
  38. <result property="goodsName" column="goods_name"/>
  39. <result property="categoryName" column="category_name"/>
  40. <result property="goodsCode" column="goods_code"/>
  41. <result property="remark" column="remark"/>
  42. <result property="standPrice" column="stand_price"/>
  43. <result property="realname" column="realname"/>
  44. <result property="idCard" column="id_card"/>
  45. <result property="applyName" column="apply_name"/>
  46. <result property="beforeId" column="before_id"/>
  47. <result property="beforeName" column="before_name"/>
  48. <result property="applySiteAddress" column="apply_site_address"/>
  49. <result property="applySiteStartTime" column="apply_site_start_time"/>
  50. <result property="applySiteEndTime" column="apply_site_end_time"/>
  51. <result property="applySiteExamTime" column="apply_site_exam_time"/>
  52. <result property="applySiteAddressTrain" column="apply_site_address_train"/>
  53. <result property="applySiteStartTrainTime" column="apply_site_start_train_time"/>
  54. <result property="applySiteEndTrainTime" column="apply_site_end_train_time"/>
  55. <result property="applySiteExamTrainTime" column="apply_site_exam_train_time"/>
  56. <result property="applyStartTime" column="apply_start_time"/>
  57. <result property="applyEndTime" column="apply_end_time"/>
  58. <result property="businessId" column="business_id"/>
  59. <result property="beforeCount" column="before_count"/>
  60. <result property="beforeName" column="before_name"/>
  61. </resultMap>
  62. <select id="listSubscribe" parameterType="com.zhongzheng.modules.user.bo.UserSubscribeQueryBo" resultMap="UserSubscribeVo">
  63. SELECT
  64. us.*, eb.before_name,
  65. (SELECT g.goods_name FROM goods g where us.goods_id = g.goods_id) as goods_name,
  66. (SELECT g.code FROM goods g where us.goods_id = g.goods_id) as goods_code,
  67. (SELECT g.stand_price FROM goods g where us.goods_id = g.goods_id) as stand_price,
  68. (SELECT m.category_name FROM goods g LEFT JOIN major m on g.major_id= m.id where us.goods_id = g.goods_id) as category_name,
  69. u.realname,
  70. u.id_card,
  71. (SELECT ea.apply_name FROM exam_apply ea where ea.apply_id = us.apply_id) as apply_name,
  72. (SELECT ea.apply_start_time FROM exam_apply ea where ea.apply_id = us.apply_id) as apply_start_time,
  73. (SELECT ea.apply_end_time FROM exam_apply ea where ea.apply_id = us.apply_id) as apply_end_time,
  74. (SELECT eb.before_name FROM exam_before eb where eb.before_id = us.before_id) as before_name,
  75. (SELECT ueg.do_number-ueg.expend_before FROM user_exam_goods ueg where ueg.goods_id = us.goods_id and ueg.user_id = us.user_id ORDER BY user_exam_goods_id DESC limit 1) as before_count
  76. FROM
  77. user_subscribe us
  78. LEFT JOIN exam_before eb ON us.before_id = eb.before_id
  79. LEFT JOIN `user` u ON us.user_id = u.user_id
  80. WHERE
  81. 1 =1
  82. <if test="applySiteAddress != null and applySiteAddress != '' ">
  83. and us.apply_site_address = #{applySiteAddress}
  84. </if>
  85. <if test="canCancel != null and canCancel == 1 ">
  86. and us.subscribe_status = 1
  87. and LEFT(us.apply_site_start_time,2)*3600+us.apply_site_exam_time > unix_timestamp(now())
  88. and us.exam_status = 0
  89. and us.before_status = 0
  90. </if>
  91. <if test="canBefore != null and canBefore == 1 ">
  92. and us.subscribe_status = 1
  93. and us.before_id >0
  94. and us.exam_status = 0
  95. and (us.before_status = 1 or (SELECT count(*) from user_exam_goods ueg where ueg.user_id = us.user_id and ueg.goods_id = us.goods_id and ueg.do_number - ueg.expend_before>0)>0)
  96. </if>
  97. <if test="canExam != null and canExam == 1 ">
  98. and us.subscribe_status = 1
  99. </if>
  100. <if test="searchKey != null and searchKey != '' ">
  101. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%'))
  102. </if>
  103. <if test="idCards != null and idCards.size()!=0 ">
  104. AND u.id_card in
  105. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  106. #{item}
  107. </foreach>
  108. </if>
  109. <if test="userId != null and userId != '' ">
  110. and us.user_id = #{userId}
  111. </if>
  112. <if test="goodsId != null and goodsId != '' ">
  113. and us.goods_id = #{goodsId}
  114. </if>
  115. <if test="result != null ">
  116. and us.result = #{result}
  117. </if>
  118. <if test="subscribeId != null and subscribeId != '' ">
  119. and us.subscribe_id = #{subscribeId}
  120. </if>
  121. <if test="subscribeStatus != null and subscribeStatus != '' ">
  122. and us.subscribe_status = #{subscribeStatus}
  123. </if>
  124. <if test="applyId != null and applyId != '' ">
  125. and us.apply_id = #{applyId}
  126. </if>
  127. <if test="studentType != null and studentType != '' ">
  128. and us.student_type = #{studentType}
  129. </if>
  130. <if test="examStatus != null ">
  131. and us.exam_status = #{examStatus}
  132. </if>
  133. <if test="examExpend != null ">
  134. and us.exam_expend is NOT NULL
  135. </if>
  136. <if test="beforeExpend != null ">
  137. and us.before_expend is NOT NULL
  138. </if>
  139. <if test="beforeId != null ">
  140. and us.before_id =#{beforeId}
  141. </if>
  142. <if test="exceedExamExpend != null and exceedExamExpend == 1">
  143. and us.exam_expend = 1
  144. </if>
  145. <if test="exceedExamExpend != null and exceedExamExpend == 2">
  146. and (us.exam_expend is null or us.exam_expend = 0)
  147. </if>
  148. <if test="exceed != null ">
  149. and unix_timestamp(now()) > us.apply_site_exam_time and us.exam_expend is NULL and us.subscribe_status = 1
  150. </if>
  151. <if test="majorId != null and majorId != '' ">
  152. and (SELECT m.id FROM goods g LEFT JOIN major m on g.major_id= m.id where us.goods_id = g.goods_id) = #{majorId}
  153. </if>
  154. <if test="realname != null and realname != '' ">
  155. and (SELECT u.realname FROM `user` u where us.user_id = u.user_id) like concat('%', #{realname}, '%')
  156. </if>
  157. order by us.create_time desc
  158. </select>
  159. <select id="selectGoodsId" parameterType="string" resultType="Long">
  160. SELECT g.goods_id FROM goods g where g.`code`=#{code} and g.status = 1
  161. </select>
  162. <select id="selectUserId" parameterType="map" resultType="Long">
  163. SELECT u.user_id FROM `user` u where u.realname=#{userName} and u.id_card=#{idCard}
  164. </select>
  165. <select id="selectBeforeId" parameterType="map" resultType="Long">
  166. SELECT eb.before_id FROM exam_before eb where eb.before_name=#{beforeName} and eb.status = 1
  167. </select>
  168. <select id="selectApplyId" parameterType="map" resultType="Long">
  169. SELECT ea.apply_id FROM exam_apply ea where ea.apply_name=#{applyName} and ea.status = 1
  170. </select>
  171. <select id="selectSubscribeId" parameterType="map" resultType="Long">
  172. SELECT
  173. us.subscribe_id
  174. FROM
  175. user_subscribe us
  176. WHERE 1=1
  177. and us.subscribe_status =1
  178. and us.apply_id = #{applyId}
  179. and us.goods_id=#{goodsId}
  180. and us.user_id = #{userId}
  181. </select>
  182. <select id="queryBusinessId" parameterType="map" resultType="Long">
  183. SELECT
  184. COUNT( 1 )
  185. FROM
  186. user_subscribe us
  187. LEFT JOIN exam_apply ea ON ea.apply_id = us.apply_id
  188. LEFT JOIN exam_apply_goods eag on ea.apply_id = eag.apply_id
  189. LEFT JOIN goods g on eag.goods_id = g.goods_id
  190. where 1=1
  191. AND g.business_id = #{businessId}
  192. AND us.subscribe_id = #{subscribeId}
  193. </select>
  194. <select id="timeSend" resultMap="UserSubscribeVo">
  195. SELECT
  196. * ,
  197. (SELECT g.business_id FROM goods g where g.goods_id = us.goods_id) as business_id
  198. FROM
  199. user_subscribe us
  200. WHERE us.subscribe_status = 1
  201. and unix_timestamp(now())+86400 > us.apply_site_exam_time
  202. and unix_timestamp(now()) &lt; us.apply_site_exam_time
  203. and (SELECT COUNT(1) FROM inform_remind ir LEFT JOIN inform_remind_business irb on ir.id = irb.remind_id where ir.id=16 and (SELECT g.business_id FROM goods g where g.goods_id = us.goods_id) = irb.business_id) > 0
  204. </select>
  205. <select id="sendExamSucceed" parameterType="map" resultType="Long">
  206. SELECT
  207. COUNT( 1 )
  208. FROM
  209. inform_remind ir
  210. LEFT JOIN inform_remind_business irb on irb.remind_id =ir.id
  211. LEFT JOIN goods g on g.business_id = irb.business_id
  212. where 1=1
  213. and g.goods_id = #{goodsId}
  214. </select>
  215. <select id="listSubscribeByUser" parameterType="com.zhongzheng.modules.user.bo.UserSubscribeQueryBo" resultMap="UserSubscribeVo">
  216. SELECT
  217. us.user_id,
  218. u.realname,
  219. u.id_card
  220. FROM
  221. ( SELECT user_id FROM user_subscribe GROUP BY user_id ) us
  222. LEFT JOIN `user` u ON us.user_id = u.user_id
  223. WHERE
  224. 1 =1
  225. <if test="searchKey != null and searchKey != '' ">
  226. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%'))
  227. </if>
  228. </select>
  229. </mapper>