| 
					
				 | 
			
			
				@@ -2,13 +2,13 @@ package com.ym.mec.biz.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dao.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.TeacherRemind; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.enums.GroupType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.enums.MessageTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.enums.TeacherRemindTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.page.StudentExercisesSituationQueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.page.StudentServiceDetailQueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.page.TeacherServeHomeworkQueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.page.TeacherServeQueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.service.StudentExtracurricularExercisesSituationService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.service.SysMessageService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -20,6 +20,7 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.util.collection.MapUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -51,6 +52,12 @@ public class StudentExtracurricularExercisesSituationServiceImpl extends BaseSer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private TeacherRemindDao teacherRemindDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private SysMessageService sysMessageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private StudentDao studentDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private SubjectDao subjectDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private CourseHomeworkDao courseHomeworkDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	public BaseDAO<Long, StudentExtracurricularExercisesSituation> getDAO() { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -280,4 +287,125 @@ public class StudentExtracurricularExercisesSituationServiceImpl extends BaseSer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			teacherRemindDao.batchInsert(reminds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public PageInfo<TeacherServeHomeworkDto> queryTeacherServeHomeworkDetail(TeacherServeHomeworkQueryInfo queryInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(Objects.isNull(queryInfo.getMonday())||Objects.isNull(queryInfo.getSunday())||Objects.isNull(queryInfo.getTeacherId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new BizException("请指定教师"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PageInfo<TeacherServeHomeworkDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String mondayStr = DateUtil.dateToString(queryInfo.getMonday(), "yyyy-MM-dd"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<StudentExtracurricularExercisesSituation> serves = studentExtracurricularExercisesSituationDao.findWeekServiceWithStudents(mondayStr, queryInfo.getTeacherId(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(CollectionUtils.isEmpty(serves)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<StudentExtracurricularExercisesSituation> homeworkServes = serves.stream().filter(s -> "HOMEWORK".equals(s.getServeType())).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(CollectionUtils.isEmpty(homeworkServes)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Long> courseIdsArr = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		for (StudentExtracurricularExercisesSituation homeworkServe : homeworkServes) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(StringUtils.isBlank(homeworkServe.getCourseIds())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Long> ids = Arrays.stream(homeworkServe.getCourseIds().split(",")).map(id -> Long.valueOf(id)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			courseIdsArr.addAll(ids); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(CollectionUtils.isEmpty(courseIdsArr)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<Long, Long> courseNumMap = courseIdsArr.stream().collect(Collectors.groupingBy(id -> id, Collectors.counting())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Set<Long> courseIds = new HashSet<>(courseIdsArr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<String, Object> params = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		MapUtil.populateMap(params, queryInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		params.put("courseIds", courseIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<TeacherServeHomeworkDto> dataList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		int count = courseScheduleDao.countByCourseScheduleIds(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			pageInfo.setTotal(count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			params.put("offset", pageInfo.getOffset()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<CourseSchedule> courseSchedules = courseScheduleDao.queryByCourseScheduleIds(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<CourseHomework> courseHomeworks = courseHomeworkDao.findByCourseSchedules(new ArrayList<>(courseIds)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Map<Long, Long> courseHomeworkMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(!CollectionUtils.isEmpty(courseHomeworks)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				courseHomeworkMap = courseHomeworks.stream().collect(Collectors.groupingBy(CourseHomework::getCourseScheduleId, Collectors.counting())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (CourseSchedule courseSchedule : courseSchedules) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				TeacherServeHomeworkDto tshd = new TeacherServeHomeworkDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				BeanUtils.copyProperties(courseSchedule,tshd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				tshd.setStudentNum(courseNumMap.get(courseSchedule.getId()).intValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(courseHomeworkMap.containsKey(courseSchedule.getId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					tshd.setHomeworkExist(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				dataList.add(tshd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			dataList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		pageInfo.setRows(dataList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public PageInfo<TeacherServeExtraDto> queryTeacherServeExtraDetail(TeacherServeHomeworkQueryInfo queryInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(Objects.isNull(queryInfo.getMonday())||Objects.isNull(queryInfo.getSunday())||Objects.isNull(queryInfo.getTeacherId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new BizException("请指定教师"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PageInfo<TeacherServeExtraDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String mondayStr = DateUtil.dateToString(queryInfo.getMonday(), "yyyy-MM-dd"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<StudentExtracurricularExercisesSituation> serves = studentExtracurricularExercisesSituationDao.findWeekServiceWithStudents(mondayStr, queryInfo.getTeacherId(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(CollectionUtils.isEmpty(serves)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<StudentExtracurricularExercisesSituation> homeworkServes = serves.stream().filter(s -> "EXERCISE".equals(s.getServeType())).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(CollectionUtils.isEmpty(homeworkServes)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Set<Integer> studentIds = homeworkServes.stream().map(StudentExtracurricularExercisesSituation::getStudentId).collect(Collectors.toSet()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<Integer, List<StudentExtracurricularExercisesSituation>> studentServeMap = homeworkServes.stream().collect(Collectors.groupingBy(StudentExtracurricularExercisesSituation::getStudentId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<String, Object> params = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		MapUtil.populateMap(params, queryInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		params.put("studentIds", studentIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<TeacherServeExtraDto> dataList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		int count = studentDao.countByIds(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			pageInfo.setTotal(count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			params.put("offset", pageInfo.getOffset()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Student> students = studentDao.queryByIds(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Set<Integer> subjectIds = new HashSet<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (Student student : students) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(StringUtils.isNotBlank(student.getSubjectIdList())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					Set<Integer> ids = Arrays.stream(student.getSubjectIdList().split(",")).map(id -> Integer.valueOf(id)).collect(Collectors.toSet()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					subjectIds.addAll(ids); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				TeacherServeExtraDto tsed = new TeacherServeExtraDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				BeanUtils.copyProperties(student,tsed); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(studentServeMap.containsKey(student.getUserId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					List<StudentExtracurricularExercisesSituation> studentServes = studentServeMap.get(student.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					int num = studentServes.stream().mapToInt(StudentExtracurricularExercisesSituation::getActualExercisesNum).reduce(0, Integer::sum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if(num>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						tsed.setHomeworkExist(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				dataList.add(tsed); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Subject> subjects = subjectDao.findBySubjectIds(new ArrayList<>(subjectIds)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Map<Integer, Subject> idSubjectMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(!CollectionUtils.isEmpty(subjects)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				idSubjectMap = subjects.stream().collect(Collectors.toMap(Subject::getId, s->s, (s1, s2)->s1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			dataList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		pageInfo.setRows(dataList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |