diff --git a/jeecg-module-weather/src/main/java/org/jeecg/job/CleanWeatherCacheData.java b/jeecg-module-weather/src/main/java/org/jeecg/job/CleanWeatherCacheData.java new file mode 100644 index 0000000..689f060 --- /dev/null +++ b/jeecg-module-weather/src/main/java/org/jeecg/job/CleanWeatherCacheData.java @@ -0,0 +1,36 @@ +package org.jeecg.job; + +import lombok.RequiredArgsConstructor; +import org.apache.commons.io.FileUtils; +import org.jeecg.common.properties.SystemStorageProperties; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * 每周六凌晨2点清除天气预报缓存数据 + */ +@Component +@RequiredArgsConstructor +public class CleanWeatherCacheData { + + private final SystemStorageProperties systemStorageProperties; + + @Scheduled(cron = "0 0 2 ? * SAT") + public void cleanCacheData(){ + + Path path = Paths.get(systemStorageProperties.getGribDataVariableCachePath()); + if(Files.exists(path)){ + try{ + FileUtils.cleanDirectory(path.toFile()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + } +}