Procházet zdrojové kódy

调整启动时逻辑

ximinghao před 2 měsíci
rodič
revize
cb71e104aa

+ 2 - 1
README.md

@@ -7,9 +7,10 @@
 | 识别名                             | 示例值 | 默认值                                        | 备注             |
 |:--------------------------------|:----|:-------------------------------------------|:---------------|
 | COUNT_CACHE_LENGTH              | -   | 5000                                       | 统计结果的缓存时长,单位毫秒 |
+| EXECUTE_STARTUP_TASKS           | true| true                                       | 应用启动时是否执行初始化任务 |
 | DMS_PATH                        | -   | http://121.43.55.7:10081/dms               |                |
 | DMS_LOGIN_NAME                  | -   | user_hj                                    |                |
-| DMS_LOGIN_NAME                  | -   | -                                          | dms登陆密码        |
+| DMS_PASSWORD                    | -   | -                                          | dms登陆密码        |
 | OAUTH_LOGIN_PATH                | -   | http://121.43.55.7:10086/oauth             |                |
 | OWS_PATH                        | -   | http://121.43.55.7:8889/geoserver/xjxm/ows |                |
 | XJCY_WECHAT_APPID               | -   | wx125843453562c86c                         |                |

+ 94 - 5
src/main/java/com/skyversation/xjcy/Timer.java

@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
+import org.springframework.beans.factory.annotation.Value;
 
 @Component
 //放一些定时器的简单类
@@ -31,6 +32,9 @@ public class Timer {
     private final DMSService dMSService;
     private final AuthService authService;
     private final MessageService messageService;
+    
+    @Value("${app.execute-startup-tasks:true}")
+    private boolean executeStartupTasks;
 
     public Timer(ParkPreCountService parkPreCountService, InvestmentPreCountService investmentPreCountService, DMSService dMSService, AuthService authService, MessageService messageService) {
         this.parkPreCountService = parkPreCountService;
@@ -40,23 +44,108 @@ public class Timer {
         this.messageService = messageService;
     }
 
-    @Scheduled(cron = "0 5 0 * * ?")
     @PostConstruct
+    public void init() {
+        // 根据配置决定是否执行启动时任务
+        if (executeStartupTasks) {
+            // 启动时依次执行所有任务
+            executeStartupSequence();
+        } else {
+            System.out.println("启动时任务已禁用,跳过执行");
+        }
+    }
+
+    @Scheduled(cron = "0 5 0 * * ?")
+    public void dailyExecute() {
+        // 每日依次执行所有任务
+        executeDailySequence();
+    }
+
+    /**
+     * 启动时执行序列
+     */
+    private void executeStartupSequence() {
+        System.out.println("开始执行启动任务序列...");
+        
+        // 执行园区预统计
+        try {
+            countPark();
+            System.out.println("园区预统计完成");
+        } catch (Exception e) {
+            System.err.println("园区预统计执行失败: " + e.getMessage());
+            e.printStackTrace();
+        }
+        
+        // 执行投资预统计
+        try {
+            countInvestment();
+            System.out.println("招商预统计完成");
+        } catch (Exception e) {
+            System.err.println("招商预统计执行失败: " + e.getMessage());
+            e.printStackTrace();
+        }
+        
+        // 执行企业健康度检查
+        try {
+            checkEnterpriseHealth();
+            System.out.println("企业健康度检查完成");
+        } catch (Exception e) {
+            System.err.println("企业健康度检查执行失败: " + e.getMessage());
+            e.printStackTrace();
+        }
+        
+        System.out.println("启动任务序列执行完毕");
+    }
+
+    /**
+     * 每日执行序列
+     */
+    private void executeDailySequence() {
+        System.out.println("开始执行每日任务序列...");
+        
+        // 执行园区预统计
+        try {
+            countPark();
+            System.out.println("园区预统计完成");
+        } catch (Exception e) {
+            System.err.println("园区预统计执行失败: " + e.getMessage());
+            e.printStackTrace();
+        }
+        
+        // 执行投资预统计
+        try {
+            countInvestment();
+            System.out.println("招商预统计完成");
+        } catch (Exception e) {
+            System.err.println("招商预统计执行失败: " + e.getMessage());
+            e.printStackTrace();
+        }
+        
+        // 执行企业健康度检查
+        try {
+            checkEnterpriseHealth();
+            System.out.println("企业健康度检查完成");
+        } catch (Exception e) {
+            System.err.println("企业健康度检查执行失败: " + e.getMessage());
+            e.printStackTrace();
+        }
+        
+        System.out.println("每日任务序列执行完毕");
+    }
+
+
     public void countPark() {
         parkPreCountService.updateAllRoom();
     }
 
-    @PostConstruct
     public void countInvestment() {
         investmentPreCountService.updateAllTarget();
     }
 
-    @Scheduled(cron = "0 5 0 * * ?")
-    @PostConstruct
+
     public void checkEnterpriseHealth(){
         LocalDate now = LocalDate.now();
         LocalDateTime actuallyTime = now.minusDays(1).atTime(23,59,59,999999999);
-//        LocalDateTime actuallyTime = LocalDateTime.of(2025,9,30,23,59,59,9999);
 
         List<Enterprise> enterprises = dMSService.query(authService.getTokenOfServiceAccount(), DMSQuery.ENTERPRISE, Enterprise.class,actuallyTime.toLocalDate());
         List<LeaseDetail> leaseDetails = dMSService.query(authService.getTokenOfServiceAccount(), DMSQuery.LAST_LEASE_DETAIL, LeaseDetail.class,actuallyTime.toLocalDate());

+ 1 - 0
src/main/resources/application.yml

@@ -21,6 +21,7 @@ logging:
             servlet: DEBUG
 app:
   count-cache-length: ${COUNT_CACHE_LENGTH:5000}
+  execute-startup-tasks: ${EXECUTE_STARTUP_TASKS:false}
   dms:
     #    path: http://127.0.0.1:10081/dms
     path: ${DMS_PATH:http://121.43.55.7:10081/dms}