MusicGroupPaymentCalenderDetailMapper.xml 28 KB

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