Browse Source

上午的上报推送分成四个批次

peiguo 3 years ago
parent
commit
30302a475a
1 changed files with 36 additions and 18 deletions
  1. 36 18
      whepi-web/src/main/java/com/bofeng/controller/EpiAdminController.java

+ 36 - 18
whepi-web/src/main/java/com/bofeng/controller/EpiAdminController.java

@@ -11,15 +11,15 @@ import com.yvan.ModelOps;
 import com.yvan.mvc.Pd;
 import com.yvan.platform.StringUtils;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.text.ParseException;
 import java.util.List;
 
+@Slf4j
 @RestController
 public class EpiAdminController {
 
@@ -58,30 +58,49 @@ public class EpiAdminController {
         return null;
     }
 
-    //    @Scheduled(cron = "0 44 12 * * ?") //每天19点执行一次
+    @Scheduled(cron = "0 0 9 * * ?") //每天9点执行一次
+    public void scheduledTaskByFixedDelay9() {
+        this.fixedDelay(1);
+    }
+    @Scheduled(cron = "0 0 10 * * ?") //每天10点执行一次
+    public void scheduledTaskByFixedDelay10() {
+        this.fixedDelay(2);
+    }
     @Scheduled(cron = "0 0 11 * * ?") //每天11点执行一次
-    public void scheduledTaskByFixedDelay() {
-        System.out.println("==============执行定时任务开始================");
+    public void scheduledTaskByFixedDelay11() {
+        this.fixedDelay(3);
+    }
+    @Scheduled(cron = "0 0 12 * * ?") //每天12点执行一次
+    public void scheduledTaskByFixedDelay12() {
+        this.fixedDelay(0);
+    }
+
+    /**
+     * 每天上午的推送取余,分成四个批次推送
+     */
+    public void fixedDelay(int i) {
+        log.info("==============执行定时任务开始================");
         Long start = 0L, count = 100L;
         while (true) {
             List<UserOpen> userOpens = userOpenMapper.getOpenUser(start, count);
             int re = 0;
             for (UserOpen userOpen : userOpens) {
-                re += epiTemplateMessageService.systemSendRemindMessage(userOpen.getUserId(), userOpen.getOpenId());
+                if ((userOpen.getUserId()&3) == i) {
+                    re += epiTemplateMessageService.systemSendRemindMessage(userOpen.getUserId(), userOpen.getOpenId());
+                }
             }
-            System.out.println("==============执行定时任务" + re + "================");
+            log.info("==============执行定时任务" + re + "================");
             start += count;
             if (userOpens == null || userOpens.size() < count) {
                 break;
             }
         }
-
-        System.out.println("==============执行定时任务完毕================");
+        log.info("==============执行定时任务完毕================");
     }
 
     @Scheduled(cron = "0 0 19 * * ?") //每天19点执行一次
     public void scheduledTaskByFixedDelay2() {
-        System.out.println("==============执行定时任务开始================");
+        log.info("==============执行定时任务开始================");
         Long start = 0L, count = 100L;
         while (true) {
             List<UserOpen> userOpens = userOpenMapper.getOpenUser(start, count);
@@ -89,26 +108,25 @@ public class EpiAdminController {
             for (UserOpen userOpen : userOpens) {
                 re += epiTemplateMessageService.systemSendRemindMessage(userOpen.getUserId(), userOpen.getOpenId());
             }
-            System.out.println("==============执行定时任务" + re + "================");
+            log.info("==============执行定时任务" + re + "================");
             start += count;
             if (userOpens == null || userOpens.size() < count) {
                 break;
             }
         }
-
-        System.out.println("==============执行定时任务完毕================");
+        log.info("==============执行定时任务完毕================");
     }
 
 //    @Scheduled(cron = "0 25 22 * * ?")
 //    public void returnWorkTaskByFixedDelay() {
-//        System.out.println("==============执行定时任务开始================");
+//        log.info("==============执行定时任务开始================");
 //        scanService.returnWorkLY(0L);
-//        System.out.println("==============执行定时任务完毕================");
+//        log.info("==============执行定时任务完毕================");
 //    }
 
     //    @Scheduled(cron = "0 0 0 * * ?") //每天0点执行一次
     public void scheduledReportByFixedDelay() {
-        System.out.println("==============执行定时任务开始================");
+        log.info("==============执行定时任务开始================");
         msReportService.getNowByYesterdayDate();
 //        Long start = 0L, count = 100L;
 //        while (true) {
@@ -117,13 +135,13 @@ public class EpiAdminController {
 //            for (UserOpen userOpen : userOpens) {
 //                re += epiTemplateMessageService.systemSendRemindMessage(userOpen.getUserId(), userOpen.getOpenId());
 //            }
-//            System.out.println("==============执行定时任务"+re+"================");
+//            log.info("==============执行定时任务"+re+"================");
 //            start += count;
 //            if (userOpens == null || userOpens.size()<count) {
 //                break;
 //            }
 //        }
 
-        System.out.println("==============执行定时任务完毕================");
+        log.info("==============执行定时任务完毕================");
     }
 }