MusicGroupPaymentStudentCourseDetailMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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.MusicGroupPaymentStudentCourseDetailDao">
  5. <resultMap
  6. type="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail"
  7. id="MusicGroupPaymentStudentCourseDetail">
  8. <result column="id_" property="id"/>
  9. <result column="music_group_payment_calender_id_" property="musicGroupPaymentCalenderId"/>
  10. <result column="music_group_payment_calender_detail_id_"
  11. property="musicGroupPaymentCalenderDetailId"/>
  12. <result column="user_id_" property="userId"/>
  13. <result column="course_type_" property="courseType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  14. <result column="course_original_price_" property="courseOriginalPrice"/>
  15. <result column="course_current_price_" property="courseCurrentPrice"/>
  16. <result column="total_course_minutes_" property="totalCourseMinutes"/>
  17. <result column="used_course_minutes_" property="usedCourseMinutes"/>
  18. <result column="create_time_" property="createTime"/>
  19. <result column="update_time_" property="updateTime"/>
  20. </resultMap>
  21. <!-- 根据主键查询一条记录 -->
  22. <select id="get" resultMap="MusicGroupPaymentStudentCourseDetail">
  23. SELECT *
  24. FROM music_group_payment_student_course_detail
  25. WHERE id_ = #{id}
  26. </select>
  27. <!-- 全查询 -->
  28. <select id="findAll" resultMap="MusicGroupPaymentStudentCourseDetail">
  29. SELECT *
  30. FROM music_group_payment_student_course_detail
  31. ORDER BY id_
  32. </select>
  33. <!-- 向数据库增加一条记录 -->
  34. <insert id="insert"
  35. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail"
  36. useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  37. INSERT INTO music_group_payment_student_course_detail
  38. (music_group_payment_calender_id_,music_group_payment_calender_detail_id_,user_id_,course_type_,
  39. total_course_minutes_,used_course_minutes_,create_time_,update_time_,course_original_price_,course_current_price_)
  40. VALUES(#{musicGroupPaymentCalenderId},#{musicGroupPaymentCalenderDetailId},#{userId},
  41. #{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{totalCourseMinutes},#{usedCourseMinutes},
  42. NOW(),NOW(),#{courseOriginalPrice},#{courseCurrentPrice})
  43. </insert>
  44. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
  45. keyProperty="id">
  46. INSERT INTO music_group_payment_student_course_detail
  47. (music_group_payment_calender_id_,music_group_payment_calender_detail_id_,user_id_,
  48. course_type_,total_course_minutes_,used_course_minutes_,create_time_,update_time_,course_original_price_,course_current_price_)
  49. VALUES
  50. <foreach collection="list" item="item" separator=",">
  51. (#{item.musicGroupPaymentCalenderId},#{item.musicGroupPaymentCalenderDetailId},
  52. #{item.userId},#{item.courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  53. #{item.totalCourseMinutes},#{item.usedCourseMinutes},NOW(),NOW(),#{item.courseOriginalPrice},#{item.courseCurrentPrice})
  54. </foreach>
  55. </insert>
  56. <!-- 根据主键查询一条记录 -->
  57. <update id="update"
  58. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail">
  59. UPDATE music_group_payment_student_course_detail
  60. <set>
  61. <if test="courseOriginalPrice != null">
  62. course_original_price_ = #{courseOriginalPrice},
  63. </if>
  64. <if test="courseCurrentPrice != null">
  65. course_current_price_ = #{courseCurrentPrice},
  66. </if>
  67. <if test="usedCourseMinutes != null">
  68. used_course_minutes_ = #{usedCourseMinutes},
  69. </if>
  70. <if test="totalCourseMinutes != null">
  71. total_course_minutes_ = #{totalCourseMinutes},
  72. </if>
  73. <if test="userId != null">
  74. user_id_ = #{userId},
  75. </if>
  76. <if test="musicGroupPaymentCalenderDetailId != null">
  77. music_group_payment_calender_detail_id_ = #{musicGroupPaymentCalenderDetailId},
  78. </if>
  79. <if test="musicGroupPaymentCalenderId != null">
  80. music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId},
  81. </if>
  82. <if test="courseType != null">
  83. course_type_ = #{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  84. </if>
  85. update_time_ = NOW()
  86. </set>
  87. WHERE id_ = #{id}
  88. </update>
  89. <update id="batchUpdate"
  90. parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail">
  91. <foreach collection="paymentCourseDetails" item="paymentCourseDetail" separator=";">
  92. UPDATE music_group_payment_student_course_detail
  93. <set>
  94. <if test="paymentCourseDetail.courseOriginalPrice != null">
  95. course_original_price_ = #{paymentCourseDetail.courseOriginalPrice},
  96. </if>
  97. <if test="paymentCourseDetail.courseCurrentPrice != null">
  98. course_current_price_ = #{paymentCourseDetail.courseCurrentPrice},
  99. </if>
  100. <if test="paymentCourseDetail.usedCourseMinutes != null">
  101. used_course_minutes_ = #{paymentCourseDetail.usedCourseMinutes},
  102. </if>
  103. <if test="paymentCourseDetail.totalCourseMinutes != null">
  104. total_course_minutes_ = #{paymentCourseDetail.totalCourseMinutes},
  105. </if>
  106. <if test="paymentCourseDetail.userId != null">
  107. user_id_ = #{paymentCourseDetail.userId},
  108. </if>
  109. <if test="paymentCourseDetail.musicGroupPaymentCalenderDetailId != null">
  110. music_group_payment_calender_detail_id_ = #{paymentCourseDetail.musicGroupPaymentCalenderDetailId},
  111. </if>
  112. <if test="paymentCourseDetail.musicGroupPaymentCalenderId != null">
  113. music_group_payment_calender_id_ = #{paymentCourseDetail.musicGroupPaymentCalenderId},
  114. </if>
  115. <if test="paymentCourseDetail.courseType != null">
  116. course_type_ = #{paymentCourseDetail.courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  117. </if>
  118. update_time_ = NOW()
  119. </set>
  120. WHERE id_ = #{paymentCourseDetail.id}
  121. </foreach>
  122. </update>
  123. <update id="updateByCourseType">
  124. UPDATE music_group_payment_student_course_detail
  125. SET course_current_price_ = #{courseCurrentPrice},update_time_ = NOW()
  126. WHERE course_type_ = #{courseType} AND FIND_IN_SET(music_group_payment_calender_detail_id_,#{musicGroupPaymentCalenderIds})
  127. </update>
  128. <!-- 根据主键删除一条记录 -->
  129. <delete id="delete">
  130. DELETE
  131. FROM music_group_payment_student_course_detail
  132. WHERE id_ = #{id}
  133. </delete>
  134. <!-- 根据主键删除一条记录 -->
  135. <delete id="deleteByMusicGroupPaymentCalenderId">
  136. DELETE FROM music_group_payment_student_course_detail
  137. WHERE music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId}
  138. </delete>
  139. <delete id="deleteByMusicGroupPaymentCalenderDetailId">
  140. DELETE FROM music_group_payment_student_course_detail
  141. <where>
  142. music_group_payment_calender_detail_id_ in
  143. <foreach item="item" collection="list" separator="," open="(" close=")" index="">
  144. #{item}
  145. </foreach>
  146. </where>
  147. </delete>
  148. <!-- 分页查询 -->
  149. <select id="queryByMusicGroupPaymentStudentCourseDetailId" resultMap="MusicGroupPaymentStudentCourseDetail"
  150. parameterType="map">
  151. SELECT * FROM music_group_payment_student_course_detail
  152. <where>
  153. music_group_payment_calender_detail_id_ in
  154. <foreach item="item" collection="list" separator="," open="(" close=")" index="">
  155. #{item}
  156. </foreach>
  157. </where>
  158. </select>
  159. <!-- 分页查询 -->
  160. <select id="queryPage" resultMap="MusicGroupPaymentStudentCourseDetail"
  161. parameterType="map">
  162. SELECT * FROM music_group_payment_student_course_detail ORDER BY id_
  163. <include refid="global.limit"/>
  164. </select>
  165. <!-- 查询当前表的总记录数 -->
  166. <select id="queryCount" resultType="int">
  167. SELECT COUNT(*)
  168. FROM music_group_payment_student_course_detail
  169. </select>
  170. <select id="getUnUseWithStudentAndCourseTypeAndCourseMinutes" resultMap="MusicGroupPaymentStudentCourseDetail">
  171. SELECT mgpscd.*
  172. FROM music_group_payment_student_course_detail mgpscd
  173. LEFT JOIN music_group_payment_calender mgpc ON mgpscd.music_group_payment_calender_id_ = mgpc.id_
  174. WHERE
  175. FIND_IN_SET(mgpc.batch_no_,#{batchNo})
  176. AND mgpscd.user_id_ = #{studentId}
  177. AND mgpscd.course_type_ = #{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  178. AND mgpscd.used_course_minutes_ &lt;= 0
  179. ORDER BY mgpscd.id_;
  180. </select>
  181. <select id="getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes" resultType="string">
  182. SELECT
  183. mgpc.batch_no_
  184. FROM music_group_payment_calender mgpc
  185. LEFT JOIN music_group_payment_student_course_detail mgpscd ON mgpscd.music_group_payment_calender_id_ = mgpc.id_
  186. WHERE
  187. mgpc.music_group_id_ = #{musicGroupId}
  188. <if test="studentId != null">
  189. AND mgpscd.user_id_ = #{studentId}
  190. </if>
  191. <if test="batchNos != null">
  192. AND mgpc.batch_no_ NOT IN
  193. <foreach collection="batchNos" item="item" open="(" close=")" separator=",">
  194. #{item}
  195. </foreach>
  196. </if>
  197. <if test="courseType != null">
  198. AND mgpscd.course_type_ = #{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  199. </if>
  200. GROUP BY mgpc.batch_no_ HAVING min(mgpscd.used_course_minutes_) &lt;=0 ORDER BY MIN(mgpc.id_) LIMIT 1;
  201. </select>
  202. <select id="getUnUseWithStudents" resultMap="MusicGroupPaymentStudentCourseDetail">
  203. SELECT
  204. MIN(mgpscd.id_) id_,
  205. MIN(mgpscd.music_group_payment_calender_id_) music_group_payment_calender_id_,
  206. mgpscd.user_id_,
  207. mgpscd.course_type_,
  208. SUM(mgpscd.total_course_minutes_) total_course_minutes_,
  209. SUM(mgpscd.used_course_minutes_) used_course_minutes_
  210. FROM music_group_payment_student_course_detail mgpscd
  211. LEFT JOIN music_group_payment_calender mgpc ON mgpscd.music_group_payment_calender_id_ = mgpc.id_
  212. WHERE mgpc.music_group_id_ = #{musicGroupId}
  213. AND user_id_ IN
  214. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  215. #{studentId}
  216. </foreach>
  217. GROUP BY mgpscd.user_id_,mgpscd.course_type_,mgpc.batch_no_
  218. HAVING used_course_minutes_ &lt;= 0
  219. </select>
  220. <delete id="deleteByUserIdAndMusicGroupId">
  221. DELETE
  222. FROM music_group_payment_student_course_detail
  223. WHERE user_id_ = #{userId}
  224. AND music_group_payment_calender_id_ IN (
  225. SELECT id_
  226. FROM music_group_payment_calender
  227. WHERE music_group_id_ = #{musicGroupId}
  228. )
  229. </delete>
  230. <resultMap id="StudentSubTotalCourseTimesDto" type="com.ym.mec.biz.dal.dto.StudentSubTotalCourseTimesDto">
  231. <result property="userId" column="user_id_"/>
  232. <result property="username" column="username_"/>
  233. <result property="phone" column="phone_"/>
  234. <collection property="mapDtos" ofType="com.ym.mec.biz.dal.dto.MapDto">
  235. <result property="key" column="key"/>
  236. <result property="value" column="value"/>
  237. </collection>
  238. </resultMap>
  239. <select id="queryStudentSubTotalCourseTimes" resultMap="StudentSubTotalCourseTimesDto">
  240. SELECT mgpscd.user_id_,su.username_,su.phone_,mgpscd.course_type_ 'key',
  241. SUM(CASE WHEN mgpscd.used_course_minutes_ = 0 THEN mgpscd.total_course_minutes_ ELSE 0 END) 'value'
  242. FROM music_group_payment_student_course_detail mgpscd
  243. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpscd.music_group_payment_calender_id_
  244. LEFT JOIN class_group_student_mapper cgsm ON cgsm.music_group_id_ = mgpc.music_group_id_ AND cgsm.status_ = 'NORMAL'
  245. LEFT JOIN sys_user su ON su.id_ = mgpscd.user_id_
  246. WHERE mgpc.music_group_id_ = #{musicGroupId}
  247. <if test="classGroupId != null">
  248. AND cgsm.class_group_id_ = #{classGroupId}
  249. </if>
  250. GROUP BY mgpscd.user_id_,mgpscd.course_type_
  251. </select>
  252. <select id="findByCalenderAndUserId" resultMap="MusicGroupPaymentStudentCourseDetail">
  253. SELECT * FROM music_group_payment_student_course_detail WHERE music_group_payment_calender_id_ = #{calenderId}
  254. <if test="userId != null">
  255. AND user_id_ = #{userId}
  256. </if>
  257. </select>
  258. </mapper>