|
@@ -34,12 +34,14 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
@@ -1212,7 +1214,325 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- @Override
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void courseAdjustOnlyWithClassDate(List<CourseSchedule> courseSchedules, Integer operatorId) {
|
|
|
+ if(CollectionUtils.isEmpty(courseSchedules)){
|
|
|
+ throw new BizException("请指定课程");
|
|
|
+ }
|
|
|
+ Map<Long, CourseSchedule> idCourseMap = courseSchedules.stream().collect(Collectors.toMap(CourseSchedule::getId, c -> c));
|
|
|
+ List<Long> courseIds = courseSchedules.stream().map(CourseSchedule::getId).collect(Collectors.toList());
|
|
|
+ List<CourseSchedule> existCourses = courseScheduleDao.findByCourseScheduleIds(courseIds);
|
|
|
+ List<CourseScheduleModifyLog> scheduleModifyLogs = new ArrayList<>();
|
|
|
+ Date now=new Date();
|
|
|
+ for (CourseSchedule existCours : existCourses) {
|
|
|
+ CourseSchedule ac = idCourseMap.get(existCours.getId());
|
|
|
+
|
|
|
+ if(now.compareTo(ac.getStartClassTime())>0){
|
|
|
+ throw new BizException("课程调整时间不得小于当前时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ CourseScheduleModifyLog scheduleModifyLog = new CourseScheduleModifyLog();
|
|
|
+ scheduleModifyLog.setCourseScheduleId(existCours.getId());
|
|
|
+ scheduleModifyLog.setPreviousCourseSchedule(JSONObject.toJSONString(existCours));
|
|
|
+ scheduleModifyLog.setCreateTime(now);
|
|
|
+ scheduleModifyLog.setOperatorId(operatorId);
|
|
|
+
|
|
|
+ int singleClassMinutes = DateUtil.minutesBetween(existCours.getStartClassTime(), existCours.getEndClassTime());
|
|
|
+
|
|
|
+ existCours.setClassDate(ac.getClassDate());
|
|
|
+ existCours.setStartClassTime(ac.getStartClassTime());
|
|
|
+ existCours.setEndClassTime(DateUtil.addMinutes(existCours.getStartClassTime(), singleClassMinutes));
|
|
|
+
|
|
|
+ scheduleModifyLog.setCurrentCourseSchedule(JSONObject.toJSONString(existCours));
|
|
|
+ scheduleModifyLogs.add(scheduleModifyLog);
|
|
|
+ }
|
|
|
+ checkNewCourseSchedules(existCourses, false);
|
|
|
+ courseScheduleDao.batchUpdate(existCourses);
|
|
|
+ courseScheduleModifyLogDao.batchInsert(scheduleModifyLogs);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String, List<CourseSchedule>> courseAdjustOnlyWithClassDateCheck(VipGroupCourseAdjustInfoDto courseAdjustInfo) {
|
|
|
+ if(StringUtils.isBlank(courseAdjustInfo.getCourseScheduleIds())){
|
|
|
+ throw new BizException("请指定课程");
|
|
|
+ }
|
|
|
+ if(Objects.isNull(courseAdjustInfo.getCourseCreateStartTime())){
|
|
|
+ throw new BizException("请指定课程调整起始时间");
|
|
|
+ }
|
|
|
+ if(Objects.isNull(courseAdjustInfo.getCourseTimes())){
|
|
|
+ throw new BizException("请指定课程调整周期");
|
|
|
+ }
|
|
|
+ Date now=new Date();
|
|
|
+ //所有课程编号
|
|
|
+ List<Long> adjustCourseScheduleIds = Arrays.asList(courseAdjustInfo.getCourseScheduleIds().split(","))
|
|
|
+ .stream().map(Long::parseLong).collect(Collectors.toList());
|
|
|
+ //所有的课程
|
|
|
+ List<CourseSchedule> courseSchedules = courseScheduleDao.findByCourseScheduleIds(adjustCourseScheduleIds);
|
|
|
+ courseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
+ if(adjustCourseScheduleIds.size()!=courseSchedules.size()){
|
|
|
+ throw new BizException("部分课程不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, CourseSchedule> idCourseMap = courseSchedules.stream().collect(Collectors.toMap(CourseSchedule::getId, c -> {
|
|
|
+ try {
|
|
|
+ return (CourseSchedule)org.apache.commons.beanutils.BeanUtils.cloneBean(c);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InstantiationException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (NoSuchMethodException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }));
|
|
|
+
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(courseAdjustInfo.getCourseCreateStartTime());
|
|
|
+ List<Date> courseStartDates = new ArrayList<>();
|
|
|
+
|
|
|
+ Set<String> holidayDays = new HashSet<>();
|
|
|
+
|
|
|
+ if (courseAdjustInfo.isHoliday()) {
|
|
|
+ SysConfig holidaySetting = sysConfigService.findByParamName(SysConfigService.HOLIDAY_SETTING);
|
|
|
+ if(StringUtils.isNotBlank(holidaySetting.getParanValue())){
|
|
|
+ holidayDays = new HashSet<>(JSON.parseArray(holidaySetting.getParanValue(), String.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<CourseSchedule>> result = new HashMap<String, List<CourseSchedule>>(){{
|
|
|
+ put("normal", new ArrayList<>());
|
|
|
+ put("revise", new ArrayList<>());
|
|
|
+ put("failed", new ArrayList<>());
|
|
|
+ }};
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ if (courseAdjustInfo.isHoliday() && holidayDays.contains(DateUtil.format(calendar.getTime(), "yyyy-MM-dd"))) {
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int i = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
+ if (i == 1) {
|
|
|
+ i = 7;
|
|
|
+ } else {
|
|
|
+ i = i - 1;
|
|
|
+ }
|
|
|
+ for (CourseTimeDto courseTime : courseAdjustInfo.getCourseTimes()) {
|
|
|
+ if (Objects.isNull(courseTime.getDayOfWeek())||StringUtils.isBlank(courseTime.getStartClassTime())) {
|
|
|
+ throw new BizException("排课循环周期错误");
|
|
|
+ }
|
|
|
+ if (courseTime.getDayOfWeek() < 1 || courseTime.getDayOfWeek() > 7) {
|
|
|
+ throw new BizException("排课循环周期错误");
|
|
|
+ }
|
|
|
+ if (courseTime.getDayOfWeek() == i) {
|
|
|
+ String dateYmdStr = DateUtil.dateToString(calendar.getTime(), DateUtil.ISO_EXPANDED_DATE_FORMAT);
|
|
|
+ dateYmdStr = dateYmdStr + " " + courseTime.getStartClassTime();
|
|
|
+ Date courseStartTime = DateUtil.stringToDate(dateYmdStr, "yyyy-MM-dd HH:mm");
|
|
|
+
|
|
|
+ if(courseStartTime.compareTo(now)<=0){
|
|
|
+ throw new BizException("课程调整时间不得小于当前时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ courseStartDates.add(DateUtil.stringToDate(dateYmdStr, DateUtil.EXPANDED_DATE_TIME_FORMAT));
|
|
|
+ CourseSchedule currentCourseSchedule = courseSchedules.get(courseStartDates.size() - 1);
|
|
|
+ int singleClassMinutes = DateUtil.minutesBetween(currentCourseSchedule.getStartClassTime(), currentCourseSchedule.getEndClassTime());
|
|
|
+ Date courseEndTime = DateUtil.addMinutes(courseStartTime, singleClassMinutes);
|
|
|
+ int settlementNum = courseScheduleTeacherSalaryDao.checkCourseIsSettlement(courseSchedules.get(courseStartDates.size() - 1).getId().intValue());
|
|
|
+ if (settlementNum > 0) {
|
|
|
+ throw new BizException("{}[{}]{}-{}课程已结算",
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).getName(),
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).getId(),
|
|
|
+ DateUtil.dateToString(courseSchedules.get(courseStartDates.size() - 1).getStartClassTime(),
|
|
|
+ DateUtil.ISO_EXPANDED_DATE_TIME_FORMAT),
|
|
|
+ DateUtil.dateToString(courseSchedules.get(courseStartDates.size() - 1).getEndClassTime(),
|
|
|
+ DateUtil.ISO_EXPANDED_DATE_TIME_FORMAT));
|
|
|
+ }
|
|
|
+ int num = studentAttendanceDao.countStudentAttendenceNum(courseSchedules.get(courseStartDates.size() - 1).getId().intValue());
|
|
|
+ if (num > 0) {
|
|
|
+ throw new BizException("{}[{}]{}-{}课程已点名",
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).getName(),
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).getId(),
|
|
|
+ DateUtil.dateToString(courseSchedules.get(courseStartDates.size() - 1).getStartClassTime(),
|
|
|
+ DateUtil.EXPANDED_DATE_TIME_FORMAT),
|
|
|
+ DateUtil.dateToString(courseSchedules.get(courseStartDates.size() - 1).getEndClassTime(),
|
|
|
+ DateUtil.EXPANDED_DATE_TIME_FORMAT));
|
|
|
+ }
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).setStatus(CourseStatusEnum.NOT_START);
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).setClassDate(courseStartTime);
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).setStartClassTime(courseStartTime);
|
|
|
+ courseSchedules.get(courseStartDates.size() - 1).setEndClassTime(courseEndTime);
|
|
|
+ }
|
|
|
+ if (courseStartDates.size() == adjustCourseScheduleIds.size()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (courseStartDates.size() == adjustCourseScheduleIds.size()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
+ }
|
|
|
+ for (CourseSchedule courseSchedule : courseSchedules) {
|
|
|
+ boolean b = checkSingleCourseConflict(courseSchedule, courseSchedules, result);
|
|
|
+ if(!b){
|
|
|
+ result.get("failed").add(idCourseMap.get(courseSchedule.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean courseTimeRevise(CourseSchedule courseSchedule, List<CourseSchedule> sameDayCourses) {
|
|
|
+ int singleClassMinutes = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
|
|
|
+ sameDayCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
+ Date lastEndClassTime = courseSchedule.getStartClassTime();
|
|
|
+
|
|
|
+ for (int i=0;i<sameDayCourses.size();i++){
|
|
|
+ CourseSchedule cs1 = sameDayCourses.get(i);
|
|
|
+ if(cs1.getEndClassTime().compareTo(lastEndClassTime)>=0){
|
|
|
+ lastEndClassTime = cs1.getEndClassTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(i!=sameDayCourses.size()-1&&DateUtil.minutesBetween(lastEndClassTime, sameDayCourses.get(i + 1).getStartClassTime())>=singleClassMinutes){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Date endClassTime = DateUtil.addMinutes(lastEndClassTime, singleClassMinutes);
|
|
|
+ if(!DateUtil.isSameDay(lastEndClassTime, endClassTime)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ courseSchedule.setStartClassTime(lastEndClassTime);
|
|
|
+ courseSchedule.setEndClassTime(endClassTime);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean checkSingleCourseConflict(CourseSchedule courseSchedule, List<CourseSchedule> adjustCourses, Map<String, List<CourseSchedule>> result) {
|
|
|
+ if(!DateUtil.isSameDay(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime())){
|
|
|
+ throw new BizException("课程时间不允许跨天");
|
|
|
+ }
|
|
|
+ List<CourseSchedule> allCourseSchedules = courseScheduleDao.findByClassDate(Arrays.asList(DateUtil.dateToString(courseSchedule.getClassDate(), "yyyy-MM-dd")));
|
|
|
+
|
|
|
+ if(null == allCourseSchedules){
|
|
|
+ allCourseSchedules = new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<CourseSchedule> adjustCourseTemp = adjustCourses.stream().filter(c -> DateUtil.isSameDay(c.getClassDate(), courseSchedule.getClassDate())).collect(Collectors.toList());
|
|
|
+ Set<Long> adjustCourseIds = adjustCourseTemp.stream().map(CourseSchedule::getId).collect(Collectors.toSet());
|
|
|
+ allCourseSchedules= (List<CourseSchedule>) org.apache.commons.collections.CollectionUtils.union(allCourseSchedules.stream()
|
|
|
+ .filter(c->!adjustCourseIds.contains(c.getId())).collect(Collectors.toList()),
|
|
|
+ adjustCourseTemp);
|
|
|
+
|
|
|
+ Map<Long, CourseSchedule> idCourseMap = allCourseSchedules.stream().collect(Collectors.toMap(CourseSchedule::getId, c -> c));
|
|
|
+ Set<Long> courseScheduleIds = allCourseSchedules.stream().map(CourseSchedule::getId).collect(Collectors.toSet());
|
|
|
+ courseScheduleIds.add(courseSchedule.getId());
|
|
|
+ List<CourseScheduleStudentPayment> courseScheduleStudentPayments = courseScheduleStudentPaymentDao.findByCourseScheduleIds(new ArrayList<>(courseScheduleIds));
|
|
|
+ Map<Long, Set<Integer>> courseStudentIdsMap = courseScheduleStudentPayments.stream()
|
|
|
+ .collect(Collectors.groupingBy(CourseScheduleStudentPayment::getCourseScheduleId,
|
|
|
+ Collectors.mapping(CourseScheduleStudentPayment::getUserId, Collectors.toSet())));
|
|
|
+
|
|
|
+ List<CourseScheduleTeacherSalary> courseScheduleTeacherSalaries = courseScheduleTeacherSalaryDao.findByCourseSchedules(new ArrayList<>(courseScheduleIds));
|
|
|
+ Map<Long, Set<Integer>> courseTeacherIdsMap = courseScheduleTeacherSalaries.stream()
|
|
|
+ .collect(Collectors.groupingBy(CourseScheduleTeacherSalary::getCourseScheduleId,
|
|
|
+ Collectors.mapping(CourseScheduleTeacherSalary::getUserId, Collectors.toSet())));
|
|
|
+ Set<Integer> currentCourseTeacherIds = courseTeacherIdsMap.get(courseSchedule.getId());
|
|
|
+
|
|
|
+ List<StudentAttendance> studentAttendances = studentAttendanceDao.findByCourseIds(new ArrayList<>(courseScheduleIds));
|
|
|
+ Map<Long, Set<Integer>> courseLeaveStudentIdsMap = new HashMap<>();
|
|
|
+ for (StudentAttendance sa : studentAttendances) {
|
|
|
+ if(sa.getCourseScheduleId().equals(courseSchedule.getId())&&!StudentAttendanceStatusEnum.LEAVE.equals(sa.getStatus())){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(!courseLeaveStudentIdsMap.containsKey(sa.getCourseScheduleId())){
|
|
|
+ courseLeaveStudentIdsMap.put(sa.getCourseScheduleId(), Collections.EMPTY_SET);
|
|
|
+ }
|
|
|
+ CourseSchedule cs = idCourseMap.get(sa.getCourseScheduleId());
|
|
|
+ if(DateUtil.addHours(sa.getCreateTime(),4).compareTo(cs.getStartClassTime())<0){
|
|
|
+ courseLeaveStudentIdsMap.get(sa.getCourseScheduleId()).add(sa.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Set<Integer> currentCourseLeaveStudentIds = courseLeaveStudentIdsMap.get(courseSchedule.getId());
|
|
|
+ Set<Integer> currentCourseStudentIds = courseStudentIdsMap.get(courseSchedule.getId())
|
|
|
+ .stream().filter(id->Objects.nonNull(currentCourseLeaveStudentIds)&&!currentCourseLeaveStudentIds.contains(id)).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ boolean isRepeat = false;
|
|
|
+ List<CourseSchedule> repeatCourses = new ArrayList<>();
|
|
|
+
|
|
|
+ allCourseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
+ for (CourseSchedule cs : allCourseSchedules) {
|
|
|
+ if(cs.getId().equals(courseSchedule.getId())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cs.getStartClassTime().compareTo(courseSchedule.getEndClassTime())>0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cs.getEndClassTime().compareTo(courseSchedule.getStartClassTime())<0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断两节课程时间是否重叠
|
|
|
+ if (!cs.getStartClassTime().before(courseSchedule.getEndClassTime())
|
|
|
+ ||!cs.getEndClassTime().after(courseSchedule.getStartClassTime())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> csLeaveStudentIds = courseLeaveStudentIdsMap.get(cs.getId());
|
|
|
+ Set<Integer> repeatStudentIds = new HashSet<>();
|
|
|
+ if(null!=csLeaveStudentIds){
|
|
|
+ Set<Integer> csStudentIds = courseStudentIdsMap.get(cs.getId()).stream()
|
|
|
+ .filter(id->Objects.nonNull(csLeaveStudentIds)&&!csLeaveStudentIds.contains(id)).collect(Collectors.toSet());
|
|
|
+ repeatStudentIds = csStudentIds.stream().filter(id -> currentCourseStudentIds.contains(id)).collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> csTeacherIds = courseTeacherIdsMap.get(cs.getId());
|
|
|
+ Set<Integer> repeatTeacherIds = new HashSet<>();
|
|
|
+ if(null!=csTeacherIds){
|
|
|
+ repeatTeacherIds = csTeacherIds.stream().filter(id -> Objects.nonNull(currentCourseTeacherIds)&¤tCourseTeacherIds.contains(id)).collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!CollectionUtils.isEmpty(repeatStudentIds)||!CollectionUtils.isEmpty(repeatTeacherIds)){
|
|
|
+ isRepeat = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(isRepeat){
|
|
|
+ for (CourseSchedule cs : allCourseSchedules) {
|
|
|
+ if(cs.getId().equals(courseSchedule.getId())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> csLeaveStudentIds = courseLeaveStudentIdsMap.get(cs.getId());
|
|
|
+ Set<Integer> repeatStudentIds = new HashSet<>();
|
|
|
+ if(null!=csLeaveStudentIds){
|
|
|
+ Set<Integer> csStudentIds = courseStudentIdsMap.get(cs.getId()).stream()
|
|
|
+ .filter(id->Objects.nonNull(csLeaveStudentIds)&&!csLeaveStudentIds.contains(id)).collect(Collectors.toSet());
|
|
|
+ repeatStudentIds = csStudentIds.stream().filter(id -> currentCourseStudentIds.contains(id)).collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> csTeacherIds = courseTeacherIdsMap.get(cs.getId());
|
|
|
+ Set<Integer> repeatTeacherIds = new HashSet<>();
|
|
|
+ if(null!=csTeacherIds){
|
|
|
+ repeatTeacherIds = csTeacherIds.stream().filter(id -> Objects.nonNull(currentCourseTeacherIds)&¤tCourseTeacherIds.contains(id)).collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(repeatStudentIds)||!CollectionUtils.isEmpty(repeatTeacherIds)){
|
|
|
+ repeatCourses.add(cs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ boolean b = courseTimeRevise(courseSchedule, repeatCourses);
|
|
|
+ if(b){
|
|
|
+ result.get("revise").add(courseSchedule);
|
|
|
+ }
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ result.get("normal").add(courseSchedule);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void checkNewCourseSchedules(List<CourseSchedule> courseSchedules, boolean checkExistCourseSchedule) {
|
|
|
if (CollectionUtils.isEmpty(courseSchedules)) {
|
|
|
return;
|
|
@@ -1404,200 +1724,6 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void checkAllCourseSchedules(List<CourseSchedule> courseSchedules, boolean checkExistCourseSchedule) {
|
|
|
- if (CollectionUtils.isEmpty(courseSchedules)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<String> classDates = courseSchedules.stream().map(courseSchedule -> DateUtil.dateToString(courseSchedule.getClassDate(), "yyyy-MM-dd"))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- List<CourseSchedule> existCourseSchedules = courseScheduleDao.findByClassDate(classDates);
|
|
|
-
|
|
|
- //只需要调整课程信息的课程编号列表
|
|
|
- List<Long> updateCourseScheduleIds = courseSchedules
|
|
|
- .stream()
|
|
|
- .filter(courseSchedule -> Objects.nonNull(courseSchedule.getId()))
|
|
|
- .map(CourseSchedule::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- //排除只需调整的课程
|
|
|
- existCourseSchedules = existCourseSchedules.stream()
|
|
|
- .filter(courseSchedule -> !updateCourseScheduleIds.contains(courseSchedule.getId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- //新课程对应的班级编号列表
|
|
|
- List<Integer> newCourseScheduleClassGroupIds = courseSchedules
|
|
|
- .stream()
|
|
|
- .map(CourseSchedule::getClassGroupId)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- List<Long> existCourseScheduleIds = existCourseSchedules.stream()
|
|
|
- .map(CourseSchedule::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- HashSet<Long> courseScheduleIdsSet = new HashSet<>(existCourseScheduleIds);
|
|
|
-
|
|
|
- //合并新课程和已存在的课程
|
|
|
- List<CourseSchedule> allCourseSchedules;
|
|
|
- if (!CollectionUtils.isEmpty(existCourseSchedules)) {
|
|
|
- allCourseSchedules = ListUtils.sum(courseSchedules, existCourseSchedules);
|
|
|
- } else {
|
|
|
- allCourseSchedules = courseSchedules;
|
|
|
- }
|
|
|
-
|
|
|
- //所有课程编号
|
|
|
- List<Long> allCourseScheduleIds = allCourseSchedules.stream().map(CourseSchedule::getId).collect(Collectors.toList());
|
|
|
- //所有课程学员签到记录
|
|
|
- List<StudentAttendance> studentAttendances = studentAttendanceDao.findByCourseIds(allCourseScheduleIds);
|
|
|
- //课程请假学员字典
|
|
|
- Map<Long, Set<Integer>> courseLeaveStudentMap = studentAttendances.stream()
|
|
|
- .filter(e -> StudentAttendanceStatusEnum.LEAVE.equals(e.getStatus()))
|
|
|
- .collect(Collectors.groupingBy(StudentAttendance::getCourseScheduleId, Collectors.mapping(StudentAttendance::getUserId, Collectors.toSet())));
|
|
|
-
|
|
|
- //所有课程的班级编号
|
|
|
- List<Integer> classGroupIds = allCourseSchedules
|
|
|
- .stream()
|
|
|
- .map(CourseSchedule::getClassGroupId)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- //班级与学生的关联记录
|
|
|
- List<ClassGroupStudentMapper> classGroupStudentMappers = classGroupStudentMapperDao.findByClassGroups(classGroupIds);
|
|
|
- Map<Integer, List<ClassGroupStudentMapper>> classGroupStudentsMap = classGroupStudentMappers
|
|
|
- .stream()
|
|
|
- .collect(Collectors.groupingBy(ClassGroupStudentMapper::getClassGroupId));
|
|
|
-
|
|
|
- //根据课程获取助教id关联集合
|
|
|
- List<IntegerAndIntegerListDto> courseScheduleTeachingTeacherIdList = new ArrayList<>();
|
|
|
- if (!CollectionUtils.isEmpty(existCourseScheduleIds)) {
|
|
|
- courseScheduleTeachingTeacherIdList = courseScheduleDao.findCourseScheduleIdAndUserIdsMap(existCourseScheduleIds, TeachTypeEnum.TEACHING.getCode());
|
|
|
- }
|
|
|
- Map<Integer, IntegerAndIntegerListDto> courseScheduleTeachingTeacherMap = courseScheduleTeachingTeacherIdList.stream()
|
|
|
- .collect(Collectors.toMap(IntegerAndIntegerListDto::getId, integerAndIntegerListDto -> integerAndIntegerListDto));
|
|
|
-
|
|
|
- //班级助教关联ID集合
|
|
|
- List<IntegerAndIntegerListDto> classGroupAndUserIdsMap = courseScheduleDao.findClassGroupAndUserIdsMap(newCourseScheduleClassGroupIds, TeachTypeEnum.TEACHING.getCode());
|
|
|
- Map<Integer, IntegerAndIntegerListDto> classGroupTeachingTeacherMap = classGroupAndUserIdsMap.stream()
|
|
|
- .collect(Collectors.toMap(IntegerAndIntegerListDto::getId, integerAndIntegerListDto -> integerAndIntegerListDto));
|
|
|
-
|
|
|
- Set<Long> existCourseScheduleIdsSet=new HashSet<>(existCourseScheduleIds);
|
|
|
-
|
|
|
- Map<String, List<CourseSchedule>> existClassDateCoursesMap = allCourseSchedules.stream().collect(Collectors.groupingBy(c -> DateUtil.dateToString(c.getClassDate(), "yyyy-MM-dd")));
|
|
|
- Map<String, List<CourseSchedule>> newClassDateCoursesMap = courseSchedules.stream().collect(Collectors.groupingBy(c -> DateUtil.dateToString(c.getClassDate(), "yyyy-MM-dd")));
|
|
|
- if (allCourseSchedules.size() > 1) {
|
|
|
- for (Map.Entry<String, List<CourseSchedule>> classDateCourseEntry : newClassDateCoursesMap.entrySet()) {
|
|
|
- List<CourseSchedule> existClassDateCourses = existClassDateCoursesMap.get(classDateCourseEntry.getKey());
|
|
|
- if(CollectionUtils.isEmpty(existClassDateCourses)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<CourseSchedule> newClassDateCourses=classDateCourseEntry.getValue();
|
|
|
- existClassDateCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
- newClassDateCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
- for (CourseSchedule preCourseSchedule : newClassDateCourses) {
|
|
|
- for (CourseSchedule backCourseSchedule : existClassDateCourses) {
|
|
|
-
|
|
|
- //判断前后两节课是否存在冲突
|
|
|
- if (!preCourseSchedule.getStartClassTime().before(backCourseSchedule.getEndClassTime())
|
|
|
- ||!preCourseSchedule.getEndClassTime().after(backCourseSchedule.getStartClassTime())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!checkExistCourseSchedule
|
|
|
- && !courseScheduleIdsSet.contains(backCourseSchedule.getId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //如果存在时间重叠,则需要判断前后两节课的教师和学生是否存在冲突
|
|
|
- //主教冲突检测
|
|
|
- if (Objects.nonNull(preCourseSchedule.getActualTeacherId())
|
|
|
- && preCourseSchedule.getActualTeacherId().equals(backCourseSchedule.getActualTeacherId())) {
|
|
|
-
|
|
|
- throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 1));
|
|
|
- }
|
|
|
-
|
|
|
- if(Objects.isNull(preCourseSchedule.getId())){
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //助教冲突检测
|
|
|
- if (Objects.isNull(preCourseSchedule.getId())) {
|
|
|
- IntegerAndIntegerListDto integerAndIntegerListDto = classGroupTeachingTeacherMap.get(preCourseSchedule.getClassGroupId());
|
|
|
- if (Objects.nonNull(integerAndIntegerListDto)) {
|
|
|
- preCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
|
|
|
- }
|
|
|
- } else if (existCourseScheduleIdsSet.contains(preCourseSchedule.getId())) {
|
|
|
- IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeachingTeacherMap.get(preCourseSchedule.getId());
|
|
|
- if (Objects.nonNull(integerAndIntegerListDto)) {
|
|
|
- preCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
|
|
|
- }
|
|
|
- }
|
|
|
- if (Objects.isNull(backCourseSchedule.getId())) {
|
|
|
- IntegerAndIntegerListDto integerAndIntegerListDto = classGroupTeachingTeacherMap.get(backCourseSchedule.getClassGroupId());
|
|
|
- if (Objects.nonNull(integerAndIntegerListDto)) {
|
|
|
- backCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
|
|
|
- }
|
|
|
- } else if (existCourseScheduleIdsSet.contains(backCourseSchedule.getId())) {
|
|
|
- IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeachingTeacherMap.get(backCourseSchedule.getId());
|
|
|
- if (Objects.nonNull(integerAndIntegerListDto)) {
|
|
|
- backCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
|
|
|
- }
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(preCourseSchedule.getTeachingTeacherIdList())
|
|
|
- && !CollectionUtils.isEmpty(backCourseSchedule.getTeachingTeacherIdList())) {
|
|
|
- List<Integer> repeatIds = preCourseSchedule.getTeachingTeacherIdList()
|
|
|
- .stream().filter(backCourseSchedule.getTeachingTeacherIdList()::contains)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!CollectionUtils.isEmpty(repeatIds)) {
|
|
|
- throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 2));
|
|
|
- }
|
|
|
- }
|
|
|
- //学生冲突检测
|
|
|
- if (preCourseSchedule.getClassGroupId().equals(backCourseSchedule.getClassGroupId())) {
|
|
|
- //如果班级相同,则学生肯定存在冲突
|
|
|
- throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 3));
|
|
|
- }
|
|
|
- //如果班级不同,则需要检测两个班级是否存在重复的学生
|
|
|
- List<ClassGroupStudentMapper> preClassGroupStudents = classGroupStudentsMap.get(preCourseSchedule.getClassGroupId());
|
|
|
- List<ClassGroupStudentMapper> backClassGroupStudents = classGroupStudentsMap.get(backCourseSchedule.getClassGroupId());
|
|
|
- //如果有一个存在没有学生的班级则不存在冲突
|
|
|
- if (CollectionUtils.isEmpty(preClassGroupStudents) || CollectionUtils.isEmpty(backClassGroupStudents)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- //课程对应请假学员编号集合
|
|
|
- Set<Integer> preLeaveStudentIds = courseLeaveStudentMap.get(preCourseSchedule.getId());
|
|
|
- if(null == preLeaveStudentIds){
|
|
|
- preLeaveStudentIds = Collections.EMPTY_SET;
|
|
|
- }
|
|
|
- Set<Integer> backLeaveStudentIds = courseLeaveStudentMap.get(backCourseSchedule.getId());
|
|
|
- if(null == backLeaveStudentIds){
|
|
|
- backLeaveStudentIds = Collections.EMPTY_SET;
|
|
|
- }
|
|
|
-
|
|
|
- //当前课程所在班级的学生编号列表
|
|
|
- Set<Integer> finalPreLeaveStudentIds = preLeaveStudentIds;
|
|
|
- List<Integer> preClassGroupStudentIds = preClassGroupStudents.stream()
|
|
|
- .filter(e->!finalPreLeaveStudentIds.contains(e.getUserId()))
|
|
|
- .map(ClassGroupStudentMapper::getUserId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- //后面一节课程所在班级的学生编号列表
|
|
|
- Set<Integer> finalBackLeaveStudentIds = backLeaveStudentIds;
|
|
|
- Set<Integer> backClassGroupStudentIds = backClassGroupStudents.stream()
|
|
|
- .filter(e->!finalBackLeaveStudentIds.contains(e.getUserId()))
|
|
|
- .map(ClassGroupStudentMapper::getUserId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- List<Integer> repeatStudentIds = preClassGroupStudentIds.stream()
|
|
|
- .filter(backClassGroupStudentIds::contains)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!CollectionUtils.isEmpty(repeatStudentIds)) {
|
|
|
- throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 3));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void checkNewCourseSchedulesWithoutMusicGroup(List<CourseSchedule> courseSchedules, boolean checkExistCourseSchedule) {
|
|
|
if (CollectionUtils.isEmpty(courseSchedules)) {
|
|
@@ -1922,11 +2048,11 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
|
|
|
}
|
|
|
|
|
|
if (existCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode()) || existCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.VIP.getCode())) {
|
|
|
- throw new BizException(courseCheckInfo(newCourseSchedule, existCourseSchedule, existCourseScheduleIds, 1));
|
|
|
+ throw new BizException(courseCheckInfo(newCourseSchedule, existCourseSchedule, existCourseScheduleIds, isTeacherRepeat?1:3));
|
|
|
}
|
|
|
|
|
|
if (!existCourseSchedule.getGroupType().equals(newCourseSchedule.getGroupType()) || !existCourseSchedule.getMusicGroupId().equals(newCourseSchedule.getMusicGroupId())) {
|
|
|
- throw new BizException(courseCheckInfo(newCourseSchedule, existCourseSchedule, existCourseScheduleIds, 1));
|
|
|
+ throw new BizException(courseCheckInfo(newCourseSchedule, existCourseSchedule, existCourseScheduleIds, isTeacherRepeat?1:3));
|
|
|
}
|
|
|
|
|
|
if (isTeacherRepeat) {
|