|
@@ -1,32 +1,93 @@
|
|
|
package com.gyee.runeconomy.task;
|
|
|
|
|
|
import com.gyee.runeconomy.service.EarlyWarning.EarlyWarningReliableService;
|
|
|
+import com.gyee.runeconomy.service.auto.impl.NewDataFittingService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.concurrent.Executor;
|
|
|
+
|
|
|
@Component
|
|
|
-@EnableAsync // 启用异步方法执行
|
|
|
+@EnableAsync
|
|
|
public class AnalysisTask {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(AnalysisTask.class);
|
|
|
|
|
|
@Autowired
|
|
|
private EarlyWarningReliableService earlyWarningReliableService;
|
|
|
- // 每日1点 - 日曲线偏差
|
|
|
- @Async
|
|
|
- @Scheduled(cron = "0 0 1 1/1 * ?")
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NewDataFittingService newDataFittingService;
|
|
|
+
|
|
|
+ // 配置专用线程池(替代默认的SimpleAsyncTaskExecutor)
|
|
|
+ @Bean(name = "scheduledTaskExecutor")
|
|
|
+ public Executor taskExecutor() {
|
|
|
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
|
+ executor.setCorePoolSize(5);
|
|
|
+ executor.setMaxPoolSize(10);
|
|
|
+ executor.setQueueCapacity(50);
|
|
|
+ executor.setThreadNamePrefix("scheduled-task-");
|
|
|
+ executor.initialize();
|
|
|
+ return executor;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 每月1日1:00执行(明确时区+超时保护)
|
|
|
+ @Async("scheduledTaskExecutor")
|
|
|
+ @Scheduled(cron = "0 0 1 1 * ?", zone = "Asia/Shanghai")
|
|
|
public void rqxpc() {
|
|
|
+ final long startTime = System.currentTimeMillis();
|
|
|
try {
|
|
|
- logger.info("预警报告计算开始运行");
|
|
|
+ logger.info("[预警报告] 任务开始");
|
|
|
earlyWarningReliableService.Electricity();
|
|
|
- logger.info("预警报告计算运行完成");
|
|
|
+ logger.info("[预警报告] 任务完成, 耗时{}ms", System.currentTimeMillis() - startTime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("[预警报告] 任务失败, 已运行{}ms", System.currentTimeMillis() - startTime, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 每月1日2:00执行
|
|
|
+ @Async("scheduledTaskExecutor")
|
|
|
+ @Scheduled(cron = "0 0 2 1 * ?", zone = "Asia/Shanghai")
|
|
|
+ public void qxnh() {
|
|
|
+ final long startTime = System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ logger.info("[功率拟合] 任务开始");
|
|
|
+
|
|
|
+ // 显式使用时区+防错处理
|
|
|
+ ZoneId zone = ZoneId.of("Asia/Shanghai");
|
|
|
+ YearMonth lastMonth = YearMonth.now(zone).minusMonths(1);
|
|
|
+
|
|
|
+ LocalDateTime start = lastMonth.atDay(1).atStartOfDay();
|
|
|
+ LocalDateTime end = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
|
|
+
|
|
|
+ // 时间范围校验
|
|
|
+ if (start.isAfter(end)) {
|
|
|
+ throw new IllegalStateException("时间范围无效: " + start + " > " + end);
|
|
|
+ }
|
|
|
+
|
|
|
+ long st = start.atZone(zone).toInstant().toEpochMilli();
|
|
|
+ long et = end.atZone(zone).toInstant().toEpochMilli();
|
|
|
+
|
|
|
+ logger.info("[功率拟合] 处理时间段: {}~{}", start, end);
|
|
|
+ newDataFittingService.newDataFitting(
|
|
|
+ "NX_FGS_HA_FDC_STA", "NX_FGS_HA_F_WT_0001_EQ", st, et, 600,
|
|
|
+ true, true, true, true, true,
|
|
|
+ 2500, 25, 3, 0, 0, 10
|
|
|
+ );
|
|
|
+
|
|
|
+ logger.info("[功率拟合] 任务完成, 耗时{}ms", System.currentTimeMillis() - startTime);
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("预警报告计算运行失败", e);
|
|
|
+ logger.error("[功率拟合] 任务失败, 已运行{}ms", System.currentTimeMillis() - startTime, e);
|
|
|
}
|
|
|
}
|
|
|
|