MusicGroupPaymentCalenderDetailMapper.xml 25 KB

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