| 
					
				 | 
			
			
				@@ -1,23 +1,28 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.ym.mec.biz.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dao.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dto.StudentEduTeacherDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dto.StudentExercisesSituationDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dto.StudentServiceDetailDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dto.UserGroupDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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.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.TeacherServeQueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.service.StudentExtracurricularExercisesSituationService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.service.SysMessageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.dal.BaseDAO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.page.PageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.service.impl.BaseServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.DayOfWeek; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,6 +47,10 @@ public class StudentExtracurricularExercisesSituationServiceImpl extends BaseSer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private ClassGroupStudentMapperDao classGroupStudentMapperDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private StudentRegistrationDao studentRegistrationDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private TeacherRemindDao teacherRemindDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private SysMessageService sysMessageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	public BaseDAO<Long, StudentExtracurricularExercisesSituation> getDAO() { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -158,6 +167,49 @@ public class StudentExtracurricularExercisesSituationServiceImpl extends BaseSer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public PageInfo<TeacherServeDto> queryTeacherServeInfo(TeacherServeQueryInfo queryInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(StringUtils.isNotBlank(queryInfo.getOrganId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Integer> organIds = Arrays.stream(queryInfo.getOrganId().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			queryInfo.setOrganIds(organIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PageInfo<TeacherServeDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<String, Object> params = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		MapUtil.populateMap(params, queryInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<TeacherServeDto> dataList = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		int count = studentExtracurricularExercisesSituationDao.countTeacherServeInfo(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			pageInfo.setTotal(count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			params.put("offset", pageInfo.getOffset()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			dataList = studentExtracurricularExercisesSituationDao.queryTeacherServeInfo(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Integer> teacherIds = dataList.stream().map(TeacherServeDto::getTeacherId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<TeacherRemind> teacherReminds = teacherRemindDao.findTeachersRemindWithType(TeacherRemindTypeEnum.SERVICE, teacherIds, queryInfo.getMonday(), queryInfo.getSunday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Map<String, Map<Integer, List<TeacherRemind>>> mondayTeacherRemindMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(!CollectionUtils.isEmpty(teacherReminds)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				mondayTeacherRemindMap = teacherReminds.stream().collect(Collectors.groupingBy(e -> DateUtil.dateToString(e.getMonday(), "yyyy-MM-dd"), Collectors.groupingBy(TeacherRemind::getTeacherId))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (TeacherServeDto teacherServeDto : dataList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				String mondayStr = DateUtil.dateToString(teacherServeDto.getMonday(), "yyyy-MM-dd"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(!mondayTeacherRemindMap.containsKey(mondayStr)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Map<Integer, List<TeacherRemind>> teacherRemindMap = mondayTeacherRemindMap.get(mondayStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(!teacherRemindMap.containsKey(teacherServeDto.getTeacherId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				TeacherRemind lastTeacherRemind = teacherRemindMap.get(teacherServeDto.getTeacherId()).stream().max(Comparator.comparing(TeacherRemind::getCreateTime)).get(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				teacherServeDto.setOperatorName(lastTeacherRemind.getOperatorName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				teacherServeDto.setRemindDate(lastTeacherRemind.getCreateTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			dataList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		pageInfo.setRows(dataList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	public List<Map<String, Object>> findServiceStudentDetail(StudentServiceDetailQueryInfo queryInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		PageInfo<StudentServiceDetailDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Map<String, Object> params = new HashMap<>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -193,4 +245,39 @@ public class StudentExtracurricularExercisesSituationServiceImpl extends BaseSer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public void teacherServeRemindPush(List<TeacherServeDto> teacherServes, Integer operatorId, String operatorName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(CollectionUtils.isEmpty(teacherServes)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<TeacherRemind> reminds = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		for (TeacherServeDto teacherServe : teacherServes) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(Objects.isNull(teacherServe.getMonday())||Objects.isNull(teacherServe.getSunday())||Objects.isNull(teacherServe.getTeacherId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			String mondayStr = DateUtil.dateToString(teacherServe.getMonday(), "yyyy-MM-dd"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<StudentExtracurricularExercisesSituation> serves = studentExtracurricularExercisesSituationDao.findWeekServiceWithStudents(mondayStr, teacherServe.getTeacherId(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(CollectionUtils.isEmpty(serves)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			TeacherRemind remind = new TeacherRemind(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			remind.setOperatorId(operatorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			remind.setOperatorName(operatorName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			remind.setMonday(teacherServe.getMonday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			remind.setTeacherId(teacherServe.getTeacherId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			remind.setType(TeacherRemindTypeEnum.SERVICE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			remind.setContent("作业布置提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			reminds.add(remind); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Map<Integer, String> userMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userMap.put(teacherServe.getTeacherId(), teacherServe.getTeacherId().toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.HOMEWORK_REMIND, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					userMap, null, 0, null, "TEACHER", null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(!CollectionUtils.isEmpty(reminds)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			teacherRemindDao.batchInsert(reminds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |