|
@@ -0,0 +1,50 @@
|
|
|
+package com.onemap.file.task;
|
|
|
+
|
|
|
+import com.onemap.common.core.utils.DateUtils;
|
|
|
+import com.onemap.file.service.ISysFileService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+/***
|
|
|
+ * 每天晚上0点10读取配置文件
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ReadFolderSchedule {
|
|
|
+ @Autowired
|
|
|
+ private ISysFileService sysFileService;
|
|
|
+
|
|
|
+ @Value("${file.readfolder}")
|
|
|
+ private String folder;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <pre>
|
|
|
+ * Scheduled 定时器参数
|
|
|
+ * cron表达式:指定任务在特定时间执行
|
|
|
+ * fixedDelay:表示上一次任务执行完成后多久再执行,参数类型long,单位:ms
|
|
|
+ * fixedDelayString:与fixedDelay一样,只是参数类型是String
|
|
|
+ * fixedRate:表示按一定的频率执行任务,参数类型long,单位:ms 如: fixedRate(5000),表示这个定时器任务每5秒执行一次
|
|
|
+ * fixedRateString:与fixedRate一样,只是参数类型变为String
|
|
|
+ * initialDelay:表示延迟多久再第一次执行任务,参数类型为long ,单位:ms
|
|
|
+ * initialDelayString:与initialDelay一样,只是参数类型String
|
|
|
+ * </pre>
|
|
|
+ * <br>
|
|
|
+ * 每天早上2点执行一次
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 10 0 * * ?")
|
|
|
+ public void ReadFolderStatus() {
|
|
|
+ log.info("ReadFolderStatus start date :" + DateUtils.getTime());
|
|
|
+ File file = new File(folder);
|
|
|
+ if (!file.exists() || !file.isDirectory()) {
|
|
|
+ log.error("ReadFolderStatus folder is not exists or isDirectory");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sysFileService.getReadFolder(file);
|
|
|
+ log.info("ReadFolderStatus end date :" + DateUtils.getTime());
|
|
|
+ }
|
|
|
+}
|