MusicGroupPaymentCalenderDetailMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. <association property="sysUser" javaType="com.ym.mec.auth.api.entity.SysUser">
  27. <result column="username_" property="username" />
  28. <result column="phone_" property="phone" />
  29. </association>
  30. <association property="studentRegistration" javaType="com.ym.mec.biz.dal.entity.StudentRegistration">
  31. <result column="subject_names_" property="subjectName" />
  32. <result column="music_group_status_" property="musicGroupStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  33. </association>
  34. </resultMap>
  35. <!-- 根据主键查询一条记录 -->
  36. <select id="get" resultMap="MusicGroupPaymentCalenderDetail">
  37. SELECT * FROM music_group_payment_calender_detail WHERE id_ = #{id}
  38. </select>
  39. <!-- 全查询 -->
  40. <select id="findAll" resultMap="MusicGroupPaymentCalenderDetail">
  41. SELECT * FROM music_group_payment_calender_detail ORDER BY id_
  42. </select>
  43. <!-- 向数据库增加一条记录 -->
  44. <insert id="insert"
  45. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail"
  46. useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  47. INSERT INTO music_group_payment_calender_detail
  48. (id_,music_group_payment_calender_id_,user_id_,expect_amount_,actual_amount_,payment_status_,
  49. user_status_,pay_time_,update_time_,create_time_,start_payment_date_,deadline_payment_date_,payment_order_id_,use_in_course_)
  50. VALUES(#{id},#{musicGroupPaymentCalenderId},#{userId},#{expectAmount},#{actualAmount},#{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  51. #{userStatus},#{payTime},#{updateTime},#{createTime},#{startPaymentDate},#{deadlinePaymentDate},#{paymentOrderId},#{useInCourse})
  52. </insert>
  53. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
  54. keyProperty="id">
  55. INSERT INTO music_group_payment_calender_detail
  56. (id_,music_group_payment_calender_id_,user_id_,expect_amount_,actual_amount_,
  57. payment_status_,user_status_,pay_time_,update_time_,create_time_,start_payment_date_,deadline_payment_date_,payment_order_id_,use_in_course_)
  58. VALUES
  59. <foreach collection="list" item="item" separator=",">
  60. (#{item.id},#{item.musicGroupPaymentCalenderId},#{item.userId},#{item.expectAmount},
  61. #{item.actualAmount},#{item.paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{item.userStatus},#{item.payTime},
  62. #{item.updateTime},#{item.createTime},#{item.startPaymentDate},#{item.deadlinePaymentDate},#{item.paymentOrderId},#{item.useInCourse})
  63. </foreach>
  64. </insert>
  65. <!-- 根据主键查询一条记录 -->
  66. <update id="update"
  67. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail">
  68. UPDATE music_group_payment_calender_detail
  69. <set>
  70. <if test="startPaymentDate != null">
  71. start_payment_date_ = #{startPaymentDate},
  72. </if>
  73. <if test="deadlinePaymentDate != null">
  74. deadline_payment_date_ = #{deadlinePaymentDate},
  75. </if>
  76. <if test="open != null">
  77. open_ = #{open},
  78. </if>
  79. <if test="userId != null">
  80. user_id_ = #{userId},
  81. </if>
  82. <if test="userStatus != null">
  83. user_status_ = #{userStatus},
  84. </if>
  85. <if test="paymentStatus != null">
  86. payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  87. </if>
  88. <if test="expectAmount != null">
  89. expect_amount_ = #{expectAmount},
  90. </if>
  91. <if test="updateTime != null">
  92. update_time_ = #{updateTime},
  93. </if>
  94. <if test="musicGroupPaymentCalenderId != null">
  95. music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId},
  96. </if>
  97. <if test="actualAmount != null">
  98. actual_amount_ = #{actualAmount},
  99. </if>
  100. <if test="payTime != null">
  101. pay_time_ = #{payTime},
  102. </if>
  103. <if test="paymentOrderId != null">
  104. payment_order_id_ = #{paymentOrderId},
  105. </if>
  106. <if test="useInCourse != null">
  107. use_in_course_ = #{useInCourse},
  108. </if>
  109. </set>
  110. WHERE id_ = #{id}
  111. </update>
  112. <update id="batchUpdate">
  113. <foreach collection="calenderDetails" item="item" index="index" open="" close="" separator=";">
  114. UPDATE music_group_payment_calender_detail
  115. <set>
  116. <if test="item.startPaymentDate != null">
  117. start_payment_date_ = #{item.startPaymentDate},
  118. </if>
  119. <if test="item.deadlinePaymentDate != null">
  120. deadline_payment_date_ = #{item.deadlinePaymentDate},
  121. </if>
  122. <if test="item.open != null">
  123. open_ = #{item.open},
  124. </if>
  125. <if test="item.userId != null">
  126. user_id_ = #{item.userId},
  127. </if>
  128. <if test="item.userStatus != null">
  129. user_status_ = #{item.userStatus},
  130. </if>
  131. <if test="item.paymentStatus != null">
  132. payment_status_ = #{item.paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  133. </if>
  134. <if test="item.expectAmount != null">
  135. expect_amount_ = #{item.expectAmount},
  136. </if>
  137. <if test="item.updateTime != null">
  138. update_time_ = #{item.updateTime},
  139. </if>
  140. <if test="item.musicGroupPaymentCalenderId != null">
  141. music_group_payment_calender_id_ = #{item.musicGroupPaymentCalenderId},
  142. </if>
  143. <if test="item.actualAmount != null">
  144. actual_amount_ = #{item.actualAmount},
  145. </if>
  146. <if test="item.payTime != null">
  147. pay_time_ = #{item.payTime},
  148. </if>
  149. <if test="item.paymentOrderId != null">
  150. payment_order_id_ = #{item.paymentOrderId},
  151. </if>
  152. <if test="item.useInCourse != null">
  153. use_in_course_ = #{item.useInCourse},
  154. </if>
  155. </set>
  156. WHERE id_ = #{item.id}
  157. </foreach>
  158. </update>
  159. <update id="refreshUserMusicGroupPaymentStatusTask">
  160. UPDATE music_group_payment_calender_detail mgpcd
  161. SET mgpcd.open_ = 0,mgpcd.start_payment_date_ = NULL,mgpcd.deadline_payment_date_ = NULL
  162. WHERE mgpcd.deadline_payment_date_ &lt; DATE_FORMAT(NOW(),'%Y-%m-%d')
  163. </update>
  164. <!-- 根据主键删除一条记录 -->
  165. <delete id="delete">
  166. DELETE FROM music_group_payment_calender_detail WHERE id_ = #{id}
  167. </delete>
  168. <delete id="batchDel">
  169. DELETE FROM music_group_payment_calender_detail WHERE FIND_IN_SET(id_,#{musicGroupPaymentCalenderIds})
  170. </delete>
  171. <delete id="deleteByUserIdAndMusicGroupId">
  172. DELETE FROM music_group_payment_calender_detail
  173. WHERE music_group_payment_calender_id_ IN (SELECT mgpc.id_ FROM music_group_payment_calender mgpc
  174. WHERE mgpc.music_group_id_ = #{musicGroupId} AND mgpc.status_ IN ('NO','OPEN'))
  175. AND user_id_ = #{userId} AND payment_status_ = 'NON_PAYMENT'
  176. </delete>
  177. <delete id="deleteByCalenderId">
  178. DELETE FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{id}
  179. </delete>
  180. <!-- 分页查询 -->
  181. <select id="queryPage" resultMap="MusicGroupPaymentCalenderDetail" parameterType="map">
  182. SELECT mgpcd.*,su.username_,su.phone_,st.name_ subject_names_,sr.music_group_status_,
  183. CASE WHEN mgpcd.start_payment_date_ IS NULL THEN mgpc.start_payment_date_ ELSE mgpcd.start_payment_date_ END start_payment_date_mgpc_,
  184. CASE WHEN mgpcd.deadline_payment_date_ IS NULL THEN mgpc.deadline_payment_date_ ELSE mgpcd.deadline_payment_date_ END deadline_payment_date_mgpc_
  185. FROM music_group_payment_calender_detail mgpcd
  186. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  187. LEFT JOIN student_registration sr ON sr.user_id_ = mgpcd.user_id_
  188. LEFT JOIN `subject` st ON st.id_ = sr.actual_subject_id_
  189. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  190. <where>
  191. mgpc.music_group_id_ = sr.music_group_id_
  192. <if test="search != null and search != ''">
  193. AND (mgpcd.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  194. </if>
  195. <if test="id != null">
  196. AND mgpcd.music_group_payment_calender_id_ = #{id}
  197. </if>
  198. <if test="paymentStatus != null and paymentStatus != ''">
  199. AND mgpcd.payment_status_ = #{paymentStatus}
  200. </if>
  201. <if test="musicGroupStatus != null and musicGroupStatus != ''">
  202. AND sr.music_group_status_ = #{musicGroupStatus}
  203. </if>
  204. <if test="subjectId != null">
  205. AND #{subjectId} = sr.actual_subject_id_
  206. </if>
  207. </where>
  208. ORDER BY mgpc.update_time_ DESC
  209. <include refid="global.limit" />
  210. </select>
  211. <!-- 查询当前表的总记录数 -->
  212. <select id="queryCount" resultType="int">
  213. SELECT COUNT(DISTINCT mgpcd.id_) FROM music_group_payment_calender_detail mgpcd
  214. LEFT JOIN student_registration sr ON sr.user_id_ = mgpcd.user_id_
  215. LEFT JOIN `subject` st ON st.id_ = sr.actual_subject_id_
  216. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  217. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  218. <where>
  219. mgpc.music_group_id_ = sr.music_group_id_
  220. <if test="search != null and search != ''">
  221. AND (mgpcd.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  222. </if>
  223. <if test="id != null">
  224. AND mgpcd.music_group_payment_calender_id_ = #{id}
  225. </if>
  226. <if test="subjectId != null">
  227. AND #{subjectId} = sr.actual_subject_id_
  228. </if>
  229. <if test="paymentStatus != null and paymentStatus != ''">
  230. AND mgpcd.payment_status_ = #{paymentStatus}
  231. </if>
  232. <if test="musicGroupStatus != null and musicGroupStatus != ''">
  233. AND sr.music_group_status_ = #{musicGroupStatus}
  234. </if>
  235. </where>
  236. </select>
  237. <select id="queryListByIds" resultMap="MusicGroupPaymentCalenderDetail">
  238. SELECT mgpcd.*,mgpc.music_group_id_ FROM music_group_payment_calender_detail mgpcd
  239. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  240. WHERE FIND_IN_SET(mgpcd.id_,#{ids})
  241. GROUP BY mgpcd.id_
  242. </select>
  243. <select id="queryByCalenderId" resultMap="MusicGroupPaymentCalenderDetail">
  244. SELECT * FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId}
  245. <if test="paymentStatus != null">
  246. AND payment_status_ = #{paymentStatus}
  247. </if>
  248. </select>
  249. <select id="findMusicGroupStudentWithSubject" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  250. SELECT DISTINCT su.id_ userId,su.username_ userName, su.avatar_ avatar, su.phone_ phone
  251. from music_group_student_fee_ mgstf
  252. LEFT JOIN sys_user su ON su.id_=mgstf.user_id_
  253. WHERE mgstf.music_group_id_=#{musicGroupId}
  254. AND mgstf.subject_id_=#{subjectId}
  255. AND mgstf.remain_network_class_times_>0
  256. ORDER BY su.id_
  257. </select>
  258. <select id="getUserLastCalenderDetail" resultMap="MusicGroupPaymentCalenderDetail">
  259. SELECT * FROM music_group_payment_calender_detail mgpcd
  260. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  261. WHERE mgpc.music_group_id_=#{musicGroupId} AND mgpcd.user_id_=#{userId} AND mgpcd.payment_status_ = 'NON_PAYMENT'
  262. AND (mgpc.status_ = 'OPEN' OR mgpcd.open_ = 1)
  263. ORDER BY mgpc.start_payment_date_ DESC LIMIT 1
  264. </select>
  265. <select id="queryCanOpenList" resultMap="MusicGroupPaymentCalenderDetail">
  266. SELECT * FROM music_group_payment_calender_detail
  267. WHERE FIND_IN_SET(id_,#{ids}) AND payment_status_ = 'NON_PAYMENT'
  268. </select>
  269. <select id="queryIntersectionByPaymentDate" resultType="java.lang.Integer">
  270. SELECT COUNT(mgpcd.id_) FROM music_group_payment_calender_detail mgpcd
  271. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  272. WHERE mgpc.music_group_id_ = #{musicGroupId} AND mgpcd.user_id_ = #{userId}
  273. AND mgpcd.open_ = 1
  274. </select>
  275. <select id="queryCanPushList" resultMap="MusicGroupPaymentCalenderDetail">
  276. SELECT mgpcd.*,mgpc.music_group_id_ FROM music_group_payment_calender_detail mgpcd
  277. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  278. LEFT JOIN student_registration sr ON sr.music_group_id_ = mgpc.music_group_id_
  279. WHERE mgpcd.payment_status_ = 'NON_PAYMENT' AND sr.music_group_status_ != 'QUIT' AND mgpc.id_ = #{musicGroupPaymentCalenderId}
  280. GROUP BY mgpcd.id_
  281. </select>
  282. <select id="queryNoPaymentCanPushList" resultMap="MusicGroupPaymentCalenderDetail">
  283. SELECT mgpcd.*,mgpc.music_group_id_ FROM music_group_payment_calender mgpc
  284. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  285. 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'
  286. </select>
  287. <select id="queryPaymentPushMap" resultType="java.util.Map">
  288. SELECT mgpcd.user_id_ 'key',mgpc.music_group_id_ 'value' FROM music_group_payment_calender mgpc
  289. LEFT JOIN music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  290. 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'
  291. </select>
  292. <select id="queryStudentIds" resultType="java.lang.Integer">
  293. SELECT user_id_ FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId}
  294. </select>
  295. <select id="countOpenPayment" resultType="java.lang.Integer">
  296. SELECT COUNT(DISTINCT mgpcd.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 mgpcd.user_id_ = #{userId} AND mgpc.music_group_id_ = #{musicGroupId} AND (mgpc.status_ = 'OPEN' OR mgpcd.open_ = 1)
  299. AND mgpcd.payment_status_ != 'PAID_COMPLETED'
  300. </select>
  301. <select id="getCalenderDetailWithCalender" resultMap="MusicGroupPaymentCalenderDetail">
  302. SELECT
  303. mgpcd.*
  304. FROM
  305. music_group_payment_calender_detail mgpcd
  306. WHERE
  307. mgpcd.music_group_payment_calender_id_ = #{calenderId}
  308. </select>
  309. <select id="getUnusedPaymentCalenderWithMusicGroup" resultMap="MusicGroupPaymentCalenderDetail">
  310. SELECT
  311. mgpcd.*
  312. FROM
  313. music_group_payment_calender_detail mgpcd
  314. LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
  315. WHERE
  316. mgpc.music_group_id_ = #{musicGroupId}
  317. AND NOT EXISTS ( SELECT id_ FROM course_schedule_student_payment WHERE batch_no_ = mgpcd.music_group_payment_calender_id_ AND music_group_id_ = #{musicGroupId} )
  318. </select>
  319. <select id="getWithCalenderIds" resultMap="MusicGroupPaymentCalenderDetail">
  320. SELECT
  321. mgpcd.*
  322. FROM
  323. music_group_payment_calender_detail mgpcd
  324. WHERE
  325. mgpcd.music_group_payment_calender_id_ IN
  326. <foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
  327. #{calenderId}
  328. </foreach>
  329. </select>
  330. <resultMap id="SimpleUserDtoMap" type="com.ym.mec.biz.dal.dto.SimpleUserDto">
  331. <result property="userName" column="username_"/>
  332. <result property="userId" column="id_"/>
  333. <result property="subjectNames" column="subject_name_"/>
  334. <result property="actualAmount" column="actual_amount_"/>
  335. </resultMap>
  336. <select id="querySimpleUserDto" resultMap="SimpleUserDtoMap">
  337. SELECT su.id_,su.username_,s.name_ subject_name_,mgpcd.actual_amount_
  338. FROM music_group_payment_calender_detail mgpcd
  339. LEFT JOIN sys_user su ON su.id_ = mgpcd.user_id_
  340. LEFT JOIN student_registration sr ON sr.user_id_ = mgpcd.user_id_ AND sr.music_group_status_ != 'QUIT' AND sr.music_group_id_ = #{musicGroupId}
  341. LEFT JOIN `subject` s ON s.id_ = sr.subject_id_
  342. WHERE mgpcd.music_group_payment_calender_id_ = #{calenderId}
  343. </select>
  344. <select id="sumActualAmount" resultType="java.math.BigDecimal">
  345. SELECT SUM(mgpcd.actual_amount_) FROM music_group_payment_calender_detail mgpcd
  346. WHERE mgpcd.music_group_payment_calender_id_ = #{id}
  347. </select>
  348. <select id="findByCalenderIdAndUserId" resultMap="MusicGroupPaymentCalenderDetail">
  349. SELECT * FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId} AND user_id_ = #{userId} LIMIT 1
  350. </select>
  351. <select id="findByOrderId" resultMap="MusicGroupPaymentCalenderDetail">
  352. SELECT * FROM music_group_payment_calender_detail WHERE payment_order_id_ = #{orderId} LIMIT 1
  353. </select>
  354. </mapper>