From 80412011affa7127986eed98eb307d19a025a75e Mon Sep 17 00:00:00 2001 From: hekaiyu <13673834656@163.com> Date: Fri, 12 Dec 2025 10:32:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81Scheduled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/properties/T1hDownloadProperties.java | 5 +++++ .../src/main/java/org/jeecg/job/DownloadT1hJob.java | 12 ++++++------ .../java/org/jeecg/JeecgWeatherCloudApplication.java | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/T1hDownloadProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/T1hDownloadProperties.java index 9eb0246..fdf548d 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/T1hDownloadProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/T1hDownloadProperties.java @@ -9,6 +9,11 @@ import org.springframework.stereotype.Component; @ConfigurationProperties(prefix = "t1h-download") public class T1hDownloadProperties { + /** + * 定时器cron + */ + private String cron; + /** * python环境路径 */ diff --git a/jeecg-module-weather/src/main/java/org/jeecg/job/DownloadT1hJob.java b/jeecg-module-weather/src/main/java/org/jeecg/job/DownloadT1hJob.java index 464a5fd..a185663 100644 --- a/jeecg-module-weather/src/main/java/org/jeecg/job/DownloadT1hJob.java +++ b/jeecg-module-weather/src/main/java/org/jeecg/job/DownloadT1hJob.java @@ -1,5 +1,6 @@ package org.jeecg.job; +import cn.hutool.core.date.StopWatch; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -12,8 +13,8 @@ import org.jeecg.common.util.ExecutePyUtils; import org.jeecg.modules.base.entity.WeatherData; import org.jeecg.service.WeatherDataService; import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.util.StopWatch; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.stereotype.Component; +import org.springframework.beans.factory.annotation.Value; import java.io.*; import java.nio.file.Files; @@ -29,17 +30,16 @@ import java.util.stream.Collectors; import java.util.stream.Stream; @Slf4j -@RestController @RequiredArgsConstructor +@Component public class DownloadT1hJob { private final WeatherDataService weatherDataService; private final SystemStorageProperties systemStorageProperties; private final T1hDownloadProperties t1hDownloadProperties; - private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd"); - private static final int PROCESS_TIMEOUT_SECONDS = 3600; // 30分钟超时 - @Scheduled(cron = "0 0 1 * * ?") + @Scheduled(cron = "#{@t1hDownloadProperties.cron}") +// @Scheduled(cron = "0 0 1 * * ?") public void downloadT1HFile() { log.info("开始执行T1H文件下载任务"); StopWatch stopWatch = new StopWatch(); diff --git a/jeecg-server-cloud/jeecg-weather-start/src/main/java/org/jeecg/JeecgWeatherCloudApplication.java b/jeecg-server-cloud/jeecg-weather-start/src/main/java/org/jeecg/JeecgWeatherCloudApplication.java index 45ec264..b6cbd37 100644 --- a/jeecg-server-cloud/jeecg-weather-start/src/main/java/org/jeecg/JeecgWeatherCloudApplication.java +++ b/jeecg-server-cloud/jeecg-weather-start/src/main/java/org/jeecg/JeecgWeatherCloudApplication.java @@ -14,6 +14,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.EnableScheduling; + import java.net.InetAddress; import java.net.UnknownHostException; @@ -21,6 +23,7 @@ import java.net.UnknownHostException; @SpringBootApplication @RequiredArgsConstructor @EnableFeignClients +@EnableScheduling public class JeecgWeatherCloudApplication extends SpringBootServletInitializer implements CommandLineRunner { private final RedisTemplate redisTemplate;