|
|
@@ -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());
|