Quellcode durchsuchen

乐团编辑中状态,声部有学生,不能删除

周箭河 vor 4 Jahren
Ursprung
Commit
2c6e836e8b

+ 61 - 40
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -401,8 +401,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentPaymentOrder.setVersion(0);
         BigDecimal balance = BigDecimal.ZERO;
         if (sporadicPayDto.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
-            if (chargeInfo.getChargeType().getCode().equals(9)||chargeInfo.getChargeType().getCode().equals(13)) {
-                throw new BizException(chargeInfo.getChargeType().getMsg()+"不支持余额支付");
+            if (chargeInfo.getChargeType().getCode().equals(9) || chargeInfo.getChargeType().getCode().equals(13)) {
+                throw new BizException(chargeInfo.getChargeType().getMsg() + "不支持余额支付");
             }
             SysUserCashAccount userCashAccount = sysUserCashAccountService.get(userId);
 
@@ -918,22 +918,47 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         String musicGroupId = subFeeSettingDto.getMusicGroupId();
         //乐团状态是否正确
         MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
-        if (musicGroup != null) {
-            if (subFeeSettingDto.getMusicGroupStatus() == null) {
-                throw new BizException("参数校验异常");
-            }
-            if (musicGroup.getStatus() == MusicGroupStatusEnum.DRAFT || musicGroup.getStatus() == MusicGroupStatusEnum.AUDIT_FAILED) {
-                musicGroup.setStatus(subFeeSettingDto.getMusicGroupStatus());
-                musicGroup.setUpdateTime(new Date());
-                musicGroupDao.update(musicGroup);
-            }
-            //记录日志信息
-            musicGroupBuildLogDao.insert(new MusicGroupBuildLog(musicGroupId, "修改乐团计划声部、乐器", sysUser.getId(), JSONObject.toJSONString(subFeeSettingDto)));
-            //删除原有的乐团声部规划
-            musicGroupSubjectPlanDao.delByMusicGroupId(musicGroupId);
-            //删除原有的声部商品组合
-            musicGroupSubjectGoodsGroupDao.delByMusicGroupId(subFeeSettingDto.getMusicGroupId());
-            //如果是进行中,补充缴费信息
+        if (musicGroup == null) {
+            throw new BizException("乐团信息不存在");
+        }
+        if (subFeeSettingDto.getMusicGroupStatus() == null) {
+            throw new BizException("参数校验异常");
+        }
+        //声部存在学生不容许删除声部
+        List<StudentRegistration> registrations = studentRegistrationDao.findClassGroupStu(musicGroupId, null);
+        Map<Integer, List<StudentRegistration>> regMap = registrations.stream().collect(Collectors.groupingBy(StudentRegistration::getActualSubjectId));
+        List<MusicGroupSubjectPlan> musicGroupSubjectPlans = subFeeSettingDto.getMusicGroupSubjectPlans();
+        List<Integer> waringSubjectIds = new ArrayList<>();
+        regMap.forEach((subjectId, regs) -> {
+            boolean hasSubject = false;
+            for (MusicGroupSubjectPlan musicGroupSubjectPlan : musicGroupSubjectPlans) {
+                if (musicGroupSubjectPlan.getSubjectId().equals(subjectId)) {
+                    hasSubject = true;
+                    musicGroupSubjectPlan.setApplyStudentNum(regs.size());
+                }
+            }
+            if (!hasSubject) {
+                waringSubjectIds.add(subjectId);
+            }
+        });
+        if (waringSubjectIds.size() > 0) {
+            List<Subject> waringSubjects = subjectDao.findBySubjectIds(waringSubjectIds);
+            String waringSubjectStr  = waringSubjects.stream().map(Subject::getName).collect(Collectors.joining(","));
+            throw new BizException(waringSubjectStr+"存在学生,不能删除");
+        }
+
+        if (musicGroup.getStatus() == MusicGroupStatusEnum.DRAFT || musicGroup.getStatus() == MusicGroupStatusEnum.AUDIT_FAILED) {
+            musicGroup.setStatus(subFeeSettingDto.getMusicGroupStatus());
+            musicGroup.setUpdateTime(new Date());
+            musicGroupDao.update(musicGroup);
+        }
+        //记录日志信息
+        musicGroupBuildLogDao.insert(new MusicGroupBuildLog(musicGroupId, "修改乐团计划声部、乐器", sysUser.getId(), JSONObject.toJSONString(subFeeSettingDto)));
+        //删除原有的乐团声部规划
+        musicGroupSubjectPlanDao.delByMusicGroupId(musicGroupId);
+        //删除原有的声部商品组合
+        musicGroupSubjectGoodsGroupDao.delByMusicGroupId(subFeeSettingDto.getMusicGroupId());
+        //如果是进行中,补充缴费信息
 //            if(musicGroup.getStatus() == MusicGroupStatusEnum.PROGRESS){
 //                List<MusicGroupStudentFee> musicGroupStudentFees = musicGroupStudentFeeDao.initMusicGroupStudentFee(musicGroupId);
 //                if(musicGroupStudentFees != null && musicGroupStudentFees.size() > 0){
@@ -941,30 +966,26 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 //                    musicGroupStudentFeeDao.batchInsert(musicGroupStudentFees,nextPaymentDate,"PAID_COMPLETED");
 //                }
 //            }
-            List<MusicGroupSubjectPlan> musicGroupSubjectPlans = subFeeSettingDto.getMusicGroupSubjectPlans();
-            if (musicGroupSubjectPlans != null && musicGroupSubjectPlans.size() > 0) {
-                musicGroupSubjectPlans.forEach(e -> {
-                    //修改课程费用
-                    musicGroupStudentFeeDao.updateCourseFee(musicGroupId, e.getSubjectId(), e.getFee());
-                });
-                musicGroupSubjectPlanDao.batchAdd(musicGroupSubjectPlans, musicGroupId);
-            }
-            if (subFeeSettingDto.getMusicGroupSubjectGoodsGroups() != null && subFeeSettingDto.getMusicGroupSubjectGoodsGroups().size() > 0) {
-                for (MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup : subFeeSettingDto.getMusicGroupSubjectGoodsGroups()) {
-                    if (musicGroupSubjectGoodsGroup.getType().equals(GoodsType.INSTRUMENT) && (musicGroupSubjectGoodsGroup.getKitGroupPurchaseTypeJson() == null
-                            || musicGroupSubjectGoodsGroup.getKitGroupPurchaseTypeJson().isEmpty()
-                            || musicGroupSubjectGoodsGroup.getKitGroupPurchaseTypeJson().equals("{}"))) {
-                        throw new BizException(musicGroupSubjectGoodsGroup.getName() + " 请选择提供方式");
-                    }
-                    if (musicGroupSubjectGoodsGroup.getGroupRemissionCourseFee() == null) {
-                        musicGroupSubjectGoodsGroup.setGroupRemissionCourseFee(0);
-                    }
+        if (musicGroupSubjectPlans != null && musicGroupSubjectPlans.size() > 0) {
+            musicGroupSubjectPlans.forEach(e -> {
+                //修改课程费用
+                musicGroupStudentFeeDao.updateCourseFee(musicGroupId, e.getSubjectId(), e.getFee());
+            });
+            musicGroupSubjectPlanDao.batchAdd(musicGroupSubjectPlans, musicGroupId);
+        }
+        if (subFeeSettingDto.getMusicGroupSubjectGoodsGroups() != null && subFeeSettingDto.getMusicGroupSubjectGoodsGroups().size() > 0) {
+            for (MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup : subFeeSettingDto.getMusicGroupSubjectGoodsGroups()) {
+                if (musicGroupSubjectGoodsGroup.getType().equals(GoodsType.INSTRUMENT) && (musicGroupSubjectGoodsGroup.getKitGroupPurchaseTypeJson() == null
+                        || musicGroupSubjectGoodsGroup.getKitGroupPurchaseTypeJson().isEmpty()
+                        || musicGroupSubjectGoodsGroup.getKitGroupPurchaseTypeJson().equals("{}"))) {
+                    throw new BizException(musicGroupSubjectGoodsGroup.getName() + " 请选择提供方式");
+                }
+                if (musicGroupSubjectGoodsGroup.getGroupRemissionCourseFee() == null) {
+                    musicGroupSubjectGoodsGroup.setGroupRemissionCourseFee(0);
                 }
-
-                musicGroupSubjectGoodsGroupDao.batchInsert(subFeeSettingDto.getMusicGroupSubjectGoodsGroups(), musicGroupId);
             }
-        } else {
-            throw new BizException("乐团信息不存在");
+
+            musicGroupSubjectGoodsGroupDao.batchInsert(subFeeSettingDto.getMusicGroupSubjectGoodsGroups(), musicGroupId);
         }
     }