Sfoglia il codice sorgente

1、服务指标导出增加作业提交时间;

Joburgess 5 anni fa
parent
commit
2c082653ef

+ 13 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentDao.java

@@ -74,6 +74,14 @@ public interface StudentDao extends com.ym.mec.common.dal.BaseDAO<Integer, Stude
     List<Student> getServiceStudents();
 
     /**
+     * @describe 获取被服务学员id列表
+     * @author Joburgess
+     * @date 2020.06.04
+     * @return java.util.List<java.lang.Integer>
+     */
+    List<Integer> getServeStudentIds();
+
+    /**
      * @describe 查询被服务学员信息
      * @author Joburgess
      * @date 2020.05.27
@@ -83,6 +91,11 @@ public interface StudentDao extends com.ym.mec.common.dal.BaseDAO<Integer, Stude
     List<StudentServeDto> getBeServiceStudents(@Param("monday") String monday,
                                                @Param("courseExpireDate")Date courseExpireDate);
 
+
+    List<StudentServeDto> getBeServiceStudentsInfoWithStudents(@Param("monday") String monday,
+                                               @Param("courseExpireDate")Date courseExpireDate,
+                                               @Param("studentIds") List<Integer> studentIds);
+
     /**
      * @describe 更新指定学员的服务指标或运营指标
      * @author Joburgess

+ 134 - 130
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentServeServiceImpl.java

@@ -61,164 +61,168 @@ public class StudentServeServiceImpl implements StudentServeService {
         LocalDate sunDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
         Date nextMonday = Date.from(sunDayDate.plusDays(1).atStartOfDay(DateUtil.zoneId).toInstant());
 
-        List<StudentServeDto> serviceStudents = studentDao.getBeServiceStudents(monDayDate.toString(), sunDayDate.isBefore(LocalDate.now())?nextMonday:new Date());
-        if(CollectionUtils.isEmpty(serviceStudents)){
-            return;
-        }
+        List<Integer> beServeStudentIds=studentDao.getServeStudentIds();
+        BigDecimal currentPage=BigDecimal.ONE,
+                pageSize=new BigDecimal(1000),
+                total=new BigDecimal(beServeStudentIds.size()),
+                totalPage=total.divide(pageSize, BigDecimal.ROUND_UP);
 
-        Map<Integer, List<StudentServeDto>> studentCoursesMap = serviceStudents.stream().collect(Collectors.groupingBy(StudentServeDto::getUserId));
+        studentExtracurricularExercisesSituationDao.deleteByMonday(monDayDate.toString());
 
-        //本周不服务学员列表
-        Set<Integer> dontServeInCurrentWeekStudentIds=new HashSet<>();
-        //本周有课学员编号集合
-        Set<Integer> haveClassStudentIds=new HashSet<>();
-        //本周无课学员编号集合
-        Set<Integer> noClassStudentIds=new HashSet<>();
-        for (Map.Entry<Integer, List<StudentServeDto>> studentCoursesEntry : studentCoursesMap.entrySet()) {
+        while (currentPage.compareTo(totalPage)<=0){
+            List<Integer> studentIds=beServeStudentIds.stream().skip(pageSize.multiply(currentPage.subtract(BigDecimal.ONE)).longValue()).limit(pageSize.longValue()).collect(Collectors.toList());
 
-            List<StudentServeDto> haveCourseStudents = studentCoursesEntry.getValue().stream().filter(e -> Objects.nonNull(e.getCourseStartTime())).collect(Collectors.toList());
-            if(CollectionUtils.isEmpty(haveCourseStudents)){
-                noClassStudentIds.add(studentCoursesEntry.getKey());
-                continue;
-            }
-            StudentServeDto studentServeDto = haveCourseStudents.stream().min(Comparator.comparing(StudentServeDto::getCourseStartTime)).get();
-            if(Objects.isNull(studentServeDto.getCourseStartTime())){
-                noClassStudentIds.add(studentCoursesEntry.getKey());
-                continue;
+            List<StudentServeDto> serviceStudents = studentDao.getBeServiceStudentsInfoWithStudents(monDayDate.toString(), sunDayDate.isBefore(LocalDate.now())?nextMonday:new Date(),studentIds);
+            if(CollectionUtils.isEmpty(serviceStudents)){
+                return;
             }
-            if(!studentServeDto.getCourseStartTime().before(nextMonday)){
-                dontServeInCurrentWeekStudentIds.add(studentCoursesEntry.getKey());
-                continue;
-            }
-            long count = haveCourseStudents.stream().filter(e -> (GroupType.PRACTICE.equals(e.getGroupType()) ||
-                    (GroupType.MUSIC.equals(e.getGroupType()) && TeachModeEnum.OFFLINE.equals(e.getTeachMode())))
-                    &&nextMonday.after(e.getCourseStartTime())).count();
-            if(count>0){
-                haveClassStudentIds.add(studentCoursesEntry.getKey());
-            }else{
-                noClassStudentIds.add(studentCoursesEntry.getKey());
-            }
-        }
 
-        Set<Integer> allServeStudentIds=new HashSet<>();
-        allServeStudentIds.addAll(haveClassStudentIds);
-        allServeStudentIds.addAll(noClassStudentIds);
+            Map<Integer, List<StudentServeDto>> studentCoursesMap = serviceStudents.stream().collect(Collectors.groupingBy(StudentServeDto::getUserId));
 
-        Map<Integer, List<StudentServeCourseHomeworkDto>> studentHomeworkMap=new HashMap<>();
-        Map<Integer, List<ExtracurricularExercisesReply>> studentExercisesMap=new HashMap<>();
+            //本周不服务学员列表
+            Set<Integer> dontServeInCurrentWeekStudentIds=new HashSet<>();
+            //本周有课学员编号集合
+            Set<Integer> haveClassStudentIds=new HashSet<>();
+            //本周无课学员编号集合
+            Set<Integer> noClassStudentIds=new HashSet<>();
+            for (Map.Entry<Integer, List<StudentServeDto>> studentCoursesEntry : studentCoursesMap.entrySet()) {
 
-        if (!CollectionUtils.isEmpty(allServeStudentIds)){
-            List<StudentServeCourseHomeworkDto> studentHomeworks = studentCourseHomeworkDao.findStudentHomeworkWithCourseDateRange(monDayDate.toString(), sunDayDate.toString(), new ArrayList<>(allServeStudentIds));
-            studentHomeworkMap = studentHomeworks.stream().filter(h -> DateUtil.daysBetween(h.getCourseStartTime(), h.getHomeworkCreateTime())<3).collect(Collectors.groupingBy(StudentServeCourseHomeworkDto::getUserId));
-        }
+                List<StudentServeDto> haveCourseStudents = studentCoursesEntry.getValue().stream().filter(e -> Objects.nonNull(e.getCourseStartTime())).collect(Collectors.toList());
+                if(CollectionUtils.isEmpty(haveCourseStudents)){
+                    noClassStudentIds.add(studentCoursesEntry.getKey());
+                    continue;
+                }
+                StudentServeDto studentServeDto = haveCourseStudents.stream().min(Comparator.comparing(StudentServeDto::getCourseStartTime)).get();
+                if(Objects.isNull(studentServeDto.getCourseStartTime())){
+                    noClassStudentIds.add(studentCoursesEntry.getKey());
+                    continue;
+                }
+                if(!studentServeDto.getCourseStartTime().before(nextMonday)){
+                    dontServeInCurrentWeekStudentIds.add(studentCoursesEntry.getKey());
+                    continue;
+                }
+                long count = haveCourseStudents.stream().filter(e -> (GroupType.PRACTICE.equals(e.getGroupType()) ||
+                        (GroupType.MUSIC.equals(e.getGroupType()) && TeachModeEnum.OFFLINE.equals(e.getTeachMode())))
+                        &&nextMonday.after(e.getCourseStartTime())).count();
+                if(count>0){
+                    haveClassStudentIds.add(studentCoursesEntry.getKey());
+                }else{
+                    noClassStudentIds.add(studentCoursesEntry.getKey());
+                }
+            }
 
-        if(!CollectionUtils.isEmpty(allServeStudentIds)){
-            List<ExtracurricularExercisesReply> studentExercises = extracurricularExercisesReplyDao.getStudentExercisesWithTimeZone(monDayDate.toString(), sunDayDate.toString(), new ArrayList<>(allServeStudentIds));
-            studentExercisesMap = studentExercises.stream().collect(Collectors.groupingBy(ExtracurricularExercisesReply::getUserId));
-        }
+            Set<Integer> allServeStudentIds=new HashSet<>();
+            allServeStudentIds.addAll(haveClassStudentIds);
+            allServeStudentIds.addAll(noClassStudentIds);
 
-        List<StudentExtracurricularExercisesSituation> results=new ArrayList<>();
-        for (Map.Entry<Integer, List<StudentServeDto>> studentCoursesEntry : studentCoursesMap.entrySet()) {
+            Map<Integer, List<StudentServeCourseHomeworkDto>> studentHomeworkMap=new HashMap<>();
+            Map<Integer, List<ExtracurricularExercisesReply>> studentExercisesMap=new HashMap<>();
 
-            if(dontServeInCurrentWeekStudentIds.contains(studentCoursesEntry.getKey())){
-                continue;
+            if (!CollectionUtils.isEmpty(allServeStudentIds)){
+                List<StudentServeCourseHomeworkDto> studentHomeworks = studentCourseHomeworkDao.findStudentHomeworkWithCourseDateRange(monDayDate.toString(), sunDayDate.toString(), new ArrayList<>(allServeStudentIds));
+                studentHomeworkMap = studentHomeworks.stream().filter(h -> DateUtil.daysBetween(h.getCourseStartTime(), h.getHomeworkCreateTime())<3).collect(Collectors.groupingBy(StudentServeCourseHomeworkDto::getUserId));
             }
 
-            StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation();
-            studentExtracurricularExercisesSituation.setStudentId(studentCoursesEntry.getKey());
-            studentExtracurricularExercisesSituation.setTeacherId(studentCoursesEntry.getValue().get(0).getTeacherId());
-            studentExtracurricularExercisesSituation.setExpectExercisesNum(1);
-            studentExtracurricularExercisesSituation.setActualExercisesNum(0);
-            studentExtracurricularExercisesSituation.setExercisesReplyNum(0);
-            studentExtracurricularExercisesSituation.setExercisesMessageNum(0);
-            studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(0);
-            studentExtracurricularExercisesSituation.setWeekOfYear(nowDate.get(DateUtil.weekFields.weekOfYear()));
-            studentExtracurricularExercisesSituation.setMonday(DateUtil.stringToDate(monDayDate.toString(), "yyyy-MM-dd"));
-            studentExtracurricularExercisesSituation.setSunday(DateUtil.stringToDate(sunDayDate.toString(), "yyyy-MM-dd"));
-
-            if(haveClassStudentIds.contains(studentCoursesEntry.getKey())){
-                studentExtracurricularExercisesSituation.setServeType("HOMEWORK");
+            if(!CollectionUtils.isEmpty(allServeStudentIds)){
+                List<ExtracurricularExercisesReply> studentExercises = extracurricularExercisesReplyDao.getStudentExercisesWithTimeZone(monDayDate.toString(), sunDayDate.toString(), new ArrayList<>(allServeStudentIds));
+                studentExercisesMap = studentExercises.stream().collect(Collectors.groupingBy(ExtracurricularExercisesReply::getUserId));
             }
 
-            if(noClassStudentIds.contains(studentCoursesEntry.getKey())){
-                studentExtracurricularExercisesSituation.setServeType("EXERCISE");
-            }
+            List<StudentExtracurricularExercisesSituation> results=new ArrayList<>();
+            for (Map.Entry<Integer, List<StudentServeDto>> studentCoursesEntry : studentCoursesMap.entrySet()) {
 
-            List<StudentServeCourseHomeworkDto> studentHomeworks = studentHomeworkMap.get(studentCoursesEntry.getKey());
-            if(!CollectionUtils.isEmpty(studentHomeworks)){
-                studentExtracurricularExercisesSituation.setActualExercisesNum(1);
-                long replyNum = studentHomeworks.stream().filter(e -> YesOrNoEnum.YES.equals(e.getStatus())).count();
-                studentExtracurricularExercisesSituation.setExercisesReplyNum(replyNum>0?1:0);
-                long haveSubmitTimes = studentHomeworks.stream().filter(e -> Objects.nonNull(e.getSubmitTime())).count();
-                if(replyNum>0&&haveSubmitTimes>0){
-                    Date lastSubmitTime = studentHomeworks.stream().filter(e->Objects.nonNull(e.getSubmitTime())).max(Comparator.comparing(StudentServeCourseHomeworkDto::getSubmitTime)).get().getSubmitTime();
-                    studentExtracurricularExercisesSituation.setLastSubmitTime(lastSubmitTime);
+                if(dontServeInCurrentWeekStudentIds.contains(studentCoursesEntry.getKey())){
+                    continue;
                 }
-                int exercisesMessageNum=0;
-                int exercisesMessageTimelyNum=0;
-                for (StudentServeCourseHomeworkDto studentHomework : studentHomeworks) {
-                    if(!YesOrNoEnum.YES.equals(studentHomework.getStatus())){
-                        continue;
-                    }
-                    if(!YesOrNoEnum.YES.equals(studentHomework.getIsReplied())){
-                        continue;
-                    }
-                    exercisesMessageNum+=1;
-                    if(new Integer(1).equals(studentHomework.getIsRepliedTimely())){
-                        exercisesMessageTimelyNum+=1;
-                    }
+
+                StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation();
+                studentExtracurricularExercisesSituation.setStudentId(studentCoursesEntry.getKey());
+                studentExtracurricularExercisesSituation.setTeacherId(studentCoursesEntry.getValue().get(0).getTeacherId());
+                studentExtracurricularExercisesSituation.setExpectExercisesNum(1);
+                studentExtracurricularExercisesSituation.setActualExercisesNum(0);
+                studentExtracurricularExercisesSituation.setExercisesReplyNum(0);
+                studentExtracurricularExercisesSituation.setExercisesMessageNum(0);
+                studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(0);
+                studentExtracurricularExercisesSituation.setWeekOfYear(nowDate.get(DateUtil.weekFields.weekOfYear()));
+                studentExtracurricularExercisesSituation.setMonday(DateUtil.stringToDate(monDayDate.toString(), "yyyy-MM-dd"));
+                studentExtracurricularExercisesSituation.setSunday(DateUtil.stringToDate(sunDayDate.toString(), "yyyy-MM-dd"));
+
+                if(haveClassStudentIds.contains(studentCoursesEntry.getKey())){
+                    studentExtracurricularExercisesSituation.setServeType("HOMEWORK");
                 }
-                studentExtracurricularExercisesSituation.setExercisesMessageNum(exercisesMessageNum>0?1:0);
-                studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(exercisesMessageTimelyNum>0?1:0);
-            }
 
-            List<ExtracurricularExercisesReply> studentExercises = studentExercisesMap.get(studentCoursesEntry.getKey());
-            if(!CollectionUtils.isEmpty(studentExercises)){
-                studentExtracurricularExercisesSituation.setActualExercisesNum(1);
-                long replyNum = studentExercises.stream().filter(e -> e.getStatus()==1).count();
-                if(studentExtracurricularExercisesSituation.getExercisesReplyNum()<=0){
-                    studentExtracurricularExercisesSituation.setExercisesReplyNum(replyNum>0?1:0);
+                if(noClassStudentIds.contains(studentCoursesEntry.getKey())){
+                    studentExtracurricularExercisesSituation.setServeType("EXERCISE");
                 }
-                long haveSubmitTimes = studentExercises.stream().filter(e->Objects.nonNull(e.getSubmitTime())).count();
-                if(replyNum>0&&haveSubmitTimes>0){
-                    Date lastSubmitTime = studentExercises.stream().filter(e->Objects.nonNull(e.getSubmitTime())).max(Comparator.comparing(ExtracurricularExercisesReply::getSubmitTime)).get().getSubmitTime();
-                    if(Objects.isNull(studentExtracurricularExercisesSituation.getLastSubmitTime())||lastSubmitTime.after(studentExtracurricularExercisesSituation.getLastSubmitTime())){
+
+                List<StudentServeCourseHomeworkDto> studentHomeworks = studentHomeworkMap.get(studentCoursesEntry.getKey());
+                if(!CollectionUtils.isEmpty(studentHomeworks)){
+                    studentExtracurricularExercisesSituation.setActualExercisesNum(1);
+                    long replyNum = studentHomeworks.stream().filter(e -> YesOrNoEnum.YES.equals(e.getStatus())).count();
+                    studentExtracurricularExercisesSituation.setExercisesReplyNum(replyNum>0?1:0);
+                    long haveSubmitTimes = studentHomeworks.stream().filter(e -> Objects.nonNull(e.getSubmitTime())).count();
+                    if(replyNum>0&&haveSubmitTimes>0){
+                        Date lastSubmitTime = studentHomeworks.stream().filter(e->Objects.nonNull(e.getSubmitTime())).max(Comparator.comparing(StudentServeCourseHomeworkDto::getSubmitTime)).get().getSubmitTime();
                         studentExtracurricularExercisesSituation.setLastSubmitTime(lastSubmitTime);
                     }
+                    int exercisesMessageNum=0;
+                    int exercisesMessageTimelyNum=0;
+                    for (StudentServeCourseHomeworkDto studentHomework : studentHomeworks) {
+                        if(!YesOrNoEnum.YES.equals(studentHomework.getStatus())){
+                            continue;
+                        }
+                        if(!YesOrNoEnum.YES.equals(studentHomework.getIsReplied())){
+                            continue;
+                        }
+                        exercisesMessageNum+=1;
+                        if(new Integer(1).equals(studentHomework.getIsRepliedTimely())){
+                            exercisesMessageTimelyNum+=1;
+                        }
+                    }
+                    studentExtracurricularExercisesSituation.setExercisesMessageNum(exercisesMessageNum>0?1:0);
+                    studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(exercisesMessageTimelyNum>0?1:0);
                 }
-                int exercisesMessageNum=0;
-                int exercisesMessageTimelyNum=0;
-                for (ExtracurricularExercisesReply studentHomework : studentExercises) {
-                    if(!new Integer(1).equals(studentHomework.getStatus())){
-                        continue;
+
+                List<ExtracurricularExercisesReply> studentExercises = studentExercisesMap.get(studentCoursesEntry.getKey());
+                if(!CollectionUtils.isEmpty(studentExercises)){
+                    studentExtracurricularExercisesSituation.setActualExercisesNum(1);
+                    long replyNum = studentExercises.stream().filter(e -> e.getStatus()==1).count();
+                    if(studentExtracurricularExercisesSituation.getExercisesReplyNum()<=0){
+                        studentExtracurricularExercisesSituation.setExercisesReplyNum(replyNum>0?1:0);
                     }
-                    if(!new Integer(1).equals(studentHomework.getIsReplied())){
-                        continue;
+                    long haveSubmitTimes = studentExercises.stream().filter(e->Objects.nonNull(e.getSubmitTime())).count();
+                    if(replyNum>0&&haveSubmitTimes>0){
+                        Date lastSubmitTime = studentExercises.stream().filter(e->Objects.nonNull(e.getSubmitTime())).max(Comparator.comparing(ExtracurricularExercisesReply::getSubmitTime)).get().getSubmitTime();
+                        if(Objects.isNull(studentExtracurricularExercisesSituation.getLastSubmitTime())||lastSubmitTime.after(studentExtracurricularExercisesSituation.getLastSubmitTime())){
+                            studentExtracurricularExercisesSituation.setLastSubmitTime(lastSubmitTime);
+                        }
                     }
-                    exercisesMessageNum+=1;
-                    if(new Integer(1).equals(studentHomework.getIsRepliedTimely())){
-                        exercisesMessageTimelyNum+=1;
+                    int exercisesMessageNum=0;
+                    int exercisesMessageTimelyNum=0;
+                    for (ExtracurricularExercisesReply studentHomework : studentExercises) {
+                        if(!new Integer(1).equals(studentHomework.getStatus())){
+                            continue;
+                        }
+                        if(!new Integer(1).equals(studentHomework.getIsReplied())){
+                            continue;
+                        }
+                        exercisesMessageNum+=1;
+                        if(new Integer(1).equals(studentHomework.getIsRepliedTimely())){
+                            exercisesMessageTimelyNum+=1;
+                        }
+                    }
+                    if(studentExtracurricularExercisesSituation.getExercisesMessageNum()<=0){
+                        studentExtracurricularExercisesSituation.setExercisesMessageNum(exercisesMessageNum>0?1:0);
+                    }
+                    if(studentExtracurricularExercisesSituation.getExercisesMessageTimelyNum()<=0){
+                        studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(exercisesMessageTimelyNum>0?1:0);
                     }
                 }
-                if(studentExtracurricularExercisesSituation.getExercisesMessageNum()<=0){
-                    studentExtracurricularExercisesSituation.setExercisesMessageNum(exercisesMessageNum>0?1:0);
-                }
-                if(studentExtracurricularExercisesSituation.getExercisesMessageTimelyNum()<=0){
-                    studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(exercisesMessageTimelyNum>0?1:0);
-                }
+                results.add(studentExtracurricularExercisesSituation);
             }
-            results.add(studentExtracurricularExercisesSituation);
-        }
 
-        studentExtracurricularExercisesSituationDao.deleteByMonday(monDayDate.toString());
-
-        BigDecimal currentPage=BigDecimal.ONE,
-                pageSize=new BigDecimal(10000),
-                total=new BigDecimal(results.size()),
-                totalPage=total.divide(pageSize, BigDecimal.ROUND_UP);
-        while (currentPage.compareTo(totalPage)<=0){
-            List<StudentExtracurricularExercisesSituation> rows=results.stream().skip(pageSize.multiply(currentPage.subtract(BigDecimal.ONE)).longValue()).limit(pageSize.longValue()).collect(Collectors.toList());
-            studentExtracurricularExercisesSituationDao.batchInsert(rows);
+//            List<StudentExtracurricularExercisesSituation> rows=results.stream().skip(pageSize.multiply(currentPage.subtract(BigDecimal.ONE)).longValue()).limit(pageSize.longValue()).collect(Collectors.toList());
+            studentExtracurricularExercisesSituationDao.batchInsert(results);
             currentPage=currentPage.add(BigDecimal.ONE);
         }
     }

+ 23 - 0
mec-biz/src/main/resources/config/mybatis/StudentMapper.xml

@@ -406,4 +406,27 @@
         WHERE
             s.service_tag_ = 1
     </select>
+    <select id="getBeServiceStudentsInfoWithStudents" resultMap="StudentServeDto">
+        SELECT
+        s.user_id_,
+        s.teacher_id_,
+        cs.group_type_,
+        cs.teach_mode_,
+        IF(CONCAT( cs.class_date_, ' ', cs.end_class_time_ )&lt;#{courseExpireDate} AND (sa.status_ != 'NORMAL' OR sa.status_ IS NULL), NULL, cs.class_date_) course_start_time_
+        FROM
+        student s
+        LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = s.user_id_
+        LEFT JOIN student_attendance sa ON cssp.course_schedule_id_=sa.course_schedule_id_ AND sa.user_id_=cssp.user_id_
+        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
+        AND cs.group_type_ IN ('VIP', 'PRACTICE')
+        AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) > #{monday}
+        WHERE
+        s.service_tag_ = 1 AND s.user_id_ IN
+        <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+            #{studentId}
+        </foreach>
+    </select>
+    <select id="getServeStudentIds" resultType="int">
+        SELECT user_id_ FROM student WHERE service_tag_=1
+    </select>
 </mapper>