Sfoglia il codice sorgente

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 anni fa
parent
commit
6e495fd1ed

+ 6 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleDao.java

@@ -620,6 +620,8 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
 
     List<CourseSchedule> findByClassDate(@Param("classDates") List<String> classDates);
 
+    List<CourseSchedule> findByClassDateWithoutMusicGroup(@Param("classDates") List<String> classDates);
+
     /**
      * @param startTime: 开始时间
      * @param endTime:   结束时间
@@ -1097,6 +1099,10 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
                                                          @Param("startTime") Date startTime,
                                                          @Param("endTime") Date endTime);
 
+    List<CourseSchedule> findTeacherCoursesWithDateRangeWithoutMusicGroup(@Param("userId") Integer userId,
+                                                         @Param("startTime") Date startTime,
+                                                         @Param("endTime") Date endTime);
+
     /**
      * @param userId: 用户编号
      * @return java.util.List<com.ym.mec.biz.dal.dto.CourseScheduleDto>

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleService.java

@@ -228,6 +228,8 @@ public interface CourseScheduleService extends BaseService<Long, CourseSchedule>
 	 */
 	void checkNewCourseSchedules(List<CourseSchedule> courseSchedules,boolean checkExistCourseSchedule);
 
+	void checkNewCourseSchedulesWithoutMusicGroup(List<CourseSchedule> courseSchedules,boolean checkExistCourseSchedule);
+
 	/**
 	 * @describe 临时课检测
 	 * @author Joburgess

+ 164 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -865,6 +865,169 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
     }
 
     @Override
+    public void checkNewCourseSchedulesWithoutMusicGroup(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.findByClassDateWithoutMusicGroup(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<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())) {
+                            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;
+                        }
+                        //当前课程所在班级的学生编号列表
+                        List<Integer> preClassGroupStudentIds = preClassGroupStudents.stream()
+                                .map(ClassGroupStudentMapper::getUserId)
+                                .collect(Collectors.toList());
+                        //后面一节课程所在班级的学生编号列表
+                        Set<Integer> backClassGroupStudentIds = backClassGroupStudents.stream()
+                                .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
     @Transactional(rollbackFor = Exception.class)
     public List<Long> checkSnapCourseShchedules(List<CourseSchedule> courseSchedules) {
         List<Long> courseScheduleIds = new ArrayList<>();
@@ -1479,7 +1642,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
             scheduleModifyLog.setCurrentCourseSchedule(JSONObject.toJSONString(courseSchedule));
             scheduleModifyLogs.add(scheduleModifyLog);
         }
-//        checkNewCourseSchedules(classGroupCourseSchedulesWithDate,false);
+        checkNewCourseSchedules(classGroupCourseSchedulesWithDate,false);
         courseScheduleDao.batchUpdate(classGroupCourseSchedulesWithDate);
         courseScheduleModifyLogDao.batchInsert(scheduleModifyLogs);
     }

+ 4 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PracticeGroupServiceImpl.java

@@ -2408,7 +2408,8 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         Date secondSunday = DateUtil.getWeekDayWithDate(applyEndDate, Calendar.SUNDAY);
 
         Map<Integer, List<String>> weekNumApplyTimesMap = getEnableApplyDatesWithWeek();
-        List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(teacherId, firstMonday, secondSunday);
+//        List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(teacherId, firstMonday, secondSunday);
+        List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRangeWithoutMusicGroup(teacherId, firstMonday, secondSunday);
         allTeacherCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
 
         JSONObject teacherLeaveData = null;
@@ -2860,7 +2861,8 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         teacherAttendanceDao.batchInsert(teacherAttendances);
 
         try {
-            courseScheduleService.checkNewCourseSchedules(practiceCourses,false);
+//            courseScheduleService.checkNewCourseSchedules(practiceCourses,false);
+            courseScheduleService.checkNewCourseSchedulesWithoutMusicGroup(practiceCourses,false);
         } catch (Exception e) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             String errMessage=new String();

+ 7 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -285,8 +286,12 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         List<StudentPaymentOrder> dataList = new ArrayList<>();
         int count = this.findCount(params);
         StudentPaymentOrder orderMoneyAmount = studentPaymentOrderDao.getOrderMoneyAmount(params);
-        pageInfo.setTotalExpectAmount(orderMoneyAmount.getExpectAmount());
-        pageInfo.setTotalActualAmount(orderMoneyAmount.getActualAmount());
+        if(orderMoneyAmount != null){
+            BigDecimal totalExpectAmount = orderMoneyAmount.getExpectAmount() !=null? orderMoneyAmount.getExpectAmount():BigDecimal.ZERO;
+            BigDecimal totalActualAmount = orderMoneyAmount.getActualAmount() !=null? orderMoneyAmount.getActualAmount():BigDecimal.ZERO;
+            pageInfo.setTotalExpectAmount(totalExpectAmount);
+            pageInfo.setTotalActualAmount(totalActualAmount);
+        }
         if (count > 0) {
             pageInfo.setTotal(count);
             params.put("offset", pageInfo.getOffset());

+ 37 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -1493,6 +1493,28 @@
         AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
     </select>
 
+    <select id="findByClassDateWithoutMusicGroup" resultMap="CourseSchedule">
+        SELECT
+        cs.id_,
+        cs.music_group_id_,
+        cs.class_group_id_,
+        cs.class_date_,
+        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
+        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
+        cs.type_,
+        cs.name_,
+        cs.actual_teacher_id_
+        FROM
+        course_schedule cs
+        WHERE
+        cs.group_type_!='MUSIC'
+        AND (cs.class_date_ IN
+        <foreach collection="classDates" item="classDate" open="(" close=")" separator=",">
+            #{classDate}
+        </foreach>
+        )
+        AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
+    </select>
 
     <select id="findAllCourseByDateZone2" resultMap="CourseSchedule">
         SELECT cs.id_,
@@ -2271,6 +2293,21 @@
           AND cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, "%Y-%m-%d") AND DATE_FORMAT(#{endTime}, "%Y-%m-%d")
           AND csts.user_id_ = #{userId}
     </select>
+
+    <select id="findTeacherCoursesWithDateRangeWithoutMusicGroup" resultMap="CourseSchedule">
+        SELECT cs.id_,
+               cs.class_date_,
+               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
+               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
+               csts.user_id_                                     actual_teacher_id_,
+               cs.group_type_
+        FROM course_schedule_teacher_salary csts
+                 LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
+        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
+          AND cs.group_type_!='MUSIC'
+          AND cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, "%Y-%m-%d") AND DATE_FORMAT(#{endTime}, "%Y-%m-%d")
+          AND csts.user_id_ = #{userId}
+    </select>
     <select id="findStudentPracticeCourses" resultMap="courseScheduleDto">
         SELECT cs.id_                                            seal_class_id_,
                cs.type_,