|
@@ -0,0 +1,28 @@
|
|
|
|
|
+package com.liangjiang.price_collection.task;
|
|
|
|
|
+
|
|
|
|
|
+import com.liangjiang.price_collection.service.ITableService;
|
|
|
|
|
+import com.liangjiang.price_collection.service.impl.QueryService;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Component
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class DataTask {
|
|
|
|
|
+
|
|
|
|
|
+ private final ITableService tableService;
|
|
|
|
|
+ // 每天1点30
|
|
|
|
|
+ @Scheduled(cron="0 30 1 * * ? ")
|
|
|
|
|
+ public void deleteData() {
|
|
|
|
|
+ // 获取3天前时间
|
|
|
|
|
+ Integer[] time = QueryService.getDaysAgoTime(System.currentTimeMillis(), 3);
|
|
|
|
|
+ Integer threeDayAgo = time[1];
|
|
|
|
|
+ // 获取所有表名
|
|
|
|
|
+ List<String> tableNames = tableService.getTableNames();
|
|
|
|
|
+ // 清除数据
|
|
|
|
|
+ tableService.deleteData(tableNames, threeDayAgo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|