MusicGroupPaymentCalenderMapper.xml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender" id="MusicGroupPaymentCalender">
  9. <result column="id_" property="id"/>
  10. <result column="music_group_id_" property="musicGroupId"/>
  11. <result column="music_group_organization_course_settings_id_" property="musicGroupOrganizationCourseSettingId"/>
  12. <result column="pay_user_type_" property="payUserType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  13. <result column="start_payment_date_" property="startPaymentDate"/>
  14. <result column="deadline_payment_date_" property="deadlinePaymentDate"/>
  15. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  16. <result column="expect_num_" property="expectNum"/>
  17. <result column="actual_num_" property="actualNum"/>
  18. <result column="memo_" property="memo"/>
  19. <result column="audit_memo_" property="auditMemo"/>
  20. <result column="reject_reason_" property="rejectReason"/>
  21. <result column="is_give_music_network_" property="isGiveMusicNetwork"/>
  22. <result column="create_time_" property="createTime"/>
  23. <result column="update_time_" property="updateTime"/>
  24. <result column="payment_valid_start_date_" property="paymentValidStartDate"/>
  25. <result column="payment_valid_end_date_" property="paymentValidEndDate"/>
  26. <result column="payment_pattern_" property="paymentPattern"/>
  27. <result column="payment_type_" property="paymentType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  28. <result column="batch_no_" property="batchNo"/>
  29. <result column="payment_amount_" property="paymentAmount"/>
  30. <result column="attribute1_" property="attribute1"/>
  31. <result column="attribute2_" property="attribute2"/>
  32. <result column="student_ids_" property="studentIds"/>
  33. </resultMap>
  34. <!-- 根据主键查询一条记录 -->
  35. <select id="get" resultMap="MusicGroupPaymentCalender">
  36. SELECT * FROM music_group_payment_calender WHERE id_ = #{id}
  37. </select>
  38. <!-- 全查询 -->
  39. <select id="findAll" resultMap="MusicGroupPaymentCalender">
  40. SELECT * FROM music_group_payment_calender ORDER BY id_
  41. </select>
  42. <!-- 向数据库增加一条记录 -->
  43. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender" useGeneratedKeys="true"
  44. keyColumn="id_" keyProperty="id">
  45. INSERT INTO music_group_payment_calender
  46. (music_group_id_,music_group_organization_course_settings_id_,pay_user_type_,reject_reason_,start_payment_date_,deadline_payment_date_,status_,expect_num_,
  47. actual_num_,memo_,is_give_music_network_,create_time_,update_time_,payment_valid_start_date_,payment_valid_end_date_,
  48. payment_pattern_,payment_type_,payment_amount_,batch_no_,audit_memo_,operator_,attribute1_,attribute2_,student_ids_)
  49. VALUES(#{musicGroupId},#{musicGroupOrganizationCourseSettingId},#{payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  50. #{rejectReason},#{startPaymentDate},#{deadlinePaymentDate},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  51. #{expectNum},#{actualNum},#{memo},#{isGiveMusicNetwork},now(),now(),
  52. #{paymentValidStartDate},#{paymentValidEndDate},#{paymentPattern},#{paymentType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  53. #{paymentAmount},#{batchNo},#{auditMemo},#{operator},#{attribute1},#{attribute2},#{studentIds})
  54. </insert>
  55. <insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender" useGeneratedKeys="true"
  56. keyColumn="id_" keyProperty="id">
  57. INSERT INTO music_group_payment_calender
  58. (music_group_id_,music_group_organization_course_settings_id_,pay_user_type_,reject_reason_,start_payment_date_,deadline_payment_date_,status_,expect_num_,
  59. actual_num_,memo_,is_give_music_network_,create_time_,update_time_,payment_valid_start_date_,payment_valid_end_date_,payment_pattern_,payment_amount_,
  60. payment_type_,batch_no_,audit_memo_,operator_,attribute1_,attribute2_,student_ids_)
  61. VALUES
  62. <foreach collection="list" item="item" index="index" separator=",">
  63. (#{item.musicGroupId},#{item.musicGroupOrganizationCourseSettingId},#{item.payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{item.rejectReason},#{item.startPaymentDate},#{item.deadlinePaymentDate},#{item.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  64. #{item.expectNum},#{item.actualNum},#{item.memo},#{item.isGiveMusicNetwork},now(),now(),
  65. #{item.paymentValidStartDate},#{item.paymentValidEndDate},#{item.paymentPattern},#{item.paymentAmount},#{item.paymentType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  66. #{item.batchNo},#{item.auditMemo},#{item.operator},#{item.attribute1},#{item.attribute2},#{item.studentIds})
  67. </foreach>
  68. </insert>
  69. <!-- 根据主键查询一条记录 -->
  70. <update id="update" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender">
  71. UPDATE music_group_payment_calender
  72. <set>
  73. <if test="studentIds != null and studentIds != ''">
  74. student_ids_ = #{studentIds},
  75. </if>
  76. <if test="auditMemo != null and auditMemo != ''">
  77. audit_memo_ = #{auditMemo},
  78. </if>
  79. <if test="paymentType != null">
  80. payment_type_ = #{paymentType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  81. </if>
  82. <if test="paymentValidStartDate != null">
  83. payment_valid_start_date_ = #{paymentValidStartDate},
  84. payment_valid_end_date_ = #{paymentValidEndDate},
  85. </if>
  86. <if test="paymentPattern != null">
  87. payment_pattern_ = #{paymentPattern},
  88. </if>
  89. <if test="isGiveMusicNetwork != null">
  90. is_give_music_network_ = #{isGiveMusicNetwork},
  91. </if>
  92. <if test="deadlinePaymentDate != null">
  93. deadline_payment_date_ = #{deadlinePaymentDate},
  94. </if>
  95. <if test="status != null">
  96. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  97. </if>
  98. <if test="expectNum != null">
  99. expect_num_ = #{expectNum},
  100. </if>
  101. <if test="actualNum != null">
  102. actual_num_ = #{actualNum},
  103. </if>
  104. <if test="memo != null">
  105. memo_ = #{memo},
  106. </if>
  107. <if test="startPaymentDate != null">
  108. start_payment_date_ = #{startPaymentDate},
  109. </if>
  110. <if test="musicGroupOrganizationCourseSettingId != null">
  111. music_group_organization_course_settings_id_ = #{musicGroupOrganizationCourseSettingId},
  112. </if>
  113. <if test="payUserType != null">
  114. pay_user_type_ = #{payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  115. </if>
  116. <if test="rejectReason != null">
  117. reject_reason_ = #{rejectReason},
  118. </if>
  119. <if test="updateTime != null">
  120. update_time_ = NOW(),
  121. </if>
  122. <if test="musicGroupId != null">
  123. music_group_id_ = #{musicGroupId},
  124. </if>
  125. <if test="batchNo != null">
  126. batch_no_ = #{batchNo},
  127. </if>
  128. <if test="paymentAmount != null">
  129. payment_amount_ = #{paymentAmount},
  130. </if>
  131. <if test="attribute1 != null">
  132. attribute1_ = #{attribute1},
  133. </if>
  134. <if test="attribute2 != null">
  135. attribute2_ = #{attribute2},
  136. </if>
  137. </set>
  138. WHERE id_ = #{id}
  139. </update>
  140. <update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender">
  141. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  142. UPDATE music_group_payment_calender
  143. <set>
  144. <if test="item.studentIds != null and item.studentIds != ''">
  145. student_ids_ = #{item.studentIds},
  146. </if>
  147. <if test="item.paymentPattern != null">
  148. payment_pattern_ = #{item.paymentPattern},
  149. </if>
  150. <if test="item.isGiveMusicNetwork != null">
  151. is_give_music_network_ = #{item.isGiveMusicNetwork},
  152. </if>
  153. <if test="item.deadlinePaymentDate != null">
  154. deadline_payment_date_ = #{item.deadlinePaymentDate},
  155. </if>
  156. <if test="item.status != null">
  157. status_ = #{item.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  158. </if>
  159. <if test="item.expectNum != null">
  160. expect_num_ = #{item.expectNum},
  161. </if>
  162. <if test="item.actualNum != null">
  163. actual_num_ = #{item.actualNum},
  164. </if>
  165. <if test="item.memo != null">
  166. memo_ = #{item.memo},
  167. </if>
  168. <if test="item.auditMemo != null">
  169. audit_memo_ = #{item.auditMemo},
  170. </if>
  171. <if test="item.startPaymentDate != null">
  172. start_payment_date_ = #{item.startPaymentDate},
  173. </if>
  174. <if test="item.musicGroupOrganizationCourseSettingId != null">
  175. music_group_organization_course_settings_id_ = #{item.musicGroupOrganizationCourseSettingId},
  176. </if>
  177. <if test="item.payUserType != null">
  178. pay_user_type_ = #{item.payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  179. </if>
  180. <if test="item.rejectReason != null">
  181. reject_reason_ = #{item.rejectReason},
  182. </if>
  183. <if test="item.updateTime != null">
  184. update_time_ = NOW(),
  185. </if>
  186. <if test="item.musicGroupId != null">
  187. music_group_id_ = #{item.musicGroupId},
  188. </if>
  189. <if test="item.batchNo != null">
  190. batch_no_ = #{item.batchNo},
  191. </if>
  192. <if test="item.paymentAmount != null">
  193. payment_amount_ = #{item.paymentAmount},
  194. </if>
  195. <if test="item.attribute1 != null">
  196. attribute1_ = #{item.attribute1},
  197. </if>
  198. <if test="item.attribute2 != null">
  199. attribute2_ = #{item.attribute2},
  200. </if>
  201. </set>
  202. WHERE id_ = #{item.id}
  203. </foreach>
  204. </update>
  205. <update id="cutCalenderExpectNum">
  206. UPDATE music_group_payment_calender
  207. SET expect_num_ = expect_num_ - 1
  208. WHERE id_ IN (SELECT music_group_payment_calender_id_ FROM music_group_payment_calender_detail
  209. WHERE user_id_ = #{userId} AND payment_status_ = 'NON_PAYMENT')
  210. AND expect_num_ > 0 AND music_group_id_ = #{musicGroupId}
  211. </update>
  212. <select id="findStudentNoPaymentCalender" resultType="java.lang.Long">
  213. SELECT DISTINCT mgpc.id_ FROM music_group_payment_calender mgpc
  214. WHERE mgpc.student_ids_ = #{userId} AND mgpc.payment_type_ = 'ADD_STUDENT'
  215. AND mgpc.music_group_id_ = #{musicGroupId} AND status_ in ('AUDITING','REJECT')
  216. </select>
  217. <!-- 根据主键删除一条记录 -->
  218. <delete id="delete">
  219. DELETE FROM music_group_payment_calender WHERE id_ = #{id}
  220. </delete>
  221. <!-- 根据主键删除一条记录 -->
  222. <delete id="delByIds">
  223. DELETE FROM music_group_payment_calender WHERE id_ IN
  224. <foreach collection="calenderIds" item="item" separator="," open="(" close=")">
  225. #{item}
  226. </foreach>
  227. </delete>
  228. <delete id="delByGroupId">
  229. DELETE FROM music_group_payment_calender WHERE music_group_id_ = #{musicGroupId}
  230. </delete>
  231. <!-- 分页查询 -->
  232. <select id="queryPage" resultMap="MusicGroupPaymentCalender" parameterType="map">
  233. SELECT * FROM music_group_payment_calender mgpc
  234. <include refid="queryPageSql"/>
  235. ORDER BY mgpc.payment_valid_start_date_,mgpc.id_ DESC
  236. <include refid="global.limit"/>
  237. </select>
  238. <sql id="queryPageSql">
  239. <where>
  240. <if test="musicGroupId != null">
  241. AND mgpc.music_group_id_ = #{musicGroupId}
  242. </if>
  243. <if test="batchNo != null">
  244. AND mgpc.batch_no_ = #{batchNo}
  245. </if>
  246. <if test="payUserType != null">
  247. AND mgpc.pay_user_type_ = #{payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  248. </if>
  249. <if test="paymentType != null">
  250. AND mgpc.payment_type_ = #{paymentType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  251. </if>
  252. <if test="status != null">
  253. AND mgpc.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  254. </if>
  255. </where>
  256. </sql>
  257. <!-- 查询当前表的总记录数 -->
  258. <select id="queryCount" resultType="int">
  259. SELECT COUNT(mgpc.id_) FROM music_group_payment_calender mgpc
  260. <include refid="queryPageSql"/>
  261. </select>
  262. <select id="findByMusicGroupId" resultMap="MusicGroupPaymentCalender">
  263. SELECT * FROM music_group_payment_calender mgpc
  264. WHERE music_group_id_ = #{musicGroupId}
  265. ORDER BY id_
  266. </select>
  267. <select id="queryByPaymentStatus" resultMap="MusicGroupPaymentCalender">
  268. SELECT * FROM music_group_payment_calender mgpc
  269. <where>
  270. <if test="status != null">
  271. status_ in
  272. <foreach collection="status" item="item" open="(" close=")" separator=",">
  273. #{item,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  274. </foreach>
  275. </if>
  276. <if test="payUserType != null">
  277. AND pay_user_type_ = #{payUserType}
  278. </if>
  279. </where>
  280. </select>
  281. <select id="getForLock" resultMap="MusicGroupPaymentCalender">
  282. SELECT * FROM music_group_payment_calender WHERE id_ = #{id} FOR UPDATE
  283. </select>
  284. <select id="queryIntersectionByPaymentDate" resultType="int" parameterType="map">
  285. SELECT count(*) FROM music_group_payment_calender mgpc
  286. WHERE music_group_id_ = #{musicGroupId}
  287. and (start_payment_date_ between #{startPaymentDate} and #{deadlinePaymentDate}
  288. or deadline_payment_date_ between #{startPaymentDate} and #{deadlinePaymentDate})
  289. <if test="calenderId != null">
  290. AND mgpc.id_ != #{calenderId}
  291. </if>
  292. </select>
  293. <select id="getLastStartOne" resultMap="MusicGroupPaymentCalender">
  294. SELECT * FROM music_group_payment_calender WHERE music_group_id_ = #{musicGroupId} ORDER BY start_payment_date_ DESC LIMIT 1
  295. </select>
  296. <select id="queryIntersectionByDate" resultType="java.lang.Integer">
  297. SELECT COUNT(DISTINCT mgpcd.id_) FROM music_group_payment_calender mgpc
  298. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  299. WHERE mgpc.music_group_id_ = #{musicGroupId} AND mgpcd.payment_status_ != 'PAID_COMPLETED'
  300. AND (DATE_FORMAT(mgpcd.start_payment_date_,'%Y-%m-%d') between #{startTime} AND #{endTime}
  301. OR DATE_FORMAT(mgpcd.deadline_payment_date_,'%Y-%m-%d') between #{startTime} AND #{endTime})
  302. </select>
  303. <select id="queryIntersectionByValidDate" resultType="java.lang.Integer">
  304. SELECT COUNT(*) FROM music_group_payment_calender mgpc
  305. WHERE music_group_id_ = #{musicGroupId}
  306. AND (payment_valid_end_date_ IS NULL OR payment_valid_start_date_ BETWEEN #{paymentValidStartDate} AND #{paymentValidEndDate}
  307. OR payment_valid_end_date_ BETWEEN #{paymentValidStartDate} AND #{paymentValidEndDate}) AND payment_valid_start_date_ IS NOT NULL
  308. AND mgpc.payment_type_ NOT IN ('SPAN_GROUP_CLASS_ADJUST','ADD_STUDENT','ADD_COURSE') AND mgpc.batch_no_ IS NOT NULL
  309. <if test="payUserType != null">
  310. and pay_user_type_ = #{payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  311. </if>
  312. <if test="calenderId != null">
  313. AND mgpc.id_ != #{calenderId}
  314. </if>
  315. </select>
  316. <select id="queryCalenderByDay" resultType="java.util.Map">
  317. SELECT mgpcd.music_group_payment_calender_id_ 'key',COUNT(mgpcd.payment_status_) 'value'
  318. FROM music_group_payment_calender_detail mgpcd
  319. WHERE mgpcd.music_group_payment_calender_id_ IN
  320. (SELECT id_ FROM music_group_payment_calender WHERE status_ != 0
  321. AND DATEDIFF(#{format},DATE_FORMAT(start_payment_date_,'%Y-%m-%d')) = #{configValue})
  322. AND mgpcd.payment_status_ = 'NON_PAYMENT'
  323. GROUP BY mgpcd.music_group_payment_calender_id_
  324. </select>
  325. <select id="queryByIds" resultMap="MusicGroupPaymentCalender">
  326. SELECT * FROM music_group_payment_calender WHERE id_ IN
  327. <foreach collection="calenderId" open="(" close=")" item="item" separator=",">
  328. #{item}
  329. </foreach>
  330. </select>
  331. <select id="queryEndIds" resultType="java.lang.Long">
  332. SELECT DISTINCT mgpc.id_ FROM music_group_payment_calender mgpc
  333. WHERE mgpc.payment_valid_end_date_ IS NOT NULL AND DATEDIFF(mgpc.payment_valid_end_date_,#{format}) = #{configValue}
  334. AND mgpc.payment_type_ IN ('MUSIC_APPLY','MUSIC_RENEW')
  335. <if test="musicGroupIds != null">
  336. AND mgpc.music_group_id_ IN
  337. <foreach collection="musicGroupIds" open="(" close=")" item="item" separator=",">
  338. #{item}
  339. </foreach>
  340. </if>
  341. </select>
  342. <resultMap id="CalenderPushDto" type="com.ym.mec.biz.dal.dto.CalenderPushDto">
  343. <result property="paymentValidEndDate" column="payment_valid_end_date_"/>
  344. <result property="paymentValidStartDate" column="payment_valid_start_date_"/>
  345. <result property="teacherId" column="educational_teacher_id_"/>
  346. <result property="musicGroupName" column="name_"/>
  347. <result property="teacherPhone" column="phone_"/>
  348. <result property="calenderId" column="id_"/>
  349. </resultMap>
  350. <select id="getCalenderPushDto" resultMap="CalenderPushDto">
  351. SELECT mgpc.id_,mgpc.payment_valid_start_date_,mgpc.payment_valid_end_date_,
  352. mg.educational_teacher_id_,mg.name_,su.phone_
  353. FROM music_group_payment_calender mgpc
  354. LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
  355. LEFT JOIN sys_user su ON su.id_ = mg.educational_teacher_id_
  356. WHERE mgpc.id_ IN
  357. <foreach collection="calenderIds" open="(" close=")" separator="," item="item">
  358. #{item}
  359. </foreach>
  360. </select>
  361. <select id="getMusicCalenderPushDto" resultMap="CalenderPushDto">
  362. SELECT mg.payment_valid_start_date_,mg.payment_valid_end_date_,
  363. mg.educational_teacher_id_,su.phone_,mg.name_ FROM music_group mg
  364. LEFT JOIN sys_user su ON mg.educational_teacher_id_ = su.id_
  365. WHERE mg.payment_valid_end_date_ IS NOT NULL AND
  366. DATEDIFF(mg.payment_valid_end_date_,#{format}) = #{configValue}
  367. </select>
  368. <select id="getMusicGroupUnusedFirstPaymentCalender" resultMap="MusicGroupPaymentCalender">
  369. SELECT
  370. mgpc.*
  371. FROM
  372. music_group_payment_calender_detail mgpcd
  373. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  374. LEFT JOIN music_group_payment_calender_course_settings mgpccs ON mgpc.id_ = mgpccs.music_group_payment_calender_id_
  375. WHERE
  376. mgpcd.music_group_payment_calender_id_ = mgpccs.music_group_payment_calender_id_
  377. AND mgpc.music_group_id_ = #{musicGroupId}
  378. AND mgpcd.use_in_course_ = 0
  379. AND mgpcd.user_id_ IN
  380. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  381. #{studentId}
  382. </foreach>
  383. ORDER BY
  384. mgpc.payment_valid_start_date_
  385. LIMIT 1;
  386. </select>
  387. <select id="getUnusedFirstPaymentCalenderWithCalenders" resultMap="MusicGroupPaymentCalender">
  388. SELECT * FROM music_group_payment_calender mgpc
  389. WHERE id_ IN
  390. <foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
  391. #{calenderId}
  392. </foreach>
  393. ORDER BY create_time_ LIMIT 1;
  394. </select>
  395. <select id="findByBatchNo" resultMap="MusicGroupPaymentCalender">
  396. SELECT * FROM music_group_payment_calender WHERE FIND_IN_SET(batch_no_,#{batchNo})
  397. </select>
  398. <resultMap id="MusicGroupPaymentCalenderAuditDtoMap" type="com.ym.mec.biz.dal.dto.MusicGroupPaymentCalenderAuditDto">
  399. <result property="musicGroupId" column="music_group_id_"/>
  400. <result column="music_group_organization_course_settings_id_" property="musicGroupOrganizationCourseSettingsId" />
  401. <result property="batchNo" column="batch_no_"/>
  402. <result property="musicGroupName" column="music_group_name_"/>
  403. <result property="organId" column="organ_id_"/>
  404. <result property="organName" column="organ_name_"/>
  405. <result property="createTime" column="create_time_"/>
  406. <result property="paymentType" column="payment_type_"/>
  407. <result property="memo" column="memo_"/>
  408. <result property="operator" column="operator_"/>
  409. <result property="auditStatus" column="status_"/>
  410. <result property="addCourseTotalTime" column="course_total_minuties_"/>
  411. <result property="courseCurrentPrice" column="course_current_price_"/>
  412. <result property="courseOriginalPrice" column="course_original_price_"/>
  413. <result property="musicGroupPaymentCalenderId" column="id_"/>
  414. <result property="payUserType" column="pay_user_type_"/>
  415. <result property="calenderSettingsName" column="calender_settings_name_"/>
  416. <result property="paymentPattern" column="payment_pattern_"/>
  417. <result property="paymentValidStartDate" column="payment_valid_start_date_"/>
  418. <result property="paymentValidEndDate" column="payment_valid_end_date_"/>
  419. <result property="startPaymentDate" column="start_payment_date_"/>
  420. <result property="deadlinePaymentDate" column="deadline_payment_date_"/>
  421. <result property="auditMemo" column="audit_memo_"/>
  422. <result property="paymentAmount" column="payment_amount_"/>
  423. <result property="isGiveMusicNetwork" column="is_give_music_network_"/>
  424. </resultMap>
  425. <sql id="MusicGroupPaymentCalenderAuditDtoSql">
  426. <where>
  427. mgpc.batch_no_ IS NOT NULL
  428. <if test="paymentType != null">
  429. AND mgpc.payment_type_ = #{paymentType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  430. </if>
  431. <if test="payUserType != null">
  432. AND mgpc.pay_user_type_ = #{payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  433. </if>
  434. <if test="status != null">
  435. AND mgpc.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  436. </if>
  437. <if test="organId != null and organId != ''">
  438. AND FIND_IN_SET(mg.organ_id_,#{organId})
  439. </if>
  440. <if test="search != null and search != ''">
  441. AND (mg.id_ LIKE CONCAT('%',#{search},'%') OR mg.name_ LIKE CONCAT('%',#{search},'%'))
  442. </if>
  443. </where>
  444. </sql>
  445. <select id="countAuditList" resultType="java.lang.Integer">
  446. SELECT COUNT(DISTINCT mgpc.batch_no_)
  447. FROM music_group_payment_calender mgpc
  448. LEFT JOIN music_group mg ON mg.id_ = mgpc.music_group_id_
  449. <include refid="MusicGroupPaymentCalenderAuditDtoSql"/>
  450. </select>
  451. <select id="queryAuditList" resultMap="MusicGroupPaymentCalenderAuditDtoMap">
  452. SELECT mgpc.batch_no_,MAX(mgpc.music_group_id_) music_group_id_
  453. ,MAX(mgpc.create_time_) create_time_,MAX(mgpc.payment_type_) payment_type_,MAX(mgpc.operator_) operator_,
  454. MAX(mgpc.pay_user_type_) pay_user_type_,MAX(mgpc.memo_) memo_,MAX(mgpc.audit_memo_) audit_memo_,MAX(mgpc.status_) status_,
  455. CASE WHEN MAX(mgpc.payment_type_) = 'SPAN_GROUP_CLASS_ADJUST' THEN MAX(mgsca.master_class_course_times_) ELSE SUM(mgpccs.course_total_minuties_) END course_total_minuties_,
  456. CASE WHEN MAX(mgpc.payment_type_) = 'SPAN_GROUP_CLASS_ADJUST' THEN MAX(mgpc.payment_amount_) ELSE SUM(mgpccs.course_original_price_) END course_original_price_,
  457. SUM(mgpccs.course_current_price_) course_current_price_,
  458. MAX(mg.name_) music_group_name_,MAX(mg.organ_id_) organ_id_,MAX(mgpc.payment_pattern_)payment_pattern_
  459. FROM music_group_payment_calender mgpc
  460. LEFT JOIN music_group mg ON mg.id_ = mgpc.music_group_id_
  461. LEFT JOIN music_group_payment_calender_course_settings mgpccs ON mgpc.id_ = mgpccs.music_group_payment_calender_id_
  462. LEFT JOIN music_group_student_class_adjust mgsca ON mgsca.batch_no_ = mgpc.batch_no_
  463. <include refid="MusicGroupPaymentCalenderAuditDtoSql"/>
  464. GROUP BY mgpc.batch_no_
  465. ORDER BY create_time_ DESC
  466. <include refid="global.limit"/>
  467. </select>
  468. <select id="countExpectNum" resultType="java.util.Map">
  469. SELECT mgpcd.music_group_payment_calender_id_ 'key',COUNT(DISTINCT mgpcd.user_id_) 'value' FROM music_group_payment_calender_detail mgpcd
  470. WHERE mgpcd.music_group_payment_calender_id_ = #{id}
  471. GROUP BY mgpcd.music_group_payment_calender_id_
  472. </select>
  473. <select id="countActualNum" resultType="java.util.Map">
  474. SELECT mgpcd.music_group_payment_calender_id_ 'key',COUNT(DISTINCT mgpcd.user_id_) 'value' FROM music_group_payment_calender_detail mgpcd
  475. WHERE mgpcd.music_group_payment_calender_id_ = #{id}
  476. AND mgpcd.payment_status_ = 'PAID_COMPLETED'
  477. GROUP BY mgpcd.music_group_payment_calender_id_
  478. </select>
  479. <select id="getAuditDetail" resultMap="MusicGroupPaymentCalenderAuditDtoMap">
  480. SELECT mgpc.batch_no_,MAX(mgpc.music_group_id_) music_group_id_
  481. ,MAX(mgpc.create_time_) create_time_,MAX(mgpc.payment_type_) payment_type_,MAX(mgpc.music_group_organization_course_settings_id_) music_group_organization_course_settings_id_,
  482. MAX(mgpc.pay_user_type_) pay_user_type_,MAX(mg.name_) music_group_name_,MAX(mgpc.payment_pattern_)payment_pattern_,MAX(o.name_) organ_name_
  483. FROM music_group_payment_calender mgpc
  484. LEFT JOIN music_group mg ON mg.id_ = mgpc.music_group_id_
  485. LEFT JOIN organization o ON o.id_ = mg.organ_id_
  486. WHERE mgpc.batch_no_ = #{batchNo}
  487. GROUP BY mgpc.batch_no_
  488. </select>
  489. <select id="findByMusicGroupRegCalender" resultMap="MusicGroupPaymentCalender">
  490. SELECT * FROM music_group_payment_calender WHERE music_group_id_=#{musicGroupId} AND payment_type_='MUSIC_APPLY'
  491. </select>
  492. <select id="getCalenderSettingsName" resultType="java.lang.String">
  493. SELECT name_ FROM music_group_payment_calender_course_settings
  494. WHERE music_group_payment_calender_id_ = #{calenderId} LIMIT 1
  495. </select>
  496. <select id="countAuditReject" resultType="java.lang.Integer">
  497. SELECT COUNT(0) FROM music_group_payment_calender
  498. WHERE music_group_id_ = #{musicGroupId} AND payment_type_='MUSIC_APPLY' AND status_ IN ('REJECT','AUDITING')
  499. <if test="calenderId != null">
  500. AND id_ != #{calenderId}
  501. </if>
  502. </select>
  503. <select id="getMusicGroupRegCalender" resultMap="MusicGroupPaymentCalender">
  504. SELECT * FROM music_group_payment_calender
  505. WHERE music_group_id_ = #{musicGroupId}
  506. AND payment_type_ = 'MUSIC_APPLY'
  507. AND pay_user_type_='STUDENT'
  508. </select>
  509. <select id="queryUserPaymentStatus" resultType="java.util.Map">
  510. SELECT mg.id_ 'key',CASE WHEN MIN(mgpcd.payment_status_) IS NULL THEN 'PAID_COMPLETED' ELSE MIN(mgpcd.payment_status_) END 'value'
  511. FROM music_group mg
  512. LEFT JOIN music_group_payment_calender mgpc ON mgpc.music_group_id_ = mg.id_
  513. AND mgpc.status_ IN ('NO','OPEN','OVER')
  514. AND DATE_FORMAT(NOW(),'%Y-%m-%d') >= DATE_FORMAT(mgpc.payment_valid_start_date_,'%Y-%m-%d')
  515. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_ AND mgpcd.user_id_ = #{userId}
  516. WHERE FIND_IN_SET(mg.id_,#{musicGroupId}) AND mgpc.batch_no_ IS NOT NULL AND mgpc.pay_user_type_ = 'STUDENT'
  517. GROUP BY mg.id_
  518. </select>
  519. <select id="queryUserCoursePaymentStatus" resultType="java.util.Map">
  520. SELECT mgpcd.user_id_ 'key',
  521. CASE WHEN MIN(mgpcd.payment_status_) IS NULL THEN 'PAID_COMPLETED' ELSE MIN(mgpcd.payment_status_) END 'value'
  522. FROM music_group mg
  523. LEFT JOIN music_group_payment_calender mgpc ON mgpc.music_group_id_ = mg.id_
  524. AND mgpc.status_ IN ('NO','OPEN','OVER')
  525. AND DATE_FORMAT(NOW(),'%Y-%m-%d') >= DATE_FORMAT(mgpc.payment_valid_start_date_,'%Y-%m-%d')
  526. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  527. WHERE mg.id_ = #{musicGroupId} AND mgpcd.expect_amount_ > 0 AND mgpc.batch_no_ IS NOT NULL AND mgpc.pay_user_type_ = 'STUDENT' AND mgpcd.user_id_ IN
  528. <foreach collection="studentId" item="item" separator="," open="(" close=")">
  529. #{item}
  530. </foreach>
  531. GROUP BY mgpcd.user_id_
  532. </select>
  533. <select id="findByBatchNoAndStudentId" resultType="Long">
  534. SELECT DISTINCT mgpc.id_ FROM music_group_payment_calender mgpc
  535. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  536. WHERE FIND_IN_SET(batch_no_,#{batchNo}) AND mgpcd.user_id_ = #{studentId}
  537. </select>
  538. <select id="getPaymentCalenderWithCalenderIdsAndPayUserType" resultMap="MusicGroupPaymentCalender">
  539. SELECT * FROM music_group_payment_calender
  540. WHERE id_ IN
  541. <foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
  542. #{calenderId}
  543. </foreach>
  544. AND pay_user_type_ = #{payUserType}
  545. AND status_ IN ('NO', 'OPEN', 'OVER', 'PAID');
  546. </select>
  547. <select id="getSchoolCalender" resultMap="MusicGroupPaymentCalender">
  548. SELECT * FROM music_group_payment_calender WHERE id_ = #{calenderId} AND status_ IN ('NO', 'OPEN', 'OVER', 'PAID');
  549. </select>
  550. <select id="queryMusicGroupIds" resultType="java.lang.String">
  551. SELECT music_group_id_ FROM music_group_payment_calender
  552. WHERE id_ IN
  553. <foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
  554. #{calenderId}
  555. </foreach>
  556. </select>
  557. <select id="getMusicGroupCalenderBatchNoTimes" resultMap="MusicGroupPaymentCalender">
  558. SELECT batch_no_, COUNT(*) expect_num_ FROM music_group_payment_calender
  559. WHERE music_group_id_ = #{musicGroupId}
  560. AND status_ IN ('AUDITING','NO', 'OPEN', 'OVER', 'PAID')
  561. GROUP BY batch_no_
  562. </select>
  563. <select id="getMusicGroupRegCalenderByIds" resultMap="MusicGroupPaymentCalender">
  564. SELECT * FROM music_group_payment_calender WHERE music_group_id_ IN
  565. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  566. #{id}
  567. </foreach>
  568. AND payment_type_='MUSIC_APPLY' AND batch_no_ IS NOT NULL
  569. </select>
  570. <select id="getMusicGroupCalenderBatchNoByIds" resultMap="MusicGroupPaymentCalender">
  571. SELECT music_group_id_,batch_no_, COUNT(*) expect_num_ FROM music_group_payment_calender
  572. WHERE music_group_id_ IN
  573. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  574. #{id}
  575. </foreach>
  576. AND status_ IN ('AUDITING','NO', 'OPEN', 'OVER', 'PAID')
  577. AND batch_no_ IS NOT NULL
  578. GROUP BY music_group_id_,batch_no_
  579. </select>
  580. </mapper>