Browse Source

教师考勤定时同步

dzx 1 year ago
parent
commit
15f9e65428
1 changed files with 24 additions and 6 deletions
  1. 24 6
      src/main/java/com/xjrsoft/module/job/AttendanceRecordTask.java

+ 24 - 6
src/main/java/com/xjrsoft/module/job/AttendanceRecordTask.java

@@ -68,7 +68,7 @@ public class AttendanceRecordTask {
     private IHolidayDateService holidayDateService;
 
 
-    @Scheduled(cron = "0 0 1 * * ?")
+    @Scheduled(cron = "0 30 * * * ?")
     public void execute() {
         String active = SpringUtil.getActiveProfile();
         if(!"prod".equals(active)){
@@ -77,15 +77,33 @@ public class AttendanceRecordTask {
         }
         //获取时间,并计算出前一天的开始时间和结束时间
         LocalDateTime now = LocalDateTime.now();
-        LocalDateTime startDateTime = now.plusDays(-1).withHour(0).withMinute(0).withSecond(0).withNano(0);
+        LocalDateTime noon = now.withHour(12).withMinute(0).withSecond(0);
+        LocalDateTime evening = now.withHour(18).withMinute(0).withSecond(0);
+
+        LocalDateTime startDateTime = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
         LocalDateTime endDateTime = startDateTime.plusDays(1).plusSeconds(-1);
 
-        //计算上午考勤
-        teacherAttendanceRecord(startDateTime, endDateTime, 1);
+        if(now.isBefore(noon)){
+            //计算上午考勤
+            teacherAttendanceRecord(startDateTime, endDateTime, 1);
+        }else if(now.isAfter(noon) && now.isBefore(evening)){
+            //计算上午考勤
+            teacherAttendanceRecord(startDateTime, endDateTime, 2);
+        }
+
+        LocalDateTime beginTime = now.withHour(0).withMinute(58).withSecond(0);
+        LocalDateTime endTime = now.withHour(1).withMinute(3).withSecond(0);
 
-        //计算上午考勤
-        teacherAttendanceRecord(startDateTime, endDateTime, 2);
+        //凌晨1点计算前一天的数据
+        if(now.isAfter(beginTime) && now.isBefore(endTime)){
+            startDateTime = now.plusDays(-1).withHour(0).withMinute(0).withSecond(0).withNano(0);
+            endDateTime = startDateTime.plusDays(1).plusSeconds(-1);
 
+            //计算上午考勤
+            teacherAttendanceRecord(startDateTime, endDateTime, 1);
+            //计算上午考勤
+            teacherAttendanceRecord(startDateTime, endDateTime, 2);
+        }
     }
 
     /**