Selaa lähdekoodia

feat:乐团排课调整

Joburgess 4 vuotta sitten
vanhempi
commit
ebab6b5ae9

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ClassGroup4MixDto.java

@@ -70,6 +70,17 @@ public class ClassGroup4MixDto implements Cloneable{
     @ApiModelProperty(value = "是否允许0课酬")
     private Boolean allowZeroSalary = false;
 
+    @ApiModelProperty(value = "确认生成课程")
+    private Boolean confirmGenerate;
+
+    public Boolean getConfirmGenerate() {
+        return confirmGenerate;
+    }
+
+    public void setConfirmGenerate(Boolean confirmGenerate) {
+        this.confirmGenerate = confirmGenerate;
+    }
+
     public Boolean getAllowZeroSalary() {
         return allowZeroSalary;
     }

+ 33 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/CourseTimeDto.java

@@ -26,6 +26,23 @@ public class CourseTimeDto {
     @ApiModelProperty(value = "上课结束时间")
     private String endClassTime;
 
+    @ApiModelProperty(value = "预计排课次数")
+    private int expectCourseNum;
+
+    @ApiModelProperty(value = "已生成课程数量")
+    private int courseNum;
+
+    @ApiModelProperty(value = "是否跳过节假日 true-跳过 false-不跳过", required = true)
+    private Boolean isHoliday = false;
+
+    public Boolean getHoliday() {
+        return isHoliday;
+    }
+
+    public void setHoliday(Boolean holiday) {
+        isHoliday = holiday;
+    }
+
     public CourseSchedule.CourseScheduleType getCourseType() {
         return courseType;
     }
@@ -73,4 +90,20 @@ public class CourseTimeDto {
     public void setEndClassTime(String endClassTime) {
         this.endClassTime = endClassTime;
     }
+
+    public int getExpectCourseNum() {
+        return expectCourseNum;
+    }
+
+    public void setExpectCourseNum(int expectCourseNum) {
+        this.expectCourseNum = expectCourseNum;
+    }
+
+    public int getCourseNum() {
+        return courseNum;
+    }
+
+    public void setCourseNum(int courseNum) {
+        this.courseNum = courseNum;
+    }
 }

+ 44 - 19
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -2292,6 +2292,11 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
             throw new BizException("班级不存在");
         }
 
+        Boolean confirmGenerate = false;
+        if(Objects.nonNull(classGroup4MixDtos.get(0).getConfirmGenerate())){
+            confirmGenerate = classGroup4MixDtos.get(0).getConfirmGenerate();
+        }
+
         TeachModeEnum teachMode = TeachModeEnum.OFFLINE;
         if (classGroup.getType().equals(HIGH_ONLINE) || classGroup.getType().equals(ClassGroupTypeEnum.MUSIC_NETWORK)) {
             teachMode = TeachModeEnum.ONLINE;
@@ -2409,6 +2414,12 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                 throw new BizException("{}课程类型剩余课程时长不足", classGroup4MixDto.getCourseType().getMsg());
             }
 
+            int totalCourseTimes = 0;
+            int generateCourseTimes = 0;
+            if(!CollectionUtils.isEmpty(classGroup4MixDto.getCourseTimeDtoList())){
+                totalCourseTimes = classGroup4MixDto.getCourseTimeDtoList().stream().mapToInt(CourseTimeDto::getExpectCourseNum).reduce(0, Integer::sum);
+            }
+
             Set<String> holidayDays = new HashSet<>();
             if (classGroup4MixDto.getHoliday()) {
                 SysConfig holidaySetting = sysConfigService.findByParamName(SysConfigService.HOLIDAY_SETTING);
@@ -2417,35 +2428,35 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                 }
             }
 
-            if(!CollectionUtils.isEmpty(classGroup4MixDto.getCourseTimeDtoList())){
-                int cycleNum = classGroup4MixDto.getCourseTimeDtoList().size();
-                long num = classGroup4MixDto.getCourseTimeDtoList().stream().filter(c -> Objects.nonNull(c.getStartDate())).count();
-                if(num>0&&num!=cycleNum){
-                    throw new BizException("循环周期排课日期未设置");
-                }
-                if(num>0){
-                    for (int i = 0;i<cycleNum-1; i++) {
-                        classGroup4MixDto.getCourseTimeDtoList().get(i).setEndDate(classGroup4MixDto.getCourseTimeDtoList().get(i+1).getStartDate());
-                    }
-                }
-            }
-
             WhileNode:
             while (true) {
-                if (classGroup4MixDto.getHoliday() && holidayDays.contains(now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))) {
-                    now = now.plusDays(1);
-                    continue;
-                }
                 int dayOfWeek = now.getDayOfWeek().getValue();
                 for (CourseTimeDto courseTimeDto : classGroup4MixDto.getCourseTimeDtoList()) {
                     if (courseTimeDto.getDayOfWeek() < 1 || courseTimeDto.getDayOfWeek() > 7) {
                         throw new BizException("排课循环周期错误,请核查");
                     }
+                    if(Objects.isNull(courseTimeDto.getStartDate())||Objects.isNull(courseTimeDto.getEndDate())){
+                        throw new BizException("排课循环周期错误,请核查");
+                    }
+
+                    //跳过节假日
+                    if (courseTimeDto.getHoliday() && holidayDays.contains(now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))) {
+                        continue;
+                    }
+
                     if (!courseTimeDto.getDayOfWeek().equals(dayOfWeek)) continue;
 
                     Date classDate = DateConvertor.toDate(now);
 
-                    if((Objects.nonNull(courseTimeDto.getStartDate())&&courseTimeDto.getStartDate().compareTo(classDate)>0)||(Objects.nonNull(courseTimeDto.getEndDate())&&courseTimeDto.getEndDate().compareTo(classDate)<0)){
+                    if(courseTimeDto.getStartDate().compareTo(classDate)>0
+                            ||courseTimeDto.getEndDate().compareTo(classDate)<0
+                            ||courseTimeDto.getExpectCourseNum()<=courseTimeDto.getCourseNum()){
+                        if(courseTimeDto.getEndDate().compareTo(classDate)<0&&courseTimeDto.getExpectCourseNum()>courseTimeDto.getCourseNum()){
+                            throw new BizException("在指定的排课时间段内({}-{})无法完成预计课时数的排课", DateUtil.dateToString(courseTimeDto.getStartDate(), "yyyy.MM.dd"), DateUtil.dateToString(courseTimeDto.getEndDate(), "yyyy.MM.dd"));
+                        }
+                        if(totalCourseTimes<=generateCourseTimes){
+                            break WhileNode;
+                        }
                         continue;
                     }
 
@@ -2456,7 +2467,14 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 
                     totalCourseDuration += classCourseDuration;
 
-                    if (totalCourseDuration > totalMinutes) {
+//                    if (totalCourseDuration > totalMinutes) {
+//                        break WhileNode;
+//                    }
+
+                    courseTimeDto.setCourseNum(courseTimeDto.getCourseNum()+1);
+                    generateCourseTimes+=1;
+
+                    if(totalCourseTimes<generateCourseTimes){
                         break WhileNode;
                     }
 
@@ -2469,6 +2487,9 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                     courseSchedule.setStatus(CourseStatusEnum.NOT_START);
                     courseSchedule.setClassDate(classDate);
                     courseSchedule.setStartClassTime(DateUtil.stringToDate(startClassTime));
+                    if(date.compareTo(courseSchedule.getStartClassTime())>0){
+                        throw new BizException("课程开始时间不得早于当前时间");
+                    }
                     courseSchedule.setEndClassTime(DateUtil.stringToDate(endClassTime));
                     courseSchedule.setCreateTime(date);
                     courseSchedule.setUpdateTime(date);
@@ -2513,6 +2534,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 
         courseScheduleService.checkNewCourseSchedules(courseScheduleList, false, false);
 
+        if(!confirmGenerate){
+            return BaseController.failed(HttpStatus.PARTIAL_CONTENT, courseScheduleList, "");
+        }
+
         //老师结算表
         if (courseScheduleTeacherSalaryList.size() > 0) {
             courseScheduleTeacherSalaryService.batchInsert(courseScheduleTeacherSalaryList);