|  | @@ -3672,104 +3672,69 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 | 
	
		
			
				|  |  |          Map<Integer, Integer> studentCLassMap = new HashMap<>();
 | 
	
		
			
				|  |  |          List<Map<Integer, BigDecimal>> surplusCourseFeeMapList = new ArrayList<>();
 | 
	
		
			
				|  |  |          List<Map<String,String>> classGroupStudents = (List<Map<String,String>>)JSON.parse(classGroupStudentMap);
 | 
	
		
			
				|  |  | -//        Map<Integer,Map<String, BigDecimal>> classGroupUnitPriceMap = new HashMap<>();
 | 
	
		
			
				|  |  | -//        Map<Integer,Map<String, BigDecimal>> classSubCoursePriceMap = new HashMap<>();
 | 
	
		
			
				|  |  | +        //学员剩余课程价值
 | 
	
		
			
				|  |  | +        Map<Integer,BigDecimal> classGroupTotalPrice = new HashMap<>();
 | 
	
		
			
				|  |  | +        //主班剩余课程价值
 | 
	
		
			
				|  |  | +        Map<String, BigDecimal> masterTotalPriceMap = getMasterTotalPriceMap(masterClassGroupId);
 | 
	
		
			
				|  |  | +        BigDecimal masterTotalPrice = getMasterTotalPrice(masterClassGroupId);
 | 
	
		
			
				|  |  |          for (Map<String, String> classGroupStudent : classGroupStudents) {
 | 
	
		
			
				|  |  |              for (String integer : classGroupStudent.keySet()) {
 | 
	
		
			
				|  |  |                  //获取学员剩余课程费用
 | 
	
		
			
				|  |  |                  surplusCourseFeeMapList.addAll(studentRegistrationDao.querySurplusCourseFeeByClassGroupId(Integer.parseInt(integer),classGroupStudent.get(integer)));
 | 
	
		
			
				|  |  | -                MusicGroup byClassId = musicGroupDao.findByClassId(Integer.parseInt(integer));
 | 
	
		
			
				|  |  | -                if (byClassId == null){
 | 
	
		
			
				|  |  | -                    throw new BizException("操作失败:班级所在乐团状态不支持");
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                //学员可能来自不同的分部,获取对应的课程单价
 | 
	
		
			
				|  |  | -//                classGroupUnitPriceMap.put(Integer.parseInt(integer),MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(byClassId.getChargeTypeId(), byClassId.getOrganId())));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                //获取班级剩余课程时长
 | 
	
		
			
				|  |  | -//                classSubCoursePriceMap.put(Integer.parseInt(integer),MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(Integer.parseInt(integer))));
 | 
	
		
			
				|  |  |                  String[] s = classGroupStudent.get(integer).split(",");
 | 
	
		
			
				|  |  |                  for (String s1 : s) {
 | 
	
		
			
				|  |  | +                    classGroupTotalPrice.put(Integer.parseInt(s1),courseScheduleStudentPaymentDao.querySubCoursePriceMap(Integer.parseInt(s1),Integer.parseInt(integer),null));
 | 
	
		
			
				|  |  |                      studentCLassMap.put(Integer.parseInt(s1),Integer.parseInt(integer));
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //学员剩余课程费用
 | 
	
		
			
				|  |  |          Map<Integer, BigDecimal> surplusCourseFeeMap = MapUtil.convertIntegerMap(surplusCourseFeeMapList);
 | 
	
		
			
				|  |  | -        //获取分布默认的课程类型单价
 | 
	
		
			
				|  |  | -        MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
 | 
	
		
			
				|  |  | -        Map<String, BigDecimal> masterUnitPriceMap = MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(musicGroup.getChargeTypeId(), musicGroup.getOrganId()));
 | 
	
		
			
				|  |  | -        Set<String> masterKeySet = masterMap.keySet();
 | 
	
		
			
				|  |  | -        //计算主班课程类型剩余价值
 | 
	
		
			
				|  |  | -//        Map<String, BigDecimal> masterTotalPriceMap = new HashMap<>(masterKeySet.size());
 | 
	
		
			
				|  |  | -        //计算从班课程类型剩余价值
 | 
	
		
			
				|  |  | -        Map<String,Map<Integer, BigDecimal>> studentTotalPriceMap = new HashMap<>();
 | 
	
		
			
				|  |  | -        //学员缴费项目列表
 | 
	
		
			
				|  |  | +        List<String> courseTypes = new ArrayList(masterMap.keySet());
 | 
	
		
			
				|  |  |          List<MusicGroupPaymentCalenderStudentDetail> musicGroupPaymentCalenderStudentDetails = new ArrayList<>();
 | 
	
		
			
				|  |  | -        for (String s : masterKeySet) {
 | 
	
		
			
				|  |  | -            BigDecimal masterUnitPrice = masterUnitPriceMap.get(s);
 | 
	
		
			
				|  |  | -            if (masterUnitPrice == null) {
 | 
	
		
			
				|  |  | -                throw new BizException("分部默认课程类型单价不存在,请设置");
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            BigDecimal masterCourseTime = masterMap.get(s);
 | 
	
		
			
				|  |  | -            //获取主班剩余课程价值,按分部默认单价计算
 | 
	
		
			
				|  |  | -            //总价四舍五入取整
 | 
	
		
			
				|  |  | -            BigDecimal masterTotalPrice = masterUnitPrice.multiply(masterCourseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -//            masterTotalPriceMap.put(s,masterTotalPrice);
 | 
	
		
			
				|  |  | -            //获取学员剩余课程价值
 | 
	
		
			
				|  |  | -            Map<Integer, BigDecimal> totalPriceMap = new HashMap<>();
 | 
	
		
			
				|  |  | -            //课程余额转移
 | 
	
		
			
				|  |  | -            for (Integer studentId : studentCLassMap.keySet()) {
 | 
	
		
			
				|  |  | -                //学员剩余课程价值
 | 
	
		
			
				|  |  | -                BigDecimal totalPrice = courseScheduleStudentPaymentDao.querySubCoursePriceMap(studentId,studentCLassMap.get(studentId),s);
 | 
	
		
			
				|  |  | -                //学员剩余课程余额
 | 
	
		
			
				|  |  | -                BigDecimal bigDecimal = surplusCourseFeeMap.get(studentId);
 | 
	
		
			
				|  |  | -                //创建学员缴费项目
 | 
	
		
			
				|  |  | +        for (Integer studentId : studentCLassMap.keySet()) {
 | 
	
		
			
				|  |  | +            //学员剩余课程价值
 | 
	
		
			
				|  |  | +            BigDecimal totalPrice = classGroupTotalPrice.get(studentId);
 | 
	
		
			
				|  |  | +            if(totalPrice == null){
 | 
	
		
			
				|  |  | +                totalPrice = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //学员剩余课程余额
 | 
	
		
			
				|  |  | +            BigDecimal bigDecimal = surplusCourseFeeMap.get(studentId);
 | 
	
		
			
				|  |  | +            if(bigDecimal == null){
 | 
	
		
			
				|  |  | +                bigDecimal = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //学员可带走的价值
 | 
	
		
			
				|  |  | +            BigDecimal subCourseAmount;
 | 
	
		
			
				|  |  | +            if(masterTotalPrice.doubleValue() >= totalPrice.doubleValue()){
 | 
	
		
			
				|  |  | +                subCourseAmount = totalPrice;
 | 
	
		
			
				|  |  | +            }else {
 | 
	
		
			
				|  |  | +                subCourseAmount = masterTotalPrice;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(subCourseAmount.doubleValue() >= bigDecimal.doubleValue()){
 | 
	
		
			
				|  |  | +                subCourseAmount = bigDecimal;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            for (int i = 0; i < courseTypes.size(); i++) {
 | 
	
		
			
				|  |  | +                BigDecimal masterPrice = masterTotalPriceMap.get(courseTypes.get(i));
 | 
	
		
			
				|  |  |                  MusicGroupPaymentCalenderStudentDetail calenderDto = new MusicGroupPaymentCalenderStudentDetail();
 | 
	
		
			
				|  |  |                  calenderDto.setClassGroupId(studentCLassMap.get(studentId));
 | 
	
		
			
				|  |  | -                //学员班级剩余课程价值
 | 
	
		
			
				|  |  | -//                Map<String, BigDecimal> subCoursePriceMap = classSubCoursePriceMap.get(calenderDto.getClassGroupId());
 | 
	
		
			
				|  |  | -//                Map<String, BigDecimal> unitPriceMap = classGroupUnitPriceMap.get(calenderDto.getClassGroupId());
 | 
	
		
			
				|  |  | -//                BigDecimal courseTime = subCoursePriceMap.get(s);
 | 
	
		
			
				|  |  | -//                BigDecimal unitPrice = unitPriceMap.get(s);
 | 
	
		
			
				|  |  | -//                if (unitPrice == null) {
 | 
	
		
			
				|  |  | -//                    throw new BizException("分部默认课程类型单价不存在,请设置");
 | 
	
		
			
				|  |  | -//                }
 | 
	
		
			
				|  |  | -                if(totalPrice == null){
 | 
	
		
			
				|  |  | -                    totalPrice = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -//                BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                totalPriceMap.put(studentId,totalPrice);
 | 
	
		
			
				|  |  | -                calenderDto.setMasterSubCoursePrice(masterTotalPrice);
 | 
	
		
			
				|  |  | -                BigDecimal subCourseAmount = new BigDecimal(Math.min(Math.min(masterTotalPrice.doubleValue(), totalPrice.doubleValue()), bigDecimal.doubleValue()));
 | 
	
		
			
				|  |  | -                calenderDto.setSubCourseAmount(subCourseAmount);
 | 
	
		
			
				|  |  | -                //如果剩余课程余额小于等于0
 | 
	
		
			
				|  |  | -                if(subCourseAmount.doubleValue() <= 0d){
 | 
	
		
			
				|  |  | -                    calenderDto.setCourseCurrentPrice(masterTotalPrice);
 | 
	
		
			
				|  |  | -                    calenderDto.setCourseOriginalPrice(masterTotalPrice);
 | 
	
		
			
				|  |  | +                if(subCourseAmount.doubleValue() >= masterPrice.doubleValue()){
 | 
	
		
			
				|  |  | +                    calenderDto.setSubCourseAmount(masterPrice);
 | 
	
		
			
				|  |  | +                    calenderDto.setCutAmount(masterPrice);
 | 
	
		
			
				|  |  | +                    subCourseAmount = subCourseAmount.subtract(masterPrice);
 | 
	
		
			
				|  |  |                  }else {
 | 
	
		
			
				|  |  | -                    //如果剩余课程余额大于等于总价值,那么补交0元
 | 
	
		
			
				|  |  | -                    if(subCourseAmount.doubleValue() >= masterTotalPrice.doubleValue()){
 | 
	
		
			
				|  |  | -                        calenderDto.setCutAmount(masterTotalPrice);
 | 
	
		
			
				|  |  | -                        calenderDto.setCourseCurrentPrice(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | -                        calenderDto.setCourseOriginalPrice(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | -                    }else {
 | 
	
		
			
				|  |  | -                        calenderDto.setCourseCurrentPrice(masterTotalPrice.subtract(subCourseAmount));
 | 
	
		
			
				|  |  | -                        calenderDto.setCutAmount(subCourseAmount);
 | 
	
		
			
				|  |  | -                        calenderDto.setCourseOriginalPrice(masterTotalPrice.subtract(subCourseAmount));
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    //剩余课程余额减去主班对应课程类型总的课程价值,负数就是需要补交的金额
 | 
	
		
			
				|  |  | -//                    bigDecimal = bigDecimal.subtract(totalPrice);
 | 
	
		
			
				|  |  | -                    surplusCourseFeeMap.put(studentId,bigDecimal.subtract(masterTotalPrice));
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -//                calenderDto.setCourseTime(courseTime.intValue());
 | 
	
		
			
				|  |  | -                calenderDto.setCourseType(s);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                    calenderDto.setSubCourseAmount(subCourseAmount);
 | 
	
		
			
				|  |  | +                    calenderDto.setCutAmount(subCourseAmount);
 | 
	
		
			
				|  |  | +                    subCourseAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                calenderDto.setCourseTime(masterMap.get(courseTypes.get(i)).intValue());
 | 
	
		
			
				|  |  | +                calenderDto.setMasterSubCoursePrice(masterPrice);
 | 
	
		
			
				|  |  | +                calenderDto.setCourseCurrentPrice(masterPrice.subtract(calenderDto.getCutAmount()));
 | 
	
		
			
				|  |  | +                calenderDto.setCourseType(courseTypes.get(i));
 | 
	
		
			
				|  |  |                  calenderDto.setPhone(phoneMaps.get(studentId));
 | 
	
		
			
				|  |  |                  calenderDto.setUserId(studentId);
 | 
	
		
			
				|  |  |                  calenderDto.setUsername(userNames.get(studentId));
 | 
	
		
			
				|  |  |                  musicGroupPaymentCalenderStudentDetails.add(calenderDto);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            studentTotalPriceMap.put(s,totalPriceMap);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return musicGroupPaymentCalenderStudentDetails;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -3779,8 +3744,8 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 | 
	
		
			
				|  |  |      public BigDecimal getMasterTotalPrice(Integer masterClassGroupId) {
 | 
	
		
			
				|  |  |          //获取主班剩余时长
 | 
	
		
			
				|  |  |          Map<String, BigDecimal> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(masterClassGroupId));
 | 
	
		
			
				|  |  | -        if(masterMap.size() <= 0){
 | 
	
		
			
				|  |  | -            throw new BizException("所选主班没有剩余课程,请重新选择");
 | 
	
		
			
				|  |  | +        if(masterMap.size() == 0){
 | 
	
		
			
				|  |  | +            throw new BizException("操作失败:所选主班没有剩余时长");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //获取分布默认的课程类型单价
 | 
	
		
			
				|  |  |          MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
 | 
	
	
		
			
				|  | @@ -3794,6 +3759,9 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 | 
	
		
			
				|  |  |                  throw new BizException("分部默认课程类型单价不存在,请设置");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              BigDecimal courseTime = masterMap.get(s);
 | 
	
		
			
				|  |  | +            if(courseTime == null){
 | 
	
		
			
				|  |  | +                courseTime = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //获取主班剩余课程价值,按分部默认单价计算
 | 
	
		
			
				|  |  |              //总价四舍五入取整
 | 
	
		
			
				|  |  |              BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
 | 
	
	
		
			
				|  | @@ -3802,6 +3770,34 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 | 
	
		
			
				|  |  |          return masterTotalPrice;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public Map<String,BigDecimal> getMasterTotalPriceMap(Integer masterClassGroupId) {
 | 
	
		
			
				|  |  | +        //获取主班剩余时长
 | 
	
		
			
				|  |  | +        Map<String, BigDecimal> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(masterClassGroupId));
 | 
	
		
			
				|  |  | +        if(masterMap.size() == 0){
 | 
	
		
			
				|  |  | +            throw new BizException("操作失败:所选主班没有剩余时长");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Map<String,BigDecimal> resultMap = new HashMap<>();
 | 
	
		
			
				|  |  | +        //获取分布默认的课程类型单价
 | 
	
		
			
				|  |  | +        MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
 | 
	
		
			
				|  |  | +        Map<String, BigDecimal> unitPriceMap = MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(musicGroup.getChargeTypeId(), musicGroup.getOrganId()));
 | 
	
		
			
				|  |  | +        Set<String> masterKeySet = masterMap.keySet();
 | 
	
		
			
				|  |  | +        //计算主班课程类型剩余价值
 | 
	
		
			
				|  |  | +        for (String s : masterKeySet) {
 | 
	
		
			
				|  |  | +            BigDecimal unitPrice = unitPriceMap.get(s);
 | 
	
		
			
				|  |  | +            if (unitPrice == null) {
 | 
	
		
			
				|  |  | +                throw new BizException("分部默认课程类型单价不存在,请设置");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            BigDecimal courseTime = masterMap.get(s);
 | 
	
		
			
				|  |  | +            if(courseTime == null){
 | 
	
		
			
				|  |  | +                courseTime = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //获取主班剩余课程价值,按分部默认单价计算
 | 
	
		
			
				|  |  | +            BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | +            resultMap.put(s,totalPrice);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return resultMap;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Map<String, Long> querySubCourseTime(Integer classGroupId) {
 | 
	
		
			
				|  |  |          return MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseNumMap(classGroupId));
 |