StudentInstrumentMapper.xml 16 KB

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