|
@@ -106,12 +106,6 @@ public class AttendanceMessageTask {
|
|
|
}
|
|
|
//查询今天的考勤规则
|
|
|
List<AttendanceRuleDetails> ruleDetails = ruleCategoryService.getTodayRules();
|
|
|
- //获取最近的时间
|
|
|
- LocalDateTime recentlyTime = getRecentlyTime(ruleDetails, now);
|
|
|
- if(now.isBefore(recentlyTime)){
|
|
|
- log.info("未到时间,不需要提醒");
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
|
|
|
// WechatMessageLog log = wechatMessageLogService.getOne(
|
|
@@ -125,9 +119,7 @@ public class AttendanceMessageTask {
|
|
|
// }
|
|
|
|
|
|
|
|
|
- List<AttendanceMessageSet> list = messageSetService.list(
|
|
|
- new QueryWrapper<AttendanceMessageSet>().lambda()
|
|
|
- );
|
|
|
+ List<AttendanceMessageSet> list = messageSetService.list();
|
|
|
//判断是上午还是下午
|
|
|
Integer timePeriod = null;
|
|
|
String timePeriodStr = null;
|
|
@@ -143,30 +135,41 @@ public class AttendanceMessageTask {
|
|
|
}
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- String format = recentlyTime.format(formatter);
|
|
|
|
|
|
int userCount = 0;
|
|
|
Set<Integer> roleTypes = list.stream().map(AttendanceMessageSet::getRoleType).collect(Collectors.toSet());
|
|
|
- Set<Long> setIds = list.stream().map(AttendanceMessageSet::getId).collect(Collectors.toSet());
|
|
|
|
|
|
//查询需要通知的人
|
|
|
- List<XjrUser> userList = userService.list(
|
|
|
- new MPJLambdaWrapper<XjrUser>().distinct()
|
|
|
- .select(XjrUser::getId)
|
|
|
- .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
- .leftJoin(UserRoleRelation.class, UserRoleRelation::getUserId, XjrUser::getId)
|
|
|
- .leftJoin(AttendanceMessageUserRelation.class, AttendanceMessageUserRelation::getUserId, XjrUser::getId)
|
|
|
- .in(UserRoleRelation::getRoleId, roleTypes)
|
|
|
- .in(AttendanceMessageUserRelation::getAttendanceMessageSetId, setIds)
|
|
|
- );
|
|
|
-
|
|
|
|
|
|
for (AttendanceMessageSet messageSet : list) {
|
|
|
+ List<XjrUser> userList = userService.list(
|
|
|
+ new MPJLambdaWrapper<XjrUser>().distinct()
|
|
|
+ .select(XjrUser::getId)
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(UserRoleRelation.class, UserRoleRelation::getUserId, XjrUser::getId)
|
|
|
+ .leftJoin(AttendanceMessageUserRelation.class, AttendanceMessageUserRelation::getUserId, XjrUser::getId)
|
|
|
+ .in(UserRoleRelation::getRoleId, roleTypes)
|
|
|
+ .eq(AttendanceMessageUserRelation::getAttendanceMessageSetId, messageSet.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ LocalDateTime recentlyTime = null;
|
|
|
String wechatTemplate = weChatUtil.getAttendanceMsgLateTemplate();
|
|
|
if(messageSet.getMessageCategory() != null && messageSet.getMessageCategory() == 1){
|
|
|
wechatTemplate = weChatUtil.getAttendanceMsgLateTemplate();
|
|
|
+
|
|
|
+ //获取最近的时间
|
|
|
+ recentlyTime = getRecentlyTime(ruleDetails, now);
|
|
|
+ if(now.isBefore(recentlyTime)){
|
|
|
+ log.info("未到时间,不需要提醒");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}else if(messageSet.getMessageCategory() != null && messageSet.getMessageCategory() == 3){
|
|
|
wechatTemplate = weChatUtil.getAttendanceMsgAbsenceTemplate();
|
|
|
+ recentlyTime = getRecentlyOverTime(ruleDetails, now);
|
|
|
+ if(now.isBefore(recentlyTime)){
|
|
|
+ log.info("未到时间,不需要提醒");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(!messageSet.getTimePeriod().contains(timePeriod + "")){
|
|
@@ -177,6 +180,12 @@ public class AttendanceMessageTask {
|
|
|
if(userList.isEmpty()){
|
|
|
continue;
|
|
|
}
|
|
|
+ if(recentlyTime == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String format = recentlyTime.format(formatter);
|
|
|
+
|
|
|
userCount += userList.size();
|
|
|
if(messageSet.getRoleType() != null && messageSet.getRoleType() == 2){
|
|
|
//教师总人数
|
|
@@ -316,5 +325,39 @@ public class AttendanceMessageTask {
|
|
|
return timeMap.get(collect.get(0));
|
|
|
}
|
|
|
|
|
|
+ LocalDateTime getRecentlyOverTime(List<AttendanceRuleDetails> ruleDetails, LocalDateTime now){
|
|
|
+ List<LocalDateTime> result = new ArrayList<>();
|
|
|
+ for (AttendanceRuleDetails ruleDetail : ruleDetails) {
|
|
|
+ if(ruleDetail.getIsAllowInOutSchool() != null && ruleDetail.getIsAllowInOutSchool() == 1
|
|
|
+ && ruleDetail.getIsAttendance() != null && ruleDetail.getIsAttendance() == 1){
|
|
|
+ if(ruleDetail.getAmStartTime() != null){
|
|
|
+ LocalDateTime amStartTime = now.with(ruleDetail.getAmStartTime().toLocalTime()).plusMinutes(ruleDetail.getOverMinutes());
|
|
|
+ result.add(amStartTime);
|
|
|
+ }
|
|
|
+ if(ruleDetail.getPmStartTime() != null){
|
|
|
+ LocalDateTime pmStartTime = now.with(ruleDetail.getPmStartTime().toLocalTime()).plusMinutes(ruleDetail.getOverMinutes());
|
|
|
+ result.add(pmStartTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ruleDetail.getEveningStartTime() != null){
|
|
|
+ LocalDateTime eveningStartTime = now.with(ruleDetail.getEveningStartTime().toLocalTime()).plusMinutes(ruleDetail.getOverMinutes());
|
|
|
+ result.add(eveningStartTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(result.isEmpty()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<Long, LocalDateTime> timeMap = new HashMap<>();
|
|
|
+ for (LocalDateTime localDateTime : result) {
|
|
|
+ long between = ChronoUnit.SECONDS.between(now, localDateTime);
|
|
|
+ timeMap.put(Math.abs(between), localDateTime);
|
|
|
+ }
|
|
|
+ List<Long> collect = timeMap.keySet().stream().collect(Collectors.toList());
|
|
|
+ Collections.sort(collect, Long::compare);
|
|
|
+
|
|
|
+ return timeMap.get(collect.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|