|
@@ -0,0 +1,183 @@
|
|
|
|
+package com.ym.mec.biz.service.impl;
|
|
|
|
+
|
|
|
|
+import com.ym.mec.biz.dal.dao.ExtracurricularExercisesReplyDao;
|
|
|
|
+import com.ym.mec.biz.dal.dao.StudentCourseHomeworkDao;
|
|
|
|
+import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
|
+import com.ym.mec.biz.dal.dao.StudentExtracurricularExercisesSituationDao;
|
|
|
|
+import com.ym.mec.biz.dal.dto.StudentServeCourseHomeworkDto;
|
|
|
|
+import com.ym.mec.biz.dal.dto.StudentServeDto;
|
|
|
|
+import com.ym.mec.biz.dal.dto.StudentServiceHomeworkDto;
|
|
|
|
+import com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply;
|
|
|
|
+import com.ym.mec.biz.dal.entity.Student;
|
|
|
|
+import com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation;
|
|
|
|
+import com.ym.mec.biz.dal.enums.YesOrNoEnum;
|
|
|
|
+import com.ym.mec.biz.service.StudentServeService;
|
|
|
|
+import com.ym.mec.util.date.DateUtil;
|
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import java.time.DayOfWeek;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author Joburgess
|
|
|
|
+ * @Date 2020.05.27
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class StudentServeServiceImpl implements StudentServeService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private StudentDao studentDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private StudentCourseHomeworkDao studentCourseHomeworkDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExtracurricularExercisesReplyDao extracurricularExercisesReplyDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private StudentExtracurricularExercisesSituationDao studentExtracurricularExercisesSituationDao;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void exercisesSituationStatistics(String monday) {
|
|
|
|
+ LocalDate nowDate = LocalDateTime.now(DateUtil.zoneId).toLocalDate();
|
|
|
|
+
|
|
|
|
+ if(nowDate.getDayOfWeek()== DayOfWeek.MONDAY){
|
|
|
|
+ int lastWeekTodayUpdateNum = studentExtracurricularExercisesSituationDao.findLastWeekTodayUpdateNum(nowDate.plusDays(-1).toString());
|
|
|
|
+ if(lastWeekTodayUpdateNum<=0){
|
|
|
|
+ nowDate = nowDate.plusDays(-1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotBlank(monday)){
|
|
|
|
+ nowDate=LocalDate.parse(monday, DateUtil.dateFormatter);
|
|
|
|
+ }
|
|
|
|
+ LocalDate monDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
|
|
|
|
+ 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());
|
|
|
|
+ if(CollectionUtils.isEmpty(serviceStudents)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //本周不服务学员列表
|
|
|
|
+ Set<Integer> dontServeInCurrentWeekStudentIds=new HashSet<>();
|
|
|
|
+ //本周有课学员编号集合
|
|
|
|
+ Set<Integer> haveClassStudentIds=new HashSet<>();
|
|
|
|
+ //本周无课学员编号集合
|
|
|
|
+ Set<Integer> noClassStudentIds=new HashSet<>();
|
|
|
|
+ for (StudentServeDto serviceStudent : serviceStudents) {
|
|
|
|
+ if(Objects.nonNull(serviceStudent.getCourseStartTime())&&serviceStudent.getCourseStartTime().after(nextMonday)){
|
|
|
|
+ dontServeInCurrentWeekStudentIds.add(serviceStudent.getUserId());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if(Objects.nonNull(serviceStudent.getCourseStartTime())){
|
|
|
|
+ haveClassStudentIds.add(serviceStudent.getUserId());
|
|
|
|
+ }else{
|
|
|
|
+ noClassStudentIds.add(serviceStudent.getUserId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<Integer, List<StudentServeCourseHomeworkDto>> studentHomeworkMap=new HashMap<>();
|
|
|
|
+ Map<Integer, List<ExtracurricularExercisesReply>> studentExercisesMap=new HashMap<>();
|
|
|
|
+
|
|
|
|
+ if (!CollectionUtils.isEmpty(haveClassStudentIds)){
|
|
|
|
+ List<StudentServeCourseHomeworkDto> studentHomeworks = studentCourseHomeworkDao.findStudentHomeworkWithCourseDateRange(monDayDate.toString(), sunDayDate.toString(), new ArrayList<>(haveClassStudentIds));
|
|
|
|
+ studentHomeworkMap = studentHomeworks.stream().filter(h -> DateUtil.daysBetween(h.getCourseStartTime(), h.getHomeworkCreateTime())<3).collect(Collectors.groupingBy(StudentServeCourseHomeworkDto::getUserId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!CollectionUtils.isEmpty(noClassStudentIds)){
|
|
|
|
+ List<ExtracurricularExercisesReply> studentExercises = extracurricularExercisesReplyDao.getStudentExercisesWithTimeZone(monDayDate.toString(), sunDayDate.toString(), new ArrayList<>(noClassStudentIds));
|
|
|
|
+ studentExercisesMap = studentExercises.stream().collect(Collectors.groupingBy(ExtracurricularExercisesReply::getUserId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<StudentExtracurricularExercisesSituation> results=new ArrayList<>();
|
|
|
|
+ for (StudentServeDto serviceStudent : serviceStudents) {
|
|
|
|
+
|
|
|
|
+ if(dontServeInCurrentWeekStudentIds.contains(serviceStudent.getUserId())){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation();
|
|
|
|
+ studentExtracurricularExercisesSituation.setStudentId(serviceStudent.getUserId());
|
|
|
|
+ studentExtracurricularExercisesSituation.setTeacherId(serviceStudent.getTeacherId());
|
|
|
|
+ studentExtracurricularExercisesSituation.setExpectExercisesNum(1);
|
|
|
|
+ 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(serviceStudent.getUserId())){
|
|
|
|
+ List<StudentServeCourseHomeworkDto> studentHomeworks = studentHomeworkMap.get(serviceStudent.getUserId());
|
|
|
|
+ if(CollectionUtils.isEmpty(studentHomeworks)){
|
|
|
|
+ studentExtracurricularExercisesSituation.setActualExercisesNum(0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesReplyNum(0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageNum(0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(0);
|
|
|
|
+ results.add(studentExtracurricularExercisesSituation);
|
|
|
|
+ continue;
|
|
|
|
+ }else{
|
|
|
|
+ studentExtracurricularExercisesSituation.setActualExercisesNum(1);
|
|
|
|
+ long replyNum = studentHomeworks.stream().filter(e -> YesOrNoEnum.YES.equals(e.getStatus())).count();
|
|
|
|
+ Date lastSubmitTime = studentHomeworks.stream().max(Comparator.comparing(StudentServeCourseHomeworkDto::getSubmitTime)).get().getSubmitTime();
|
|
|
|
+ studentExtracurricularExercisesSituation.setLastSubmitTime(lastSubmitTime);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesReplyNum(replyNum>0?1:0);
|
|
|
|
+ int exercisesMessageNum=0;
|
|
|
|
+ int exercisesMessageTimelyNum=0;
|
|
|
|
+ for (StudentServeCourseHomeworkDto studentHomework : studentHomeworks) {
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageNum(exercisesMessageNum>0?1:0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(exercisesMessageTimelyNum>0?1:0);
|
|
|
|
+ results.add(studentExtracurricularExercisesSituation);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(noClassStudentIds.contains(serviceStudent.getUserId())){
|
|
|
|
+ List<ExtracurricularExercisesReply> studentExercises = studentExercisesMap.get(serviceStudent.getUserId());
|
|
|
|
+ if(CollectionUtils.isEmpty(studentExercises)){
|
|
|
|
+ studentExtracurricularExercisesSituation.setActualExercisesNum(0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesReplyNum(0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageNum(0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(0);
|
|
|
|
+ results.add(studentExtracurricularExercisesSituation);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ studentExtracurricularExercisesSituation.setActualExercisesNum(1);
|
|
|
|
+ long replyNum = studentExercises.stream().filter(e -> e.getStatus()==1).count();
|
|
|
|
+ Date lastSubmitTime = studentExercises.stream().max(Comparator.comparing(ExtracurricularExercisesReply::getSubmitTime)).get().getSubmitTime();
|
|
|
|
+ studentExtracurricularExercisesSituation.setLastSubmitTime(lastSubmitTime);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesReplyNum(replyNum>0?1:0);
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageNum(exercisesMessageNum>0?1:0);
|
|
|
|
+ studentExtracurricularExercisesSituation.setExercisesMessageTimelyNum(exercisesMessageTimelyNum>0?1:0);
|
|
|
|
+ results.add(studentExtracurricularExercisesSituation);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|