Browse Source

Merge remote-tracking branch 'origin/master'

Joburgess 5 years ago
parent
commit
492476f6ad

+ 7 - 6
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentCalenderCourseSettingsDao.java

@@ -19,15 +19,15 @@ public interface MusicGroupPaymentCalenderCourseSettingsDao extends BaseDAO<Inte
 	List<MusicGroupPaymentCalenderCourseSettings> getWithPaymentCalender(@Param("calenderId") Long calenderId);
 
 	/**
-	 * @describe 根据缴费日历和课程类型获取课程价格设置
-	 * @author Joburgess
-	 * @date 2020.11.04
 	 * @param calenderId:
 	 * @param courseType:
 	 * @return com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings
+	 * @describe 根据缴费日历和课程类型获取课程价格设置
+	 * @author Joburgess
+	 * @date 2020.11.04
 	 */
 	MusicGroupPaymentCalenderCourseSettings getWithPaymentCalenderAndCourseType(@Param("calenderId") Long calenderId,
-																				@Param("courseType")CourseSchedule.CourseScheduleType courseType);
+																				@Param("courseType") CourseSchedule.CourseScheduleType courseType);
 
 	int deleteByMusicGroupPaymentCalenderId(Long musicGroupPaymentCalenderId);
 
@@ -49,19 +49,20 @@ public interface MusicGroupPaymentCalenderCourseSettingsDao extends BaseDAO<Inte
 
 	/**
 	 * 批量新增
+	 *
 	 * @param musicGroupPaymentCalenderCourseSettingsList
 	 * @return
 	 */
 	int batchInsert(List<MusicGroupPaymentCalenderCourseSettings> musicGroupPaymentCalenderCourseSettingsList);
 
 	/**
+	 * @param calenderId:
+	 * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings>
 	 * @describe 获取收费标准
 	 * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
 	 * @author zouxuan
 	 * @date 2020/10/30
 	 * @time 16:04
-	 * @param calenderId:
-	 * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings>
 	 */
 	List<MusicGroupPaymentCalenderCourseSettings> queryCalenderCourseSettings(Long calenderId);
 }

+ 16 - 8
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentStudentCourseDetailDao.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.dal.dao;
 
 import com.ym.mec.biz.dal.entity.CourseSchedule;
+
 import java.util.List;
 
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail;
@@ -10,27 +11,34 @@ import org.apache.ibatis.annotations.Param;
 public interface MusicGroupPaymentStudentCourseDetailDao extends BaseDAO<Long, MusicGroupPaymentStudentCourseDetail> {
 
     /**
-     * @describe 获取指定学员,指定课程,指定课程时长下的可用缴费记录
-     * @author Joburgess
-     * @date 2020.11.04
      * @param studentId:
      * @param courseType:
      * @param courseMinutes:
      * @return com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail
+     * @describe 获取指定学员,指定课程,指定课程时长下的可用缴费记录
+     * @author Joburgess
+     * @date 2020.11.04
      */
     MusicGroupPaymentStudentCourseDetail getUnUseWithStudentAndCourseTypeAndCourseMinutes(@Param("studentId") Integer studentId,
-                                                                                           @Param("courseType")CourseSchedule.CourseScheduleType courseType,
-                                                                                           @Param("courseMinutes") Integer courseMinutes);
+                                                                                          @Param("courseType") CourseSchedule.CourseScheduleType courseType,
+                                                                                          @Param("courseMinutes") Integer courseMinutes);
 
     /**
+     * @param studentIds:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail>
      * @describe
      * @author Joburgess
      * @date 2020.11.04
-     * @param studentIds:
-     * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail>
      */
     List<MusicGroupPaymentStudentCourseDetail> getUnUseWithStudents(@Param("musicGroupId") String musicGroupId, @Param("studentIds") List<Integer> studentIds);
 
-	int batchInsert(List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetailList);
+    int batchInsert(List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetailList);
 
+    /**
+     * 删除用户购买乐团课程记录
+     * @param userId
+     * @param musicGroupId
+     * @return
+     */
+    int deleteByUserIdAndMusicGroupId(@Param("userId") Integer userId, @Param("musicGroupId") String musicGroupId);
 }

+ 48 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -157,6 +157,10 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
     @Autowired
     private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
+    @Autowired
+    private MusicGroupPaymentStudentCourseDetailDao musicGroupPaymentStudentCourseDetailDao;
+    @Autowired
+    private SubjectChangeDao subjectChangeDao;
 
     private SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -447,7 +451,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         //乐器及打包辅件
         List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
         if (studentRegistration.getTemporaryCourseFee() != null) {
-            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(),studentRegistration.getMusicGroupId(), DealStatusEnum.WAIT_PAY);
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), studentRegistration.getMusicGroupId(), DealStatusEnum.WAIT_PAY);
             for (StudentPaymentOrderDetail orderDetail : orderDetails) {
                 if (orderDetail == null || orderDetail.getPrice() == null || orderDetail.getGoodsIdList() == null) {
                     continue;
@@ -665,7 +669,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         //乐器及打包辅件
         List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
         if (studentRegistration.getTemporaryCourseFee() != null) {
-            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(),studentRegistration.getMusicGroupId(), DealStatusEnum.WAIT_PAY);
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), studentRegistration.getMusicGroupId(), DealStatusEnum.WAIT_PAY);
             for (StudentPaymentOrderDetail orderDetail : orderDetails) {
                 if (orderDetail == null || orderDetail.getPrice() == null || orderDetail.getGoodsIdList() == null) {
                     continue;
@@ -1515,6 +1519,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
             studentRegistrationDao.update(studentRegistration);
 
+            //删除用户购买的课程记录
+            musicGroupPaymentStudentCourseDetailDao.deleteByUserIdAndMusicGroupId(userId, musicGroupId);
+
             BigDecimal amount = new BigDecimal(0);
 
             // 判断乐器是否是租赁
@@ -1529,6 +1536,17 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
             List<StudentPaymentOrderDetail> orderDetailList = studentPaymentOrderDetailDao.findApplyOrderGoods(studentPaymentOrder.getId());
 
+            Set<String> courseTypeSet = new HashSet<>();
+            if (isRefundCourseFee) {
+                List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.getMusicGroupRegCalenderCourseSettings(studentRegistration.getMusicGroupId());
+                courseTypeSet = courseSettings.stream().map(e -> e.getCourseType().getCode()).collect(Collectors.toSet());
+            }
+
+            SubjectChange studentLastChange = null;
+            if (isRefundInstrumentFee || isRefundTeachingAssistantsFee) {
+                studentLastChange = subjectChangeDao.getStudentLastChange(userId, musicGroupId);
+            }
+
             BigDecimal remitFee = studentPaymentOrder.getRemitFee() == null ? BigDecimal.ZERO : studentPaymentOrder.getRemitFee();
             for (StudentPaymentOrderDetail detail : orderDetailList) {
                 if (remitFee.compareTo(detail.getPrice()) >= 0) {
@@ -1541,24 +1559,27 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
                 if (isRefundCourseFee) {
                     // 退课程费用
-                    if (detail.getType() == OrderDetailTypeEnum.COURSE) {
+                    if (courseTypeSet.contains(detail.getType().getCode())) {
                         amount = amount.add(detail.getPrice());
                     }
                 }
-                if (isRefundInstrumentFee) {
+                if (isRefundInstrumentFee && studentLastChange == null) {
                     // 退乐器费用
                     if (detail.getType() == OrderDetailTypeEnum.MUSICAL) {
                         amount = amount.add(detail.getPrice());
                     }
 
                 }
-                if (isRefundTeachingAssistantsFee) {
+                if (isRefundTeachingAssistantsFee && studentLastChange == null) {
                     // 退教辅费用
                     if (detail.getType() == OrderDetailTypeEnum.ACCESSORIES || detail.getType() == OrderDetailTypeEnum.TEACHING) {
                         amount = amount.add(detail.getPrice());
                     }
                 }
             }
+            if (studentLastChange != null) {
+                amount = amount.add(studentLastChange.getChangeMusicalPrice()).add(studentLastChange.getChangeAccessoriesPrice());
+            }
             if (amount.doubleValue() > 0) {
                 // 增加交易流水
                 sysUserCashAccountDetailService.addCashAccountDetail(userId, amount, SysUserCashAccountDetailService.MUSIC_GROUP + musicGroupId, "",
@@ -1618,6 +1639,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
         studentRegistrationDao.update(studentRegistration);
 
+        //删除用户购买的课程记录
+        musicGroupPaymentStudentCourseDetailDao.deleteByUserIdAndMusicGroupId(userId, musicGroupId);
+
         BigDecimal amount = new BigDecimal(0);
 
         // 判断乐器是否是租赁
@@ -1630,6 +1654,18 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
 
         List<StudentPaymentOrderDetail> orderDetailList = studentPaymentOrderDetailDao.findApplyOrderGoods(studentPaymentOrder.getId());
+
+        Set<String> courseTypeSet = new HashSet<>();
+        if (isRefundCourseFee) {
+            List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.getMusicGroupRegCalenderCourseSettings(studentRegistration.getMusicGroupId());
+            courseTypeSet = courseSettings.stream().map(e -> e.getCourseType().getCode()).collect(Collectors.toSet());
+        }
+
+        SubjectChange studentLastChange = null;
+        if (isRefundInstrumentFee || isRefundTeachingAssistantsFee) {
+            studentLastChange = subjectChangeDao.getStudentLastChange(userId, musicGroupId);
+        }
+
         BigDecimal remitFee = studentPaymentOrder.getRemitFee() == null ? BigDecimal.ZERO : studentPaymentOrder.getRemitFee();
 
         for (StudentPaymentOrderDetail detail : orderDetailList) {
@@ -1642,24 +1678,27 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             }
             if (isRefundCourseFee) {
                 // 退课程费用
-                if (detail.getType() == OrderDetailTypeEnum.COURSE) {
+                if (courseTypeSet.contains(detail.getType().getCode())) {
                     amount = amount.add(detail.getPrice());
                 }
             }
-            if (isRefundInstrumentFee) {
+            if (isRefundInstrumentFee && studentLastChange == null) {
                 // 退乐器费用
                 if (detail.getType() == OrderDetailTypeEnum.MUSICAL) {
                     amount = amount.add(detail.getPrice());
                 }
 
             }
-            if (isRefundTeachingAssistantsFee) {
+            if (isRefundTeachingAssistantsFee && studentLastChange == null) {
                 // 退教辅费用
                 if (detail.getType() == OrderDetailTypeEnum.ACCESSORIES || detail.getType() == OrderDetailTypeEnum.TEACHING) {
                     amount = amount.add(detail.getPrice());
                 }
             }
         }
+        if (studentLastChange != null) {
+            amount = amount.add(studentLastChange.getChangeMusicalPrice()).add(studentLastChange.getChangeAccessoriesPrice());
+        }
         if (amount.doubleValue() > 0) {
             // 增加交易流水
             sysUserCashAccountDetailService.addCashAccountDetail(userId, amount, SysUserCashAccountDetailService.MUSIC_GROUP + musicGroupId, "",
@@ -1844,7 +1883,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
             List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.queryCalenderCourseSettings(calenderDetail.getMusicGroupPaymentCalenderId());
             List<StudentPaymentOrderDetail> paymentOrderDetails = new ArrayList<>();
-            courseSettings.forEach(e->{
+            courseSettings.forEach(e -> {
                 StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
                 studentPaymentOrderDetail.setType(OrderDetailTypeEnum.valueOf(e.getCourseType().getCode()));
                 studentPaymentOrderDetail.setPrice(e.getCourseCurrentPrice());

+ 0 - 1
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderCourseSettingsMapper.xml

@@ -125,7 +125,6 @@
 		WHERE mgpc.music_group_id_ = #{musicGroupId}
 		AND mgpc.payment_type_ = 'MUSIC_APPLY'
 		AND mgpc.pay_user_type_='STUDENT'
-		AND mgpc.status_='OPEN'
 	</select>
 
     <select id="getCalenderCourseSettings" resultMap="MusicGroupPaymentCalenderCourseSettings">

+ 127 - 110
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentStudentCourseDetailMapper.xml

@@ -3,124 +3,141 @@
 <!-- 这个文件是自动生成的。 不要修改此文件。所有改动将在下次重新自动生成时丢失。 -->
 <mapper namespace="com.ym.mec.biz.dal.dao.MusicGroupPaymentStudentCourseDetailDao">
 
-	<resultMap
-		type="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail"
-		id="MusicGroupPaymentStudentCourseDetail">
-		<result column="id_" property="id" />
-		<result column="music_group_payment_calender_id_" property="musicGroupPaymentCalenderId" />
-		<result column="music_group_payment_calender_detail_id_"
-			property="musicGroupPaymentCalenderDetailId" />
-		<result column="user_id_" property="userId" />
-		<result column="course_type_" property="courseType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
-		<result column="total_course_minutes_" property="totalCourseMinutes" />
-		<result column="used_course_minutes_" property="usedCourseMinutes" />
-		<result column="create_time_" property="createTime" />
-		<result column="update_time_" property="updateTime" />
-	</resultMap>
+    <resultMap
+            type="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail"
+            id="MusicGroupPaymentStudentCourseDetail">
+        <result column="id_" property="id"/>
+        <result column="music_group_payment_calender_id_" property="musicGroupPaymentCalenderId"/>
+        <result column="music_group_payment_calender_detail_id_"
+                property="musicGroupPaymentCalenderDetailId"/>
+        <result column="user_id_" property="userId"/>
+        <result column="course_type_" property="courseType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+        <result column="total_course_minutes_" property="totalCourseMinutes"/>
+        <result column="used_course_minutes_" property="usedCourseMinutes"/>
+        <result column="create_time_" property="createTime"/>
+        <result column="update_time_" property="updateTime"/>
+    </resultMap>
 
-	<!-- 根据主键查询一条记录 -->
-	<select id="get" resultMap="MusicGroupPaymentStudentCourseDetail">
-		SELECT * FROM music_group_payment_student_course_detail WHERE id_ =
-		#{id}
-	</select>
+    <!-- 根据主键查询一条记录 -->
+    <select id="get" resultMap="MusicGroupPaymentStudentCourseDetail">
+        SELECT *
+        FROM music_group_payment_student_course_detail
+        WHERE id_ =
+              #{id}
+    </select>
 
-	<!-- 全查询 -->
-	<select id="findAll" resultMap="MusicGroupPaymentStudentCourseDetail">
-		SELECT * FROM
-		music_group_payment_student_course_detail ORDER BY id_
-	</select>
+    <!-- 全查询 -->
+    <select id="findAll" resultMap="MusicGroupPaymentStudentCourseDetail">
+        SELECT *
+        FROM music_group_payment_student_course_detail
+        ORDER BY id_
+    </select>
 
-	<!-- 向数据库增加一条记录 -->
-	<insert id="insert"
-		parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail"
-		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
-			AS ID FROM DUAL </selectKey> -->
-		INSERT INTO music_group_payment_student_course_detail
-		(id_,music_group_payment_calender_id_,music_group_payment_calender_detail_id_,user_id_,course_type_,total_course_minutes_,used_course_minutes_,create_time_,update_time_)
-		VALUES(#{id},#{musicGroupPaymentCalenderId},#{musicGroupPaymentCalenderDetailId},#{userId},#{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{totalCourseMinutes},#{usedCourseMinutes},#{createTime},#{updateTime})
-	</insert>
-	
-	<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
+    <!-- 向数据库增加一条记录 -->
+    <insert id="insert"
+            parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail"
+            useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+        <!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval
+            AS ID FROM DUAL </selectKey> -->
+        INSERT INTO music_group_payment_student_course_detail
+        (id_,music_group_payment_calender_id_,music_group_payment_calender_detail_id_,user_id_,course_type_,total_course_minutes_,used_course_minutes_,create_time_,update_time_)
+        VALUES(#{id},#{musicGroupPaymentCalenderId},#{musicGroupPaymentCalenderDetailId},#{userId},#{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{totalCourseMinutes},#{usedCourseMinutes},#{createTime},#{updateTime})
+    </insert>
+
+    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
-		INSERT INTO music_group_payment_student_course_detail
-		(id_,music_group_payment_calender_id_,music_group_payment_calender_detail_id_,user_id_,course_type_,total_course_minutes_,used_course_minutes_,create_time_,update_time_)
-		VALUES
-		<foreach collection="list" item="item" separator=",">
-		(#{item.id},#{item.musicGroupPaymentCalenderId},#{item.musicGroupPaymentCalenderDetailId},#{item.userId},#{item.courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{item.totalCourseMinutes},#{item.usedCourseMinutes},#{item.createTime},#{item.updateTime})
-		</foreach>
-	</insert>
+        INSERT INTO music_group_payment_student_course_detail
+        (id_,music_group_payment_calender_id_,music_group_payment_calender_detail_id_,user_id_,course_type_,total_course_minutes_,used_course_minutes_,create_time_,update_time_)
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (#{item.id},#{item.musicGroupPaymentCalenderId},#{item.musicGroupPaymentCalenderDetailId},#{item.userId},#{item.courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{item.totalCourseMinutes},#{item.usedCourseMinutes},#{item.createTime},#{item.updateTime})
+        </foreach>
+    </insert>
 
-	<!-- 根据主键查询一条记录 -->
-	<update id="update"
-		parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail">
-		UPDATE music_group_payment_student_course_detail
-		<set>
-			<if test="usedCourseMinutes != null">
-				used_course_minutes_ = #{usedCourseMinutes},
-			</if>
-			<if test="totalCourseMinutes != null">
-				total_course_minutes_ = #{totalCourseMinutes},
-			</if>
-			<if test="userId != null">
-				user_id_ = #{userId},
-			</if>
-			<if test="musicGroupPaymentCalenderDetailId != null">
-				music_group_payment_calender_detail_id_ = #{musicGroupPaymentCalenderDetailId},
-			</if>
-			<if test="id != null">
-				id_ = #{id},
-			</if>
-			<if test="updateTime != null">
-				update_time_ = #{updateTime},
-			</if>
-			<if test="musicGroupPaymentCalenderId != null">
-				music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId},
-			</if>
-			<if test="courseType != null">
-				course_type_ = #{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-			</if>
-			<if test="createTime != null">
-				create_time_ = #{createTime},
-			</if>
-		</set>
-		WHERE id_ = #{id}
-	</update>
+    <!-- 根据主键查询一条记录 -->
+    <update id="update"
+            parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail">
+        UPDATE music_group_payment_student_course_detail
+        <set>
+            <if test="usedCourseMinutes != null">
+                used_course_minutes_ = #{usedCourseMinutes},
+            </if>
+            <if test="totalCourseMinutes != null">
+                total_course_minutes_ = #{totalCourseMinutes},
+            </if>
+            <if test="userId != null">
+                user_id_ = #{userId},
+            </if>
+            <if test="musicGroupPaymentCalenderDetailId != null">
+                music_group_payment_calender_detail_id_ = #{musicGroupPaymentCalenderDetailId},
+            </if>
+            <if test="id != null">
+                id_ = #{id},
+            </if>
+            <if test="updateTime != null">
+                update_time_ = #{updateTime},
+            </if>
+            <if test="musicGroupPaymentCalenderId != null">
+                music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId},
+            </if>
+            <if test="courseType != null">
+                course_type_ = #{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+            </if>
+            <if test="createTime != null">
+                create_time_ = #{createTime},
+            </if>
+        </set>
+        WHERE id_ = #{id}
+    </update>
 
-	<!-- 根据主键删除一条记录 -->
-	<delete id="delete">
-		DELETE FROM
-		music_group_payment_student_course_detail WHERE id_ = #{id}
-	</delete>
+    <!-- 根据主键删除一条记录 -->
+    <delete id="delete">
+        DELETE
+        FROM music_group_payment_student_course_detail
+        WHERE id_ = #{id}
+    </delete>
 
-	<!-- 分页查询 -->
-	<select id="queryPage" resultMap="MusicGroupPaymentStudentCourseDetail"
-		parameterType="map">
-		SELECT * FROM music_group_payment_student_course_detail ORDER BY id_
-		<include refid="global.limit" />
-	</select>
+    <!-- 分页查询 -->
+    <select id="queryPage" resultMap="MusicGroupPaymentStudentCourseDetail"
+            parameterType="map">
+        SELECT * FROM music_group_payment_student_course_detail ORDER BY id_
+        <include refid="global.limit"/>
+    </select>
 
-	<!-- 查询当前表的总记录数 -->
-	<select id="queryCount" resultType="int">
-		SELECT COUNT(*) FROM
-		music_group_payment_student_course_detail
-	</select>
+    <!-- 查询当前表的总记录数 -->
+    <select id="queryCount" resultType="int">
+        SELECT COUNT(*)
+        FROM music_group_payment_student_course_detail
+    </select>
     <select id="getUnUseWithStudentAndCourseTypeAndCourseMinutes" resultMap="MusicGroupPaymentStudentCourseDetail">
-		SELECT * FROM music_group_payment_student_course_detail
-		WHERE user_id_=#{studentId}
-		AND course_type_=#{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
-		AND total_course_minutes_ &gt;= #{courseMinutes}
-		AND used_course_minutes_ &lt;= 0
-		ORDER BY id_ DESC LIMIT 1;
-	</select>
+        SELECT *
+        FROM music_group_payment_student_course_detail
+        WHERE user_id_ = #{studentId}
+          AND course_type_ = #{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+          AND total_course_minutes_ &gt;= #{courseMinutes}
+          AND used_course_minutes_ &lt;= 0
+        ORDER BY id_ DESC
+        LIMIT 1;
+    </select>
     <select id="getUnUseWithStudents" resultMap="MusicGroupPaymentStudentCourseDetail">
-		SELECT * FROM music_group_payment_student_course_detail mgpscd
-		LEFT JOIN music_group_payment_calender mgpc ON mgpscd.music_group_payment_calender_id_ = mgpc.id_
-		WHERE used_course_minutes_ &lt;= 0
-		AND mgpc.music_group_id_ = #{musicGroupId}
-		AND user_id_ IN
-		<foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
-			#{studentId}
-		</foreach>
-	</select>
+        SELECT * FROM music_group_payment_student_course_detail mgpscd
+        LEFT JOIN music_group_payment_calender mgpc ON mgpscd.music_group_payment_calender_id_ = mgpc.id_
+        WHERE used_course_minutes_ &lt;= 0
+        AND mgpc.music_group_id_ = #{musicGroupId}
+        AND user_id_ IN
+        <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+            #{studentId}
+        </foreach>
+    </select>
+
+    <delete id="deleteByUserIdAndMusicGroupId">
+        DELETE
+        FROM music_group_payment_student_course_detail
+        WHERE user_id_ = #{userId}
+          AND music_group_payment_calender_id_ IN (
+            SELECT id_
+            FROM music_group_payment_calender
+            WHERE music_group_id_ = #{musicGroupId}
+        )
+    </delete>
 </mapper>