Browse Source

跨团合班逻辑调整

zouxuan 4 years ago
parent
commit
2dfbaeed57

+ 47 - 81
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -3672,104 +3672,70 @@ 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<>();
+        //主班剩余课程价值
+        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;
+            }
+            BigDecimal subDecimal = subCourseAmount;
+            BigDecimal masterDecimal1 = masterTotalPrice;
+            for (int i = 0; i < courseTypes.size(); 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);
-                }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);
-
+                BigDecimal decimal = subCourseAmount.divide(new BigDecimal(courseTypes.size())).setScale(0, BigDecimal.ROUND_HALF_UP);
+                BigDecimal masterDecimal = masterTotalPrice.divide(new BigDecimal(courseTypes.size())).setScale(0, BigDecimal.ROUND_HALF_UP);
+                subDecimal = subDecimal.subtract(decimal);
+                masterDecimal1 = masterDecimal1.subtract(masterDecimal);
+                if(i == courseTypes.size() - 1){
+                    decimal =  decimal.add(subDecimal);
+                }
+                if(i == courseTypes.size() - 1){
+                    masterDecimal =  masterDecimal.add(masterDecimal1);
+                }
+                calenderDto.setMasterSubCoursePrice(masterDecimal);
+                calenderDto.setSubCourseAmount(decimal);
+                calenderDto.setCutAmount(decimal);
+                calenderDto.setCourseCurrentPrice(masterDecimal.subtract(decimal));
+                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,9 +3745,6 @@ 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("所选主班没有剩余课程,请重新选择");
-        }
         //获取分布默认的课程类型单价
         MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
         Map<String, BigDecimal> unitPriceMap = MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(musicGroup.getChargeTypeId(), musicGroup.getOrganId()));
@@ -3794,6 +3757,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);

+ 3 - 1
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -715,6 +715,8 @@
 		SELECT SUM(cssp.expect_price_) FROM course_schedule_student_payment cssp
 		LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
 		WHERE cssp.class_group_id_ = #{classGroupId} AND cssp.user_id_ = #{studentId} AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW()
-		AND cs.type_ = #{courseType}
+	  <if test="courseType != null">
+		  AND cs.type_ = #{courseType}
+	  </if>
 	</select>
 </mapper>