StudentInstrumentMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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.ym.mec.biz.dal.dao.StudentInstrumentDao">
  4. <resultMap id="StudentInstrument" type="com.ym.mec.biz.dal.entity.StudentInstrument">
  5. <!--@mbg.generated-->
  6. <!--@Table student_instrument-->
  7. <id column="id_" property="id"/>
  8. <result column="student_id_" property="studentId"/>
  9. <result column="organ_id_" property="organId"/>
  10. <result column="goods_id_" property="goodsId"/>
  11. <result column="goods_category_id_" property="goodsCategoryId"/>
  12. <result column="goods_category_name_" property="goodsCategoryName"/>
  13. <result column="status_" property="status"/>
  14. <result column="start_time_" property="startTime"/>
  15. <result column="end_time_" property="endTime"/>
  16. <result column="order_id_" property="orderId"/>
  17. <result column="change_order_id_" property="changeOrderId"/>
  18. <result column="operation_" property="operation"/>
  19. <result column="create_time_" property="createTime"/>
  20. <result column="update_time" property="updateTime"/>
  21. <result column="del_flag_" property="delFlag"/>
  22. <result column="goods_name_" property="goodsName"/>
  23. <result column="specification_" property="specification"/>
  24. <result column="goods_brand_" property="goodsBrand"/>
  25. <result column="goods_img_" property="goodsImg"/>
  26. </resultMap>
  27. <select id="get" parameterType="java.lang.Long" resultMap="StudentInstrument">
  28. <!--@mbg.generated-->
  29. SELECT * FROM student_instrument
  30. where id_ = #{id}
  31. </select>
  32. <delete id="delete" parameterType="java.lang.Long">
  33. <!--@mbg.generated-->
  34. delete from student_instrument
  35. where id_ = #{id}
  36. </delete>
  37. <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.StudentInstrument"
  38. useGeneratedKeys="true">
  39. <!--@mbg.generated-->
  40. insert into student_instrument
  41. (student_id_,organ_id_,goods_id_,goods_category_id_,goods_category_name_,goods_name_,goods_brand_,specification_,goods_img_,
  42. status_,order_id_,change_order_id_,operation_, start_time_, end_time_, create_time_, update_time
  43. )
  44. values
  45. (#{studentId},#{organId},#{goodsId},#{goodsCategoryId},#{goodsCategoryName},#{goodsName},#{goodsBrand},#{specification},#{goodsImg},
  46. #{status},#{orderId},#{changeOrderId},#{operation}, #{startTime}, #{endTime}, NOW(), NOW()
  47. )
  48. </insert>
  49. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentInstrument">
  50. <!--@mbg.generated-->
  51. update student_instrument
  52. <set>
  53. <if test="studentId != null">
  54. student_id_ = #{studentId},
  55. </if>
  56. <if test="organId != null">
  57. organ_id_ = #{organId},
  58. </if>
  59. <if test="goodsId != null">
  60. goods_id_ = #{goodsId},
  61. </if>
  62. <if test="goodsName != null">
  63. goods_name_ = #{goodsName},
  64. </if>
  65. <if test="goodsBrand != null">
  66. goods_brand_ = #{goodsBrand},
  67. </if>
  68. <if test="specification != null">
  69. specification_ = #{specification},
  70. </if>
  71. <if test="goodsImg != null">
  72. goods_img_ = #{goodsImg},
  73. </if>
  74. <if test="status != null">
  75. status_ = #{status},
  76. </if>
  77. <if test="operation != null">
  78. operation_ = #{operation},
  79. </if>
  80. start_time_ = #{startTime},
  81. end_time_ = #{endTime},
  82. <if test="changeOrderId != null">
  83. change_order_id_ = #{changeOrderId},
  84. </if>
  85. <if test="createTime != null">
  86. create_time_ = #{createTime},
  87. </if>
  88. <if test="delFlag != null">
  89. del_flag_ = #{delFlag},
  90. </if>
  91. update_time = NOW(),
  92. </set>
  93. where id_ = #{id}
  94. </update>
  95. <!-- 全查询 -->
  96. <select id="findAll" resultMap="StudentInstrument">
  97. SELECT *
  98. FROM student
  99. </select>
  100. <!-- 分页查询 -->
  101. <select id="queryPage" resultMap="StudentInstrument" parameterType="map">
  102. SELECT si.*,su.username_ studentName,su.phone_ phone,o.name_ organName FROM student_instrument si
  103. LEFT JOIN sys_user su ON su.id_ = si.student_id_
  104. LEFT JOIN organization o ON o.id_ = si.organ_id_
  105. <include refid="queryPageSql"/>
  106. <include refid="global.limit"/>
  107. </select>
  108. <!-- 查询当前表的总记录数 -->
  109. <select id="queryCount" resultType="int">
  110. SELECT COUNT(*)
  111. FROM student_instrument si
  112. LEFT JOIN sys_user su ON su.id_ = si.student_id_
  113. <include refid="queryPageSql"/>
  114. </select>
  115. <sql id="queryPageSql">
  116. <where>
  117. <if test="studentId != null">
  118. AND si.student_id_ = #{studentId}
  119. </if>
  120. <if test="organId != null">
  121. AND FIND_IN_SET(si.organ_id_,#{organId})
  122. </if>
  123. <if test="goodsId != null">
  124. AND si.goods_id_ = #{goodsId}
  125. </if>
  126. <if test="goodsCategoryId != null">
  127. AND si.goods_category_id_ = #{goodsCategoryId}
  128. </if>
  129. <if test="goodsBrand != null">
  130. AND si.goods_brand_ LIKE CONCAT('%',#{goodsBrand},'%')
  131. </if>
  132. <if test="specification != null">
  133. AND si.specification_ LIKE CONCAT('%',#{specification},'%')
  134. </if>
  135. <if test="status != null">
  136. AND si.status_ = #{status}
  137. </if>
  138. <if test="search != null">
  139. AND (si.student_id_ = #{search} OR su.phone_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%'))
  140. </if>
  141. AND si.del_flag_ = 0
  142. </where>
  143. </sql>
  144. <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  145. insert into student_instrument
  146. (student_id_,organ_id_,goods_id_,goods_category_id_,goods_category_name_,goods_name_,goods_brand_,specification_,goods_img_,
  147. order_id_,change_order_id_,status_, start_time_, end_time_, create_time_, update_time)
  148. VALUE
  149. <foreach collection="studentInstruments" item="item" separator=",">
  150. (#{item.studentId},#{item.organId},#{item.goodsId},#{item.goodsCategoryId},#{item.goodsCategoryName},#{item.goodsName},#{item.goodsBrand},#{item.specification},#{item.goodsImg},
  151. #{item.orderId},#{item.changeOrderId},#{item.status}, #{item.startTime},
  152. #{item.endTime}, NOW(), NOW())
  153. </foreach>
  154. </insert>
  155. <update id="batchUpdate">
  156. <![CDATA[
  157. UPDATE student_instrument
  158. SET status_ = 0
  159. WHERE status_ = 1
  160. AND end_time_ <= NOW()
  161. ]]>
  162. </update>
  163. <select id="getListByEndTime" resultMap="StudentInstrument">
  164. <![CDATA[
  165. SELECT *
  166. FROM student_instrument
  167. WHERE end_time_ >= #{startTime}
  168. AND end_time_ <= #{endTime}
  169. ]]>
  170. </select>
  171. <select id="getByOrderId" resultMap="StudentInstrument">
  172. SELECT *
  173. FROM student_instrument
  174. WHERE change_order_id_ = #{orderId}
  175. </select>
  176. <select id="getStudentInstrument" resultMap="StudentInstrument">
  177. SELECT *
  178. FROM student_instrument
  179. WHERE student_id_ = #{studentId}
  180. AND goods_id_ = #{goodsId}
  181. AND del_flag_ = 0
  182. ORDER BY id_ DESC
  183. LIMIT 1
  184. </select>
  185. <select id="getOldStudentInstrument" resultMap="StudentInstrument">
  186. SELECT spo.user_id_ student_id_,
  187. spo.organ_id_,
  188. g.id_ goods_id_,
  189. g.goods_category_id_,
  190. gc.name_ goods_category_name_,
  191. g.name_ goods_name_,
  192. g.brand_ goods_brand_,
  193. g.specification_,
  194. g.image_ goods_img_,
  195. spo.create_time_ start_time_,
  196. DATE_ADD(spo.create_time_, INTERVAL 1 YEAR) end_time_,
  197. spo.id_ order_id_
  198. FROM student_payment_order_detail spod
  199. LEFT JOIN student_payment_order spo ON spo.id_ = spod.payment_order_id_
  200. LEFT JOIN student_payment_order_detail spod2 ON spod2.payment_order_id_ = spo.id_
  201. LEFT JOIN goods g ON g.id_ = spod2.goods_id_list_
  202. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  203. WHERE spo.status_ = 'SUCCESS'
  204. AND spod2.type_ = 'MUSICAL'
  205. AND (
  206. <if test="goodsIds != null and goodsIds.size() != 0">
  207. spod.goods_id_list_ IN
  208. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  209. #{goodsId}
  210. </foreach>
  211. OR
  212. </if>
  213. FIND_IN_SET('76', spod.goods_id_list_)
  214. )
  215. <if test="startTime != null ">
  216. AND spo.pay_time_ >= #{startTime}
  217. </if>
  218. ORDER BY spo.create_time_ ASC
  219. </select>
  220. <resultMap id="StudentInstrumentExportDto" type="com.ym.mec.biz.dal.dto.StudentInstrumentExportDto"
  221. extends="StudentInstrument">
  222. <result column="order_no_" property="orderNo"/>
  223. <result column="trans_no_" property="transNo"/>
  224. <result column="type_" property="type"/>
  225. </resultMap>
  226. <select id="getInstruments" resultMap="StudentInstrumentExportDto">
  227. SELECT si.*,spo.create_time_,o.name_ organName,su.username_
  228. studentName,spo.order_no_,spo.trans_no_,spod.is_renew_ type_,spo.id_
  229. FROM student_payment_order_detail spod
  230. LEFT JOIN student_payment_order spo ON spo.id_ = spod.payment_order_id_
  231. LEFT JOIN student_instrument si ON si.id_ = spod.student_instrument_id_
  232. LEFT JOIN organization o ON spo.organ_id_ = o.id_
  233. LEFT JOIN sys_user su ON su.id_ = si.student_id_
  234. WHERE spo.status_ = 'SUCCESS' AND spod.type_='MAINTENANCE'
  235. <if test="startTime != null ">
  236. AND spo.create_time_ >= #{startTime}
  237. </if>
  238. <if test="endTime != null ">
  239. <![CDATA[AND spo.create_time_ <= #{endTime}]]>
  240. </if>
  241. <if test="organId != null">
  242. AND FIND_IN_SET(spo.organ_id_,#{organId})
  243. </if>
  244. </select>
  245. <select id="findStudentMusicGroup"
  246. resultMap="com.ym.mec.biz.dal.dao.StudentRegistrationDao.StudentRegistration">
  247. SELECT sr.id_, sr.user_id_, mg.name_ class_group_name_, su.real_name_ parents_name_, sr.music_group_status_
  248. FROM student_registration sr
  249. LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
  250. LEFT JOIN sys_user su ON su.id_ = mg.repair_user_id_
  251. WHERE sr.user_id_ = #{userId}
  252. AND sr.payment_status_ = 2
  253. AND mg.status_ IN ('PREPARE', 'PROGRESS', 'PAUSE', 'CLOSE')
  254. ORDER BY sr.id_ DESC
  255. LIMIT 1
  256. </select>
  257. <select id="getStudentsMaintenanceNum" resultMap="StudentInstrument">
  258. SELECT student_id_,COUNT(*) goods_id_
  259. FROM student_instrument
  260. WHERE order_id_ IN (
  261. SELECT MAX(id_)
  262. FROM student_payment_order
  263. WHERE type_ = 'APPLY'
  264. AND music_group_id_ = #{musicGroupId}
  265. AND status_ = 'SUCCESS'
  266. AND user_id_ IN
  267. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  268. #{studentId}
  269. </foreach>
  270. GROUP BY user_id_
  271. )
  272. AND student_id_ IN
  273. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  274. #{studentId}
  275. </foreach>
  276. AND del_flag_ = 0 AND end_time_ > NOW()
  277. GROUP BY student_id_
  278. </select>
  279. <select id="getStudentMaintenance" resultMap="StudentInstrument">
  280. SELECT * FROM student_instrument
  281. WHERE order_id_ = (
  282. SELECT MAX(id_)
  283. FROM student_payment_order
  284. WHERE type_ = 'APPLY'
  285. AND music_group_id_ = #{musicGroupId}
  286. AND status_ = 'SUCCESS'
  287. AND user_id_ = #{studentId}
  288. )
  289. AND student_id_ = #{studentId} AND del_flag_ = 0 AND end_time_ > NOW()
  290. </select>
  291. </mapper>