MusicGroupPaymentCalenderDetailMapper.xml 14 KB

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