1811872455@163.com 1 неделя назад
Родитель
Сommit
f2d3d85c4e

+ 25 - 2
storlead-centre-api/src/main/java/com/storlead/centre/dispatch/AttendanceSignDispatchTask.java

@@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
+import java.time.LocalTime;
 import java.util.Date;
 
 /**
@@ -27,9 +28,30 @@ public class AttendanceSignDispatchTask {
      * 同步考勤数据
      * @throws ParseException
      */
-    @Scheduled(cron ="0 */5 6-23 * * ? ")
+    @Scheduled(cron ="0 * * * * ? ")
     public void syncSignData() throws ParseException {
-        log.error("开始时间--"+new Date());
+
+        LocalTime now = LocalTime.now();
+
+        // ===== 总时间窗:06:00 – 22:30 =====
+        if (now.isBefore(LocalTime.of(6, 0))
+                || now.isAfter(LocalTime.of(22, 30))) {
+            return;
+        }
+
+        boolean morningHighFrequency =
+                (now.getHour() == 8 && now.getMinute() >= 30)
+                        || (now.getHour() == 9 && now.getMinute() <= 10);
+
+        boolean eveningHighFrequency =
+                (now.getHour() == 18)
+                        || (now.getHour() == 19 && now.getMinute() <= 40);
+
+        boolean highFrequency = morningHighFrequency || eveningHighFrequency;
+        // 非高频时间:只允许 5 分钟一次
+        if (!highFrequency && now.getMinute() % 5 != 0) {
+            return;
+        }
         log.info("oa company dept job user sync task starting ----");
         try {
             attendanceSignRecordService.getSaveSignRecord();
@@ -43,4 +65,5 @@ public class AttendanceSignDispatchTask {
             log.error("----syncSignData------error-"+e);
         }
     }
+
 }

+ 24 - 1
storlead-centre-api/src/main/java/com/storlead/centre/dispatch/SyncAttendanceSignToOaTask.java

@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -43,8 +44,30 @@ public class SyncAttendanceSignToOaTask {
     @Resource
     private SystemConfigItemService systemConfigItemService;
 
-    @Scheduled(cron ="0 */5 6-23 * * ? ")
+    @Scheduled(cron ="0 * * * * ? ")
     public void syncSignData() throws ParseException {
+
+        LocalTime now = LocalTime.now();
+        // ===== 总时间窗:06:00 – 22:30 =====
+        if (now.isBefore(LocalTime.of(6, 0))
+                || now.isAfter(LocalTime.of(22, 30))) {
+            return;
+        }
+
+        boolean morningHighFrequency =
+                (now.getHour() == 8 && now.getMinute() >= 30)
+                        || (now.getHour() == 9 && now.getMinute() <= 10);
+
+        boolean eveningHighFrequency =
+                (now.getHour() == 18)
+                        || (now.getHour() == 19 && now.getMinute() <= 40);
+
+        boolean highFrequency = morningHighFrequency || eveningHighFrequency;
+        // 非高频时间:只允许 5 分钟一次
+        if (!highFrequency && now.getMinute() % 5 != 0) {
+            return;
+        }
+
         // 获取未同步的数据到
         LambdaQueryWrapper<AttendanceSignRecordEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
         lambdaQueryWrapper.eq(AttendanceSignRecordEntity::getSyncOa,Integer.valueOf(0));