فهرست منبع

添加定时任务

yq 4 سال پیش
والد
کامیت
e460c96932

+ 2 - 0
fiveep-controller/src/main/java/com/bizmatics/controller/DemoControllerApplication.java

@@ -6,6 +6,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 @EnableElasticsearchRepositories(basePackages = "com.bizmatics.persistence.mapper.es")
@@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @ComponentScan("com.bizmatics")
 @SpringBootApplication
 @EnableTransactionManagement
+@EnableScheduling
 public class DemoControllerApplication {
 
     public static void main(String[] args) {

+ 28 - 0
fiveep-service/src/main/java/com/bizmatics/service/job/RatAnalogTask.java

@@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.poi.ss.usermodel.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -102,4 +103,31 @@ public class RatAnalogTask {
                 .build();
         hadVoList.add(hadDataLogVO);
     }
+
+//    @Scheduled(cron = "*/5 * * * * ?")
+    @Scheduled(cron = "0 0 0 */1 * ?")
+    public void addHadJob(){
+        List<HtAnalogData> list = null;
+        Integer index = 1;
+        Date date = new Date();
+        do {
+            Page<HtAnalogData> page = new Page<>(index, 4000);
+            page = htAnalogDataMapper.page(page, DateUtils.getDayStartTime(date),DateUtils.getDayEndTime(date),null);
+            list = page.getRecords();
+            if (!CollectionUtils.isEmpty(list)){
+                List<HtAnalogData> collect = list.stream().sorted(Comparator.comparing(HtAnalogData::getSiteId)).collect(Collectors.toList());
+                List<List<HtAnalogData>> rsList = Lists.partition(collect, 2000);
+                for (List<HtAnalogData> logVOS:rsList) {
+                    ArrayList<HtAnalogData> distant = logVOS.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(HtAnalogData::getSiteId))), ArrayList::new));
+                    List<Integer> siteList = distant.stream().map(HtAnalogData::getSiteId).collect(Collectors.toList());
+                    HadDataLog hadDataLog = new HadDataLog();
+                    hadDataLog.setDataTime(DateUtils.getDayStartTime(date));
+                    hadDataLog.setSiteIdList(JsonUtils.toJson(siteList));
+                    hadDataLog.setHadData(JsonUtils.toJson(logVOS));
+                    hadDataLogMapper.insert(hadDataLog);
+                }
+            }
+        }while (!CollectionUtils.isEmpty(list));
+        log.info("处理完成");
+    }
 }