MusicGroupPaymentCalenderDetailMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. <mapper namespace="com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDetailDao">
  5. <resultMap type="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail"
  6. id="MusicGroupPaymentCalenderDetail">
  7. <result column="id_" property="id" />
  8. <result column="music_group_payment_calender_id_" property="musicGroupPaymentCalenderId" />
  9. <result column="user_id_" property="userId" />
  10. <result column="expect_amount_" property="expectAmount" />
  11. <result column="actual_amount_" property="actualAmount" />
  12. <result column="payment_status_" property="paymentStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  13. <result column="user_status_" property="userStatus" />
  14. <result column="music_group_id_" property="musicGroupId" />
  15. <result column="pay_time_" property="payTime" />
  16. <result column="start_payment_date_" property="startPaymentDate" />
  17. <result column="deadline_payment_date_" property="deadlinePaymentDate" />
  18. <result column="start_payment_date_mgpc_" property="startPaymentDateMgpc" />
  19. <result column="deadline_payment_date_mgpc_" property="deadlinePaymentDateMgpc" />
  20. <result column="payment_order_id_" property="paymentOrderId"/>
  21. <result column="update_time_" property="updateTime" />
  22. <result column="create_time_" property="createTime" />
  23. <result column="open_" property="open"/>
  24. <result column="open_" property="openFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  25. <result column="use_in_course_" property="useInCourse"/>
  26. <result column="responsible_user_id_" property="responsibleUserId"/>
  27. <result column="responsible_record_" property="responsibleRecord"/>
  28. <result column="responsible_username_" property="responsible.username"/>
  29. <association property="sysUser" javaType="com.ym.mec.auth.api.entity.SysUser">
  30. <result column="username_" property="username" />
  31. <result column="phone_" property="phone" />
  32. </association>
  33. <association property="studentRegistration" javaType="com.ym.mec.biz.dal.entity.StudentRegistration">
  34. <result column="subject_names_" property="subjectName" />
  35. <result column="music_group_status_" property="musicGroupStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  36. </association>
  37. </resultMap>
  38. <!-- 根据主键查询一条记录 -->
  39. <select id="get" resultMap="MusicGroupPaymentCalenderDetail">
  40. SELECT * FROM music_group_payment_calender_detail WHERE id_ = #{id}
  41. </select>
  42. <!-- 全查询 -->
  43. <select id="findAll" resultMap="MusicGroupPaymentCalenderDetail">
  44. SELECT * FROM music_group_payment_calender_detail ORDER BY id_
  45. </select>
  46. <!-- 向数据库增加一条记录 -->
  47. <insert id="insert"
  48. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail"
  49. useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  50. INSERT INTO music_group_payment_calender_detail
  51. (id_,music_group_payment_calender_id_,user_id_,expect_amount_,actual_amount_,payment_status_,
  52. user_status_,pay_time_,update_time_,create_time_,start_payment_date_,deadline_payment_date_,payment_order_id_,use_in_course_,responsible_user_id_,responsible_record_)
  53. VALUES(#{id},#{musicGroupPaymentCalenderId},#{userId},#{expectAmount},#{actualAmount},#{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  54. #{userStatus},#{payTime},NOW(),NOW(),#{startPaymentDate},#{deadlinePaymentDate},#{paymentOrderId},#{useInCourse},#{responsibleUserId},#{responsibleRecord})
  55. </insert>
  56. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
  57. keyProperty="id">
  58. INSERT INTO music_group_payment_calender_detail
  59. (id_,music_group_payment_calender_id_,user_id_,expect_amount_,actual_amount_,
  60. payment_status_,user_status_,pay_time_,update_time_,create_time_,start_payment_date_,deadline_payment_date_,payment_order_id_,use_in_course_,responsible_user_id_,responsible_record_)
  61. VALUES
  62. <foreach collection="list" item="item" separator=",">
  63. (#{item.id},#{item.musicGroupPaymentCalenderId},#{item.userId},#{item.expectAmount},
  64. #{item.actualAmount},#{item.paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{item.userStatus},#{item.payTime},
  65. #{item.updateTime},#{item.createTime},#{item.startPaymentDate},#{item.deadlinePaymentDate},#{item.paymentOrderId},#{item.useInCourse},#{item.responsibleUserId},#{item.responsibleRecord})
  66. </foreach>
  67. </insert>
  68. <!-- 根据主键查询一条记录 -->
  69. <update id="update"
  70. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail">
  71. UPDATE music_group_payment_calender_detail
  72. <set>
  73. <if test="startPaymentDate != null">
  74. start_payment_date_ = #{startPaymentDate},
  75. </if>
  76. <if test="deadlinePaymentDate != null">
  77. deadline_payment_date_ = #{deadlinePaymentDate},
  78. </if>
  79. <if test="open != null">
  80. open_ = #{open},
  81. </if>
  82. <if test="userId != null">
  83. user_id_ = #{userId},
  84. </if>
  85. <if test="userStatus != null">
  86. user_status_ = #{userStatus},
  87. </if>
  88. <if test="paymentStatus != null">
  89. payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  90. </if>
  91. <if test="expectAmount != null">
  92. expect_amount_ = #{expectAmount},
  93. </if>
  94. <if test="updateTime != null">
  95. update_time_ = #{updateTime},
  96. </if>
  97. <if test="musicGroupPaymentCalenderId != null">
  98. music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId},
  99. </if>
  100. <if test="actualAmount != null">
  101. actual_amount_ = #{actualAmount},
  102. </if>
  103. <if test="payTime != null">
  104. pay_time_ = #{payTime},
  105. </if>
  106. <if test="paymentOrderId != null">
  107. payment_order_id_ = #{paymentOrderId},
  108. </if>
  109. <if test="useInCourse != null">
  110. use_in_course_ = #{useInCourse},
  111. </if>
  112. <if test="responsibleUserId != null">
  113. responsible_user_id_ = #{responsibleUserId},
  114. </if>
  115. <if test="responsibleRecord != null">
  116. responsible_record_ = #{responsibleRecord},
  117. </if>
  118. </set>
  119. WHERE id_ = #{id}
  120. </update>
  121. <update id="batchUpdate">
  122. <foreach collection="calenderDetails" item="item" index="index" open="" close="" separator=";">
  123. UPDATE music_group_payment_calender_detail
  124. <set>
  125. <if test="item.startPaymentDate != null">
  126. start_payment_date_ = #{item.startPaymentDate},
  127. </if>
  128. <if test="item.deadlinePaymentDate != null">
  129. deadline_payment_date_ = #{item.deadlinePaymentDate},
  130. </if>
  131. <if test="item.open != null">
  132. open_ = #{item.open},
  133. </if>
  134. <if test="item.userId != null">
  135. user_id_ = #{item.userId},
  136. </if>
  137. <if test="item.userStatus != null">
  138. user_status_ = #{item.userStatus},
  139. </if>
  140. <if test="item.paymentStatus != null">
  141. payment_status_ = #{item.paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  142. </if>
  143. <if test="item.expectAmount != null">
  144. expect_amount_ = #{item.expectAmount},
  145. </if>
  146. <if test="item.updateTime != null">
  147. update_time_ = #{item.updateTime},
  148. </if>
  149. <if test="item.musicGroupPaymentCalenderId != null">
  150. music_group_payment_calender_id_ = #{item.musicGroupPaymentCalenderId},
  151. </if>
  152. <if test="item.actualAmount != null">
  153. actual_amount_ = #{item.actualAmount},
  154. </if>
  155. <if test="item.payTime != null">
  156. pay_time_ = #{item.payTime},
  157. </if>
  158. <if test="item.paymentOrderId != null">
  159. payment_order_id_ = #{item.paymentOrderId},
  160. </if>
  161. <if test="item.useInCourse != null">
  162. use_in_course_ = #{item.useInCourse},
  163. </if>
  164. <if test="item.responsibleUserId != null">
  165. responsible_user_id_ = #{item.responsibleUserId},
  166. </if>
  167. <if test="item.responsibleRecord != null">
  168. responsible_record_ = #{item.responsibleRecord},
  169. </if>
  170. </set>
  171. WHERE id_ = #{item.id}
  172. </foreach>
  173. </update>
  174. <update id="refreshUserMusicGroupPaymentStatusTask">
  175. UPDATE music_group_payment_calender_detail mgpcd
  176. SET mgpcd.open_ = 0,mgpcd.start_payment_date_ = NULL,mgpcd.deadline_payment_date_ = NULL
  177. WHERE mgpcd.deadline_payment_date_ &lt; DATE_FORMAT(NOW(),'%Y-%m-%d')
  178. </update>
  179. <!-- 根据主键删除一条记录 -->
  180. <delete id="delete">
  181. DELETE FROM music_group_payment_calender_detail WHERE id_ = #{id}
  182. </delete>
  183. <delete id="batchDel">
  184. DELETE FROM music_group_payment_calender_detail WHERE FIND_IN_SET(id_,#{musicGroupPaymentCalenderIdDetails})
  185. </delete>
  186. <delete id="deleteByCalenderId">
  187. DELETE FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{id}
  188. </delete>
  189. <select id="queryNotPaymentStudentByUserIdAndMusicGroupId" resultMap="MusicGroupPaymentCalenderDetail" parameterType="map">
  190. select * FROM music_group_payment_calender_detail
  191. WHERE music_group_payment_calender_id_ IN (SELECT mgpc.id_ FROM music_group_payment_calender mgpc
  192. WHERE mgpc.music_group_id_ = #{musicGroupId})
  193. AND user_id_ = #{userId} AND payment_status_ = 'NON_PAYMENT'
  194. </select>
  195. <!-- 分页查询 -->
  196. <select id="queryPage" resultMap="MusicGroupPaymentCalenderDetail" parameterType="map">
  197. SELECT su.username_,su.phone_,st.name_ subject_names_,sr.music_group_status_,tu.real_name_ responsible_username_,
  198. CASE WHEN mgpcd.start_payment_date_ IS NULL THEN mgpc.start_payment_date_ ELSE mgpcd.start_payment_date_ END start_payment_date_mgpc_,
  199. CASE WHEN mgpcd.deadline_payment_date_ IS NULL THEN mgpc.deadline_payment_date_ ELSE mgpcd.deadline_payment_date_ END deadline_payment_date_mgpc_,
  200. CASE WHEN mgpc.status_ = 'OPEN' OR mgpcd.open_ = 1 THEN 1 ELSE 0 END open_,mgpcd.*
  201. FROM music_group_payment_calender_detail mgpcd
  202. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  203. left join sys_user tu on tu.id_ = mgpcd.responsible_user_id_
  204. LEFT JOIN student_registration sr ON sr.user_id_ = mgpcd.user_id_
  205. LEFT JOIN `subject` st ON st.id_ = sr.actual_subject_id_
  206. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  207. <include refid="queryPageSql"/>
  208. ORDER BY mgpc.update_time_ DESC
  209. <include refid="global.limit" />
  210. </select>
  211. <sql id="queryPageSql">
  212. <where>
  213. mgpc.music_group_id_ = sr.music_group_id_
  214. <if test="search != null and search != ''">
  215. AND (mgpcd.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  216. </if>
  217. <if test="id != null">
  218. AND mgpcd.music_group_payment_calender_id_ = #{id}
  219. </if>
  220. <if test="paymentStatus != null and paymentStatus != ''">
  221. AND mgpcd.payment_status_ = #{paymentStatus}
  222. </if>
  223. <if test="musicGroupId != null and musicGroupId != ''">
  224. AND mgpc.music_group_id_ = #{musicGroupId}
  225. </if>
  226. <if test="userId != null">
  227. AND mgpcd.user_id_ = #{userId}
  228. </if>
  229. <if test="musicGroupStatus != null and musicGroupStatus != ''">
  230. AND sr.music_group_status_ = #{musicGroupStatus}
  231. </if>
  232. <if test="subjectId != null">
  233. AND #{subjectId} = sr.actual_subject_id_
  234. </if>
  235. <if test="responsibleRealName != null and responsibleRealName != ''">
  236. AND (mgpcd.responsible_user_id_ = #{responsibleRealName} OR tu.real_name_ LIKE CONCAT('%',#{responsibleRealName},'%') OR tu.phone_ LIKE CONCAT('%',#{responsibleRealName},'%'))
  237. </if>
  238. </where>
  239. </sql>
  240. <!-- 查询当前表的总记录数 -->
  241. <select id="queryCount" resultType="int">
  242. SELECT COUNT(DISTINCT mgpcd.id_) FROM music_group_payment_calender_detail mgpcd
  243. LEFT JOIN student_registration sr ON sr.user_id_ = mgpcd.user_id_
  244. LEFT JOIN `subject` st ON st.id_ = sr.actual_subject_id_
  245. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  246. left join sys_user tu on tu.id_ = mgpcd.responsible_user_id_
  247. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  248. <include refid="queryPageSql"/>
  249. </select>
  250. <select id="queryListByIds" resultMap="MusicGroupPaymentCalenderDetail">
  251. SELECT mgpcd.*,mgpc.music_group_id_ FROM music_group_payment_calender_detail mgpcd
  252. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  253. WHERE FIND_IN_SET(mgpcd.id_,#{ids})
  254. GROUP BY mgpcd.id_
  255. </select>
  256. <select id="queryByCalenderId" resultMap="MusicGroupPaymentCalenderDetail">
  257. SELECT * FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId}
  258. <if test="paymentStatus != null">
  259. AND payment_status_ = #{paymentStatus}
  260. </if>
  261. </select>
  262. <select id="findMusicGroupStudentWithSubject" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  263. SELECT DISTINCT su.id_ userId,su.username_ userName, su.avatar_ avatar, su.phone_ phone
  264. from music_group_student_fee_ mgstf
  265. LEFT JOIN sys_user su ON su.id_=mgstf.user_id_
  266. WHERE mgstf.music_group_id_=#{musicGroupId}
  267. AND mgstf.subject_id_=#{subjectId}
  268. AND mgstf.remain_network_class_times_>0
  269. ORDER BY su.id_
  270. </select>
  271. <select id="getUserLastCalenderDetail" resultMap="MusicGroupPaymentCalenderDetail">
  272. SELECT * FROM music_group_payment_calender_detail mgpcd
  273. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  274. WHERE mgpc.music_group_id_=#{musicGroupId} AND mgpcd.user_id_=#{userId} AND mgpcd.payment_status_ = 'NON_PAYMENT'
  275. AND (mgpc.status_ = 'OPEN' OR mgpcd.open_ = 1)
  276. ORDER BY mgpc.start_payment_date_ DESC LIMIT 1
  277. </select>
  278. <select id="queryCanOpenList" resultMap="MusicGroupPaymentCalenderDetail">
  279. SELECT * FROM music_group_payment_calender_detail
  280. WHERE FIND_IN_SET(id_,#{ids}) AND payment_status_ = 'NON_PAYMENT' AND open_ = 0
  281. </select>
  282. <select id="queryIntersectionByPaymentDate" resultType="java.lang.Integer">
  283. SELECT COUNT(mgpcd.id_) FROM music_group_payment_calender_detail mgpcd
  284. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  285. WHERE mgpc.music_group_id_ = #{musicGroupId} AND mgpcd.user_id_ = #{userId}
  286. AND mgpcd.open_ = 1
  287. </select>
  288. <select id="queryCanPushList" resultMap="MusicGroupPaymentCalenderDetail">
  289. SELECT mgpcd.*,mgpc.music_group_id_ FROM music_group_payment_calender_detail mgpcd
  290. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  291. LEFT JOIN student_registration sr ON sr.music_group_id_ = mgpc.music_group_id_
  292. WHERE mgpcd.payment_status_ = 'NON_PAYMENT' AND sr.music_group_status_ != 'QUIT' AND mgpc.id_ = #{musicGroupPaymentCalenderId}
  293. GROUP BY mgpcd.id_
  294. </select>
  295. <select id="queryNoPaymentCanPushList" resultMap="MusicGroupPaymentCalenderDetail">
  296. SELECT mgpcd.*,mgpc.music_group_id_ FROM music_group_payment_calender mgpc
  297. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  298. WHERE DATE_FORMAT(mgpc.create_time_,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND mgpc.status_ = 'OPEN' AND mgpcd.payment_status_ = 'NON_PAYMENT'
  299. </select>
  300. <select id="queryPaymentPushMap" resultType="java.util.Map">
  301. SELECT mgpcd.user_id_ 'key',mgpc.music_group_id_ 'value' FROM music_group_payment_calender mgpc
  302. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  303. WHERE DATE_FORMAT(mgpc.create_time_,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND mgpc.status_ = 'OPEN' AND mgpcd.payment_status_ = 'NON_PAYMENT'
  304. </select>
  305. <select id="queryStudentIds" resultType="java.lang.Integer">
  306. SELECT user_id_ FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId}
  307. </select>
  308. <select id="countOpenPayment" resultType="java.lang.Integer">
  309. SELECT COUNT(DISTINCT mgpcd.id_) FROM music_group_payment_calender mgpc
  310. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  311. WHERE mgpcd.user_id_ = #{userId} AND mgpc.music_group_id_ = #{musicGroupId} AND (mgpc.status_ = 'OPEN' OR mgpcd.open_ = 1)
  312. AND mgpcd.payment_status_ != 'PAID_COMPLETED'
  313. </select>
  314. <select id="getCalenderDetailWithCalender" resultMap="MusicGroupPaymentCalenderDetail">
  315. SELECT
  316. mgpcd.*
  317. FROM
  318. music_group_payment_calender_detail mgpcd
  319. WHERE
  320. mgpcd.music_group_payment_calender_id_ = #{calenderId}
  321. </select>
  322. <select id="getWithCalenderIds" resultMap="MusicGroupPaymentCalenderDetail">
  323. SELECT
  324. mgpcd.*
  325. FROM
  326. music_group_payment_calender_detail mgpcd
  327. WHERE
  328. mgpcd.music_group_payment_calender_id_ IN
  329. <foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
  330. #{calenderId}
  331. </foreach>
  332. </select>
  333. <resultMap id="SimpleUserDtoMap" type="com.ym.mec.biz.dal.dto.SimpleUserDto">
  334. <result property="userName" column="username_"/>
  335. <result property="userId" column="id_"/>
  336. <result property="subjectNames" column="subject_name_"/>
  337. <result property="actualAmount" column="actual_amount_"/>
  338. </resultMap>
  339. <select id="querySimpleUserDto" resultMap="SimpleUserDtoMap">
  340. SELECT su.id_,su.username_,s.name_ subject_name_,mgpcd.actual_amount_
  341. FROM music_group_payment_calender_detail mgpcd
  342. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  343. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  344. LEFT JOIN student_registration sr ON sr.user_id_ = mgpcd.user_id_ AND sr.music_group_status_ != 'QUIT' AND sr.music_group_id_ = mgpc.music_group_id_
  345. LEFT JOIN `subject` s ON s.id_ = sr.subject_id_
  346. WHERE mgpc.batch_no_ = #{batchNo}
  347. </select>
  348. <select id="sumActualAmount" resultType="java.math.BigDecimal">
  349. SELECT SUM(mgpcd.actual_amount_) FROM music_group_payment_calender_detail mgpcd
  350. WHERE mgpcd.music_group_payment_calender_id_ = #{id}
  351. </select>
  352. <select id="findByCalenderIdAndUserId" resultMap="MusicGroupPaymentCalenderDetail">
  353. SELECT * FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId} AND user_id_ = #{userId} LIMIT 1
  354. </select>
  355. <select id="findByOrderId" resultMap="MusicGroupPaymentCalenderDetail">
  356. SELECT * FROM music_group_payment_calender_detail WHERE payment_order_id_ = #{orderId} LIMIT 1
  357. </select>
  358. <select id="queryNoPaymentStudentIds" resultType="java.lang.Integer">
  359. SELECT user_id_ FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId} AND payment_status_ = 'NON_PAYMENT'
  360. </select>
  361. <select id="queryNoPaymentAndNotZeroStudent" resultType="java.util.Map">
  362. SELECT mgpcd.user_id_ 'key',su.phone_ 'value' FROM music_group_payment_calender_detail mgpcd
  363. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  364. WHERE music_group_payment_calender_id_ = #{calenderId} AND expect_amount_ != 0 AND payment_status_ = 'NON_PAYMENT'
  365. <if test="studentIds != null">
  366. AND mgpcd.user_id_ IN
  367. <foreach collection="studentIds" separator="," close=")" open="(" item="item">
  368. #{item}
  369. </foreach>
  370. </if>
  371. </select>
  372. <select id="queryNoPaymentTotalAmount" resultType="java.util.Map">
  373. SELECT mgpcd.user_id_ 'key',SUM(mgpcd.expect_amount_) 'value' FROM music_group_payment_calender_detail mgpcd
  374. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  375. WHERE mgpc.batch_no_ IS NOT NULL AND mgpcd.payment_status_ = 'NON_PAYMENT' AND mgpcd.expect_amount_ > 0
  376. AND mgpc.music_group_id_ = #{musicGroupId} AND mgpc.status_ IN ('OPEN','OVER','PAID')
  377. GROUP BY mgpcd.user_id_
  378. </select>
  379. <select id="queryNoPaymentUserIds" resultType="java.lang.Integer">
  380. SELECT mgpcd.user_id_ FROM music_group_payment_calender_detail mgpcd
  381. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  382. WHERE mgpc.batch_no_ IS NOT NULL AND mgpcd.payment_status_ = 'NON_PAYMENT' AND mgpcd.expect_amount_ > 0
  383. AND mgpc.music_group_id_ = #{musicGroupId} AND mgpc.status_ IN ('OPEN','OVER','PAID')
  384. <if test="userIds != null">
  385. AND mgpcd.user_id_ IN
  386. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  387. #{item}
  388. </foreach>
  389. </if>
  390. GROUP BY mgpcd.user_id_ HAVING SUM(mgpcd.expect_amount_) > 0
  391. </select>
  392. <resultMap id="MusicArrearageStudentDto" type="com.ym.mec.biz.dal.dto.MusicArrearageStudentDto">
  393. <result property="userId" column="user_id_"/>
  394. <result property="studentName" column="student_name_"/>
  395. <result property="organName" column="organ_name_"/>
  396. <result property="cooperationName" column="cooperation_name_"/>
  397. <result property="musicGroupId" column="music_group_id_"/>
  398. <result property="musicGroupName" column="music_group_name_"/>
  399. <result property="eduTeacherName" column="edu_teacher_name_"/>
  400. <result property="subjectName" column="subject_name_"/>
  401. <result property="gender" column="gender_"/>
  402. <result property="parentName" column="parent_name_"/>
  403. <result property="phone" column="phone_"/>
  404. <result property="noPaymentAmount" column="no_payment_amount_"/>
  405. </resultMap>
  406. <sql id="queryArrearageStudentsCondition">
  407. <where>
  408. mg.status_ = 'PROGRESS'
  409. AND DATE_FORMAT( NOW(), '%Y-%m-%d' ) >= DATE_FORMAT( mgpc.payment_valid_start_date_, '%Y-%m-%d' )
  410. AND mgpcd.payment_status_ = 'NON_PAYMENT' AND mgpc.batch_no_ IS NOT NULL AND mgpc.pay_user_type_ = 'STUDENT'
  411. AND mgpcd.expect_amount_ > 0
  412. <if test="organIds!=null and organIds.size()>0">
  413. AND mg.organ_id_ IN
  414. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  415. #{organId}
  416. </foreach>
  417. </if>
  418. <if test="musicGroupId!=null and musicGroupId!=''">
  419. AND mgpc.music_group_id_ = #{musicGroupId}
  420. </if>
  421. <if test="cooperationOrganId!=null">
  422. AND mg.cooperation_organ_id_ = #{cooperationOrganId}
  423. </if>
  424. <if test="eduTeacherId!=null">
  425. AND mg.educational_teacher_id_=#{eduTeacherId}
  426. </if>
  427. <if test="search!=null and search!=''">
  428. AND (mgpcd.user_id_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  429. </if>
  430. </where>
  431. </sql>
  432. <select id="queryArrearageStudents" resultMap="MusicArrearageStudentDto">
  433. SELECT
  434. mgpcd.user_id_,
  435. SUM( mgpcd.expect_amount_ ) no_payment_amount_,
  436. su.username_ student_name_,
  437. organ.name_ organ_name_,
  438. co.name_ cooperation_name_,
  439. mgpc.music_group_id_,
  440. mg.name_ music_group_name_,
  441. edu.real_name_ edu_teacher_name_,
  442. MAX( sub.name_ ) subject_name_,
  443. su.gender_ gender_,
  444. su.real_name_ parent_name_,
  445. su.phone_ phone_
  446. FROM
  447. music_group_payment_calender_detail mgpcd
  448. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  449. LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
  450. LEFT JOIN student_registration sr ON sr.music_group_id_ = mgpc.music_group_id_
  451. AND mgpcd.user_id_ = sr.user_id_
  452. LEFT JOIN sys_user su ON mgpcd.user_id_ = su.id_
  453. LEFT JOIN sys_user edu ON edu.id_ = mg.educational_teacher_id_
  454. LEFT JOIN organization organ ON organ.id_ = mg.organ_id_
  455. LEFT JOIN `subject` sub ON sr.actual_subject_id_ = sub.id_
  456. LEFT JOIN cooperation_organ co ON mg.cooperation_organ_id_ = co.id_
  457. <include refid="queryArrearageStudentsCondition"/>
  458. GROUP BY
  459. mgpc.music_group_id_,mgpcd.user_id_
  460. <include refid="global.limit" />
  461. </select>
  462. <select id="countArrearageStudents" resultType="int">
  463. SELECT
  464. COUNT(DISTINCT mgpc.music_group_id_,mgpcd.user_id_)
  465. FROM
  466. music_group_payment_calender_detail mgpcd
  467. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  468. LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
  469. <if test="search!=null and search!=''">
  470. LEFT JOIN sys_user su ON mgpcd.user_id_ = su.id_
  471. </if>
  472. <include refid="queryArrearageStudentsCondition"/>
  473. </select>
  474. <select id="getNoPaymentStudentMusicGroups" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.MusicGroup">
  475. SELECT
  476. DISTINCT mg.id_,mg.name_
  477. FROM
  478. music_group_payment_calender_detail mgpcd
  479. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  480. LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
  481. WHERE mg.status_ = 'PROGRESS'
  482. AND DATE_FORMAT( NOW(), '%Y-%m-%d' ) >= DATE_FORMAT( mgpc.payment_valid_start_date_, '%Y-%m-%d' )
  483. AND mgpcd.payment_status_ = 'NON_PAYMENT'
  484. AND mgpcd.expect_amount_ > 0
  485. <if test="organIds!=null and organIds.size()>0">
  486. AND mg.organ_id_ IN
  487. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  488. #{organId}
  489. </foreach>
  490. </if>
  491. </select>
  492. <update id="updateNoPaymentAndZeroPaymentStatus">
  493. UPDATE music_group_payment_calender_detail SET payment_status_ = 'PAID_COMPLETED',actual_amount_ = 0,update_time_ = NOW()
  494. WHERE music_group_payment_calender_id_ = #{calenderId} AND expect_amount_ = 0 AND payment_status_ = 'NON_PAYMENT'
  495. </update>
  496. </mapper>