瀏覽代碼

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
周箭河 4 年之前
父節點
當前提交
468ee47bad

+ 18 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleDao.java

@@ -9,6 +9,7 @@ import com.ym.mec.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -1678,6 +1679,15 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
     List<Map<String, Integer>> querySubCourseNumMap(@Param("classGroupId") Integer classGroupId);
 
     /**
+     * 获取班级剩余的课程类型和课程总时长
+     *
+     * @param classGroupId
+     * @return
+     * @author zouxuan
+     */
+    List<Map<String, BigDecimal>> querySubCourseTimeMap(@Param("classGroupId") Integer classGroupId);
+
+    /**
      * 获取所选班级最大剩余课时
      *
      * @param classGroupIds
@@ -1731,4 +1741,12 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
      * @author zouxuan
      */
     int countStudentNoStartCourse(Map<String, Object> params);
+
+    /**
+     * 根据班级编号和课程编号获取课程列表
+     * @param classGroupId
+     * @param allLockCourseIds
+     * @return
+     */
+    List<CourseSchedule> findCoursesByClassGroupIdAndCourseIds(@Param("classGroupId") Long classGroupId, @Param("allLockCourseIds") List<Long> allLockCourseIds);
 }

+ 6 - 4
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderStudentDetail.java

@@ -29,7 +29,7 @@ public class MusicGroupPaymentCalenderStudentDetail {
 	private String courseType;
 	
 	/** 课程时长 */
-	private Long courseTime;
+	private Integer courseTime;
 	
 	/** 班级编号 */
 	private Integer classGroupId;
@@ -99,11 +99,11 @@ public class MusicGroupPaymentCalenderStudentDetail {
 		return this.courseType;
 	}
 
-	public Long getCourseTime() {
+	public Integer getCourseTime() {
 		return courseTime;
 	}
 
-	public void setCourseTime(Long courseTime) {
+	public void setCourseTime(Integer courseTime) {
 		this.courseTime = courseTime;
 	}
 
@@ -143,6 +143,7 @@ public class MusicGroupPaymentCalenderStudentDetail {
 	public String toString() {
 		return "MusicGroupPaymentCalenderStudentDetail{" +
 				"userId=" + userId +
+				", courseOriginalPrice=" + courseOriginalPrice +
 				", courseCurrentPrice=" + courseCurrentPrice +
 				", courseType='" + courseType + '\'' +
 				", classGroupId=" + classGroupId +
@@ -155,6 +156,7 @@ public class MusicGroupPaymentCalenderStudentDetail {
 		if (o == null || getClass() != o.getClass()) return false;
 		MusicGroupPaymentCalenderStudentDetail that = (MusicGroupPaymentCalenderStudentDetail) o;
 		return userId.equals(that.userId) &&
+				courseOriginalPrice.equals(that.courseOriginalPrice) &&
 				courseCurrentPrice.equals(that.courseCurrentPrice) &&
 				courseType.equals(that.courseType) &&
 				classGroupId.equals(that.classGroupId);
@@ -162,6 +164,6 @@ public class MusicGroupPaymentCalenderStudentDetail {
 
 	@Override
 	public int hashCode() {
-		return Objects.hash(userId, courseCurrentPrice, courseType, classGroupId);
+		return Objects.hash(userId, courseOriginalPrice, courseCurrentPrice, courseType, classGroupId);
 	}
 }

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/ClassGroupService.java

@@ -543,5 +543,5 @@ public interface ClassGroupService extends BaseService<Integer, ClassGroup> {
      * @param courseIds
      * @param classGroupStudents
      */
-    void spanGroupClassAdjustPass(Integer masterClassGroupId,List<Integer> studentIds,List<Long> courseIds,List<Map<Integer, String>> classGroupStudents);
+    void spanGroupClassAdjustPass(Integer masterClassGroupId,List<Integer> studentIds,List<Long> courseIds,List<Map<Integer, String>> classGroupStudents,List<Long> allLockCourseIds,String batchNo);
 }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ClassGroupStudentMapperService.java

@@ -89,4 +89,14 @@ public interface ClassGroupStudentMapperService extends BaseService<Long, ClassG
      */
     void updateClassGroupStudents(Long classGroupId, Set<Integer> studentIds);
 
+    /**
+     * @describe 更新班级学员
+     * @author Joburgess
+     * @date 2020.11.04
+     * @param classGroupId:
+     * @param studentIds:
+     * @return void
+     */
+    void updateClassGroupStudents1(Long classGroupId, List<Integer> studentIds,List<Long> allLockCourseIds,String batchNo);
+
 }

+ 23 - 16
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -3494,7 +3494,6 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         if (noRepeatTeacherIds.size() != classGroupTeacherMapperList.size()) {
             throw new BizException("主教与助教存在冲突");
         }
-        //所选班级不能有未开始的临时合并课程
         List<Integer> classGroupIds = mergeClassSplitClassAffirmDto.getClassGroupIds();
         if (classGroupIds == null || classGroupIds.size() == 0) {
             throw new BizException("请填写班级信息");
@@ -3574,9 +3573,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
     }
 
     @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public List<MusicGroupPaymentCalenderStudentDetail> queryStudentPaymentCalenders(Integer masterClassGroupId,List<Map<Integer, String>> classGroupStudents,List<Integer> studentIds) {
-        //获取主班剩余时长
-        Map<String, Long> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseNumMap(masterClassGroupId));
+        //获取主班剩余课程时长
+        Map<String, BigDecimal> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(masterClassGroupId));
         if(masterMap.size() <= 0){
             throw new BizException("所选主班没有剩余课程,请重新选择");
         }
@@ -3611,13 +3611,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
             if (unitPrice == null) {
                 throw new BizException("分部默认课程类型单价不存在,请设置");
             }
-            Long courseTime = masterMap.get(s);
+            BigDecimal courseTime = masterMap.get(s);
             //获取主班剩余课程价值,按分部默认单价计算
-            if(courseTime == 0l){
-                masterTotalPriceMap.put(s,BigDecimal.ZERO);
-            }
             //总价四舍五入取整
-            BigDecimal totalPrice = unitPrice.multiply(new BigDecimal(courseTime)).setScale(0, BigDecimal.ROUND_HALF_UP);
+            BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
             masterTotalPriceMap.put(s,totalPrice);
             //课程余额转移
             for (Integer studentId : studentCLassMap.keySet()) {
@@ -3643,7 +3640,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 //                    bigDecimal = bigDecimal.subtract(totalPrice);
                     surplusCourseFeeMap.put(studentId,bigDecimal.subtract(totalPrice));
                 }
-                calenderDto.setCourseTime(courseTime);
+                calenderDto.setCourseTime(courseTime.intValue());
                 calenderDto.setCourseType(s);
 
                 calenderDto.setPhone(phoneMaps.get(studentId));
@@ -3659,7 +3656,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
     @Override
     public BigDecimal getMasterTotalPrice(Integer masterClassGroupId) {
         //获取主班剩余时长
-        Map<String, Long> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseNumMap(masterClassGroupId));
+        Map<String, BigDecimal> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(masterClassGroupId));
         if(masterMap.size() <= 0){
             throw new BizException("所选主班没有剩余课程,请重新选择");
         }
@@ -3674,10 +3671,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
             if (unitPrice == null) {
                 throw new BizException("分部默认课程类型单价不存在,请设置");
             }
-            Long courseTime = masterMap.get(s);
+            BigDecimal courseTime = masterMap.get(s);
             //获取主班剩余课程价值,按分部默认单价计算
             //总价四舍五入取整
-            BigDecimal totalPrice = unitPrice.multiply(new BigDecimal(courseTime)).setScale(0, BigDecimal.ROUND_HALF_UP);
+            BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
             masterTotalPrice = masterTotalPrice.add(totalPrice);
         }
         return masterTotalPrice;
@@ -3703,6 +3700,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         if(hasStudent){
             throw new BizException("操作失败: 主班包含部分已选学员");
         }
+
         //学员列表
         List<Integer> classGroupIds = mergeClassSplitClassAffirmDto.getClassGroupIds();
         //班级和学员关联
@@ -3754,24 +3752,33 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         musicGroupStudentClassAdjust.setStudentPaymentIds(JSON.toJSONString(studentPaymentIds));
         //获取需要冻结的课程
         classGroupIds.add(masterClassGroupId);
+        //所选班级列表,是否包含已冻结的班级
+        List<ClassGroup> lockClassGroupIds = classGroupDao.findByClassGroupIds(classGroupIds, 1);
+        if (lockClassGroupIds != null && lockClassGroupIds.size() > 0) {
+            throw new BizException("所选班级包含审核中的学员班级调整申请");
+        }
+        //所选班级不能有未开始的临时合并课程
+        int courseNum = courseScheduleDao.findNoStartMasterCourseNum(classGroupIds);
+        if (courseNum > 0) {
+            throw new BizException("所选班级不能有未开始的临时合并课程");
+        }
         List<Long> allLockCourseIds = courseScheduleDao.queryStudentNotStartByClassIdsAndStudentIds(classGroupIds, null);
         musicGroupStudentClassAdjust.setAllLockCourseIds(JSON.toJSONString(allLockCourseIds));
         musicGroupStudentClassAdjustDao.insert(musicGroupStudentClassAdjust);
         //没有需要审核的缴费项目
         if (paymentCalenderDto.getStatus() != AUDITING) {
-            spanGroupClassAdjustPass(masterClassGroupId,studentIds,courseIds,classGroupStudents);
+            spanGroupClassAdjustPass(masterClassGroupId,studentIds,courseIds,classGroupStudents,allLockCourseIds,paymentCalenderDto.getBatchNo());
         }else {
 //                冻结班级
             classGroupDao.batchUpdateLockByClassGroupIds(classGroupIds, 1);
 //                冻结所选班级的课程
             courseScheduleDao.batchUpdateLockByCourseIds(allLockCourseIds, 1);
         }
-        int i = 1/0;
     }
 
-    public void spanGroupClassAdjustPass(Integer masterClassGroupId,List<Integer> studentIds,List<Long> courseIds,List<Map<Integer, String>> classGroupStudents){
+    public void spanGroupClassAdjustPass(Integer masterClassGroupId,List<Integer> studentIds,List<Long> courseIds,List<Map<Integer, String>> classGroupStudents,List<Long> allLockCourseIds,String batchNo){
         //将学员加进班级未开始的课程,以及班级关联、加群
-        classGroupStudentMapperService.updateClassGroupStudents(masterClassGroupId.longValue(),new HashSet<>(studentIds));
+        classGroupStudentMapperService.updateClassGroupStudents1(masterClassGroupId.longValue(),studentIds,allLockCourseIds,batchNo);
         //删除学员课程
         courseScheduleDao.deleteMusicGroupCourseSchedulesWithStudents(courseIds, studentIds);
         //删除班级关联的学员

+ 67 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupStudentMapperServiceImpl.java

@@ -16,6 +16,8 @@ import java.util.stream.Collectors;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.util.collection.MapUtil;
+import com.ym.mec.util.date.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
@@ -72,6 +74,8 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
     @Autowired
     private CourseScheduleDao courseScheduleDao;
     @Autowired
+    private OrganizationCourseUnitPriceSettingsDao organizationCourseUnitPriceSettingsDao;
+    @Autowired
     private ClassGroupDao classGroupDao;
     @Autowired
     private MusicGroupDao musicGroupDao;
@@ -529,4 +533,67 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
             imFeignService.groupJoin(new ImGroupModel(classGroup.getId().toString(), imGroupMembers, classGroup.getName()));
         }
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateClassGroupStudents1(Long classGroupId, List<Integer> studentIds,List<Long> allLockCourseIds,String batchNo) {
+        ClassGroup classGroup = classGroupDao.lockClassGroup(classGroupId.intValue());
+        if (Objects.isNull(classGroup)) {
+            throw new BizException("班级信息错误");
+        }
+        List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
+        //获取冻结的课程列表
+        List<CourseSchedule> classGroupNotStartCourse = courseScheduleDao.findCoursesByClassGroupIdAndCourseIds(classGroupId,allLockCourseIds);
+
+        Date now = new Date();
+        List<ClassGroupStudentMapper> classGroupStudentMappers = new ArrayList<>();
+        //获取分布默认的课程类型单价
+        MusicGroup musicGroup = musicGroupDao.findByClassGroupId(classGroupId.intValue());
+        Map<String, BigDecimal> unitPriceMap = MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(musicGroup.getChargeTypeId(), musicGroup.getOrganId()));
+
+        //生成班级关联
+        for (Integer studentId : studentIds) {
+            ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
+            classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
+            classGroupStudentMapper.setClassGroupId(classGroupId.intValue());
+            classGroupStudentMapper.setUserId(studentId);
+            classGroupStudentMapper.setCreateTime(now);
+            classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+            classGroupStudentMapper.setGroupType(GroupType.MUSIC);
+            classGroupStudentMappers.add(classGroupStudentMapper);
+            //生成课程关联
+            for (CourseSchedule courseSchedule : classGroupNotStartCourse) {
+                //获取课程时长
+                int minutesBetween = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
+                BigDecimal multiply = unitPriceMap.get(courseSchedule.getType().getCode()).multiply(new BigDecimal(minutesBetween));
+                CourseScheduleStudentPayment cssp = new CourseScheduleStudentPayment();
+                cssp.setGroupType(courseSchedule.getGroupType());
+                cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
+                cssp.setCourseScheduleId(courseSchedule.getId());
+                cssp.setClassGroupId(courseSchedule.getClassGroupId());
+                cssp.setBatchNo(batchNo);
+                cssp.setUserId(studentId);
+                cssp.setOriginalPrice(multiply);
+                cssp.setExpectPrice(multiply);
+                cssp.setActualPrice(BigDecimal.ZERO);
+                courseScheduleStudentPayments.add(cssp);
+            }
+        }
+        if (classGroupStudentMappers.size() > 0) {
+            classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
+        }
+        if (courseScheduleStudentPayments.size() > 0) {
+            courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
+        }
+        //修改班级人数
+        classGroupService.updateClassStudentNum(classGroupId.intValue(), classGroup.getStudentNum() + studentIds.size());
+
+        //添加进IM群组
+        List<ImGroupMember> imGroupMemberList = new ArrayList<>();
+        for (Integer studentId : studentIds) {
+            imGroupMemberList.add(new ImGroupMember(studentId.toString()));
+        }
+        ImGroupMember[] imGroupMembers = imGroupMemberList.toArray(new ImGroupMember[imGroupMemberList.size()]);
+        imFeignService.groupJoin(new ImGroupModel(classGroupId.toString(), imGroupMembers, classGroup.getName()));
+    }
 }

+ 4 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -757,8 +757,9 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 				List<Map<Integer,String>> classGroupStudents = (List<Map<Integer,String>>)JSON.parse(adjust.getClassGroupStudents());
 				List<Integer> studentIds = JSON.parseArray(adjust.getStudentIds(), Integer.class);
 				List<Long> courseIds = JSON.parseArray(adjust.getSubLockCourseIds(), Long.class);
+				List<Long> allLockCourseIds = JSON.parseArray(adjust.getAllLockCourseIds(), Long.class);
 				classGroupService.spanGroupClassAdjustPass(adjust.getMasterClassGroupId()
-						,studentIds,courseIds,classGroupStudents);
+						,studentIds,courseIds,classGroupStudents,allLockCourseIds,batchNo);
 			}
 		}
 		return batchNo;
@@ -1071,8 +1072,9 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			List<Map<Integer,String>> classGroupStudents = (List<Map<Integer,String>>)JSON.parse(adjust.getClassGroupStudents());
 			List<Integer> studentIds = JSON.parseArray(adjust.getStudentIds(), Integer.class);
 			List<Long> courseIds = JSON.parseArray(adjust.getSubLockCourseIds(), Long.class);
+			List<Long> allLockCourseIds = JSON.parseArray(adjust.getAllLockCourseIds(), Long.class);
 			classGroupService.spanGroupClassAdjustPass(adjust.getMasterClassGroupId()
-					,studentIds,courseIds,classGroupStudents);
+					,studentIds,courseIds,classGroupStudents,allLockCourseIds,batchNo);
 		}
 		musicGroupPaymentCalenderDao.batchUpdate(musicGroupPaymentCalenders);
 	}

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupSubjectPlanServiceImpl.java

@@ -148,6 +148,11 @@ public class MusicGroupSubjectPlanServiceImpl extends BaseServiceImpl<Integer, M
         boolean flag = false;
         for (int i = 10; i >= 1; i--) {
             MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, subjectId);
+            if(musicOneSubjectClassPlan == null){
+                MusicGroup musicGroup = musicGroupService.get(musicGroupId);
+                Subject subject = subjectService.get(subjectId);
+                throw new BizException("操作失败:{}乐团缺少{}声部",musicGroup.getName(),subject.getName());
+            }
             int applyNum = musicOneSubjectClassPlan.getApplyStudentNum() == null ? 0 : musicOneSubjectClassPlan.getApplyStudentNum();
             musicOneSubjectClassPlan.setApplyStudentNum(applyNum + num);
             musicOneSubjectClassPlan.setUpdateTime(new Date());

+ 34 - 44
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
@@ -658,7 +659,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         }*/
         Date date = new Date();
         String musicGroupId = studentRegistration.getMusicGroupId();
-
+        
         studentRegistration.setCreateTime(date);
         studentRegistration.setUpdateTime(date);
 
@@ -836,25 +837,26 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public void insertStudent(String studentIds, String oldMusicGroupId, String newMusicGroupId, BigDecimal masterTotalPrice) {
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+    public void insertStudent(String studentIds,String oldMusicGroupId,String newMusicGroupId,BigDecimal masterTotalPrice){
         SysUser sysUser1 = sysUserFeignService.queryUserInfo();
         //获取旧乐团学员注册信息
-        List<StudentRegistration> studentRegistrations = studentRegistrationDao.queryByUserIdsAndMusicGroupId(studentIds, oldMusicGroupId);
+        List<StudentRegistration> studentRegistrations = studentRegistrationDao.queryByUserIdsAndMusicGroupId(studentIds,oldMusicGroupId);
         List<StudentCourseFeeDetail> studentCourseFeeDetails = new ArrayList<>();
         BigDecimal amount = BigDecimal.ZERO;
         for (StudentRegistration studentRegistration : studentRegistrations) {
             //记录课程余额消费日志
-            if (studentRegistration.getSurplusCourseFee().doubleValue() > 0d && masterTotalPrice.doubleValue() > 0d) {
+            if(studentRegistration.getSurplusCourseFee().doubleValue() > 0d && masterTotalPrice.doubleValue() > 0d){
                 StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
-                if (studentRegistration.getSurplusCourseFee().doubleValue() > masterTotalPrice.doubleValue()) {
+                if(studentRegistration.getSurplusCourseFee().doubleValue() > masterTotalPrice.doubleValue()){
+                    amount = masterTotalPrice;
                     studentCourseFeeDetail.setAmount(masterTotalPrice.negate());
                     studentCourseFeeDetail.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().subtract(masterTotalPrice));
-                } else {
+                }else {
+                    amount = studentRegistration.getSurplusCourseFee();
                     studentCourseFeeDetail.setAmount(studentRegistration.getSurplusCourseFee().negate());
                     studentCourseFeeDetail.setSurplusCourseFee(BigDecimal.ZERO);
                 }
-                amount = studentCourseFeeDetail.getAmount();
                 studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
                 studentRegistration.setSurplusCourseFee(studentCourseFeeDetail.getSurplusCourseFee());
                 studentCourseFeeDetail.setMemo("跨团合班消费");
@@ -869,35 +871,37 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 //修改剩余课程余额
                 registration.setSurplusCourseFee(registration.getSurplusCourseFee().add(amount));
                 studentRegistrationDao.update(registration);
-            } else {
+            }else {
                 //生成学员乐团注册表
+                studentRegistration.setOrganId(musicGroupDao.get(newMusicGroupId).getOrganId());
                 studentRegistration.setSurplusCourseFee(amount);
                 studentRegistration.setMusicGroupId(newMusicGroupId);
-                studentRegistrationDao.insertBasic(studentRegistration);
+                studentRegistrationDao.insert(studentRegistration);
                 registration = studentRegistration;
+
+                //增加报名学生数
+                musicGroupSubjectPlanService.addApplyStudentNum(newMusicGroupId, studentRegistration.getSubjectId(), 1);
+                //新增Fee表
+                MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(studentRegistration.getUserId(),newMusicGroupId);
+                if(musicGroupStudentFee == null){
+                    musicGroupStudentFee = new MusicGroupStudentFee(newMusicGroupId,
+                            studentRegistration.getUserId(), studentRegistration.getSubjectId(),BigDecimal.ZERO,
+                            null, studentRegistration.getTemporaryCourseFee(), studentRegistration.getPaymentStatus()==YES?PAID_COMPLETED:NON_PAYMENT);
+                    musicGroupStudentFeeDao.insert(musicGroupStudentFee);
+                }
             }
             //主班新增余额日志
-            if (studentRegistration.getSurplusCourseFee().doubleValue() > 0d && masterTotalPrice.doubleValue() > 0d) {
+            if(amount.doubleValue() != 0d && masterTotalPrice.doubleValue() > 0d){
                 StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
                 studentCourseFeeDetail.setAmount(amount);
-                studentCourseFeeDetail.setSurplusCourseFee(registration.getSurplusCourseFee().add(amount));
-                studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
+                studentCourseFeeDetail.setSurplusCourseFee(registration.getSurplusCourseFee());
+                studentCourseFeeDetail.setStudentRegistrationId(registration.getId());
                 studentCourseFeeDetail.setMemo("跨团合班费用转移");
                 studentCourseFeeDetail.setOperator(sysUser1.getId());
                 studentCourseFeeDetails.add(studentCourseFeeDetail);
             }
-            //增加报名学生数
-            musicGroupSubjectPlanService.addApplyStudentNum(newMusicGroupId, studentRegistration.getSubjectId(), 1);
-            //新增Fee表
-            MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(studentRegistration.getUserId(), oldMusicGroupId);
-            if (musicGroupStudentFee == null) {
-                musicGroupStudentFee = new MusicGroupStudentFee(newMusicGroupId,
-                        studentRegistration.getUserId(), studentRegistration.getSubjectId(), BigDecimal.ZERO,
-                        null, studentRegistration.getTemporaryCourseFee(), studentRegistration.getPaymentStatus() == YES ? PAID_COMPLETED : NON_PAYMENT);
-                musicGroupStudentFeeDao.insert(musicGroupStudentFee);
-            }
         }
-        if (studentCourseFeeDetails.size() > 0) {
+        if(studentCourseFeeDetails.size() > 0){
             studentCourseFeeDetailDao.batchInsert(studentCourseFeeDetails);
         }
     }
@@ -1386,7 +1390,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Override
     @Transactional
     public StudentRegistration updateStudent(StudentRegistration studentRegistration) {
-        if (StringUtils.isBlank(studentRegistration.getCertificateType())) {
+        if(StringUtils.isBlank(studentRegistration.getCertificateType())){
             studentRegistration.setCertificateType(CertificateTypeEnum.IDENTITY.getCode());
         }
         StudentRegistration student = get(studentRegistration.getId());
@@ -1398,7 +1402,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         update(student);
         studentRegistrationDao.updateUser(student.getUserId(), student.getParentsName(), student.getIdCardNo(), studentRegistration.getCertificateType());
         // 添加用户电子签章账户
-        if (CertificateTypeEnum.IDENTITY.getCode().equals(studentRegistration.getCertificateType())) {
+        if(CertificateTypeEnum.IDENTITY.getCode().equals(studentRegistration.getCertificateType())){
             contractService.register(student.getUserId(), student.getParentsName(), student.getIdCardNo(), student.getParentsPhone());
         }
         return student;
@@ -1586,22 +1590,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         return amount;
     }
 
-    @Override
-    public List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId) {
-        return studentRegistrationDao.queryStudentMusicGroupInfo(userId);
-    }
-
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Boolean delReg(Long id) {
-        StudentRegistration studentRegistration = studentRegistrationDao.get(id);
-        MusicGroupSubjectPlan subjectPlan = musicGroupSubjectPlanDao.findSubjectPlan(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId());
-        int delNum = studentRegistrationDao.delete(id);
-        subjectPlan.setApplyStudentNum(subjectPlan.getApplyStudentNum() - 1);
-        int updateNum = musicGroupSubjectPlanDao.update(subjectPlan);
-        if (delNum <= 0 || updateNum <= 0) {
-            throw new BizException("删除失败,请重试");
-        }
-        return true;
-    }
+	@Override
+	public List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId) {
+		return studentRegistrationDao.queryStudentMusicGroupInfo(userId);
+	}
 }

+ 14 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -3384,6 +3384,12 @@
         WHERE cs.class_group_id_ = #{classGroupId}
         GROUP BY cs.type_
     </select>
+    <select id="querySubCourseTimeMap" resultType="java.util.Map">
+        SELECT cs.type_ 'key',SUM(ROUND((UNIX_TIMESTAMP(CONCAT(cs.class_date_,' ',cs.end_class_time_)) - UNIX_TIMESTAMP(CONCAT(cs.class_date_,' ',cs.start_class_time_)))/60)) 'value'
+        FROM course_schedule cs
+        WHERE cs.class_group_id_ = #{classGroupId} AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW()
+        GROUP BY cs.type_
+    </select>
     <select id="findClassMaxCourseNumMap" resultType="java.util.Map">
         SELECT c.type_ 'key',MAX(c.subCourseNum) 'value' FROM (SELECT cs.type_,COUNT(cs.id_) subCourseNum FROM course_schedule cs
         WHERE cs.class_group_id_ IN
@@ -3489,4 +3495,12 @@
         WHERE cssp.user_id_ = #{studentId} AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW()
         AND vg.educational_teacher_id_ = #{teacherId}
     </select>
+    <select id="findCoursesByClassGroupIdAndCourseIds" resultMap="CourseSchedule">
+        SELECT * FROM course_schedule WHERE class_group_id_ = #{classGroupId}
+        AND id_ IN
+        <foreach collection="allLockCourseIds" item="courseId" open="(" close=")" separator=",">
+            #{courseId}
+        </foreach>
+        ORDER BY class_date_,start_class_time_ ASC
+    </select>
 </mapper>

+ 2 - 1
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -488,7 +488,8 @@
         </foreach>
     </insert>
 
-    <insert id="insertBasic" parameterType="com.ym.mec.biz.dal.entity.StudentRegistration">
+    <insert id="insertBasic" parameterType="com.ym.mec.biz.dal.entity.StudentRegistration" useGeneratedKeys="true"
+            keyColumn="id" keyProperty="id">
         INSERT INTO student_registration
         (parents_phone_,user_id_,name_,music_group_id_,current_grade_,current_class_,subject_id_,
         create_time_,update_time_,parents_name_,payment_status_,actual_subject_id_,music_group_status_,temporary_course_fee_,class_group_id_)