|
@@ -1,16 +1,21 @@
|
|
package com.huimv.production.task;
|
|
package com.huimv.production.task;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.huimv.production.domain.*;
|
|
import com.huimv.production.domain.*;
|
|
import com.huimv.production.repo.*;
|
|
import com.huimv.production.repo.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -35,93 +40,124 @@ public class WarningParameterTask {
|
|
@Autowired
|
|
@Autowired
|
|
private IndexParameterEntityRepo indexParameterEntityRepo;
|
|
private IndexParameterEntityRepo indexParameterEntityRepo;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private WarningInfoEntityRepo warningInfoEntityRepo;
|
|
|
|
|
|
+// @Autowired
|
|
|
|
+// private WarningInfoEntityRepo warningInfoEntityRepo;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private WarningParameterEntityRepo warningParameterEntityRepo;
|
|
private WarningParameterEntityRepo warningParameterEntityRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
+
|
|
@Transactional(rollbackOn = Throwable.class)
|
|
@Transactional(rollbackOn = Throwable.class)
|
|
- @Scheduled(cron = "0 0 0/12 * * ?")
|
|
|
|
-// @Scheduled(cron = "0 41 17 * * ?")
|
|
|
|
|
|
+// @Scheduled(cron = "0 0 0/12 * * ?")
|
|
|
|
+ @Scheduled(cron = "0 25 12 * * ?")
|
|
public void warningTask() {
|
|
public void warningTask() {
|
|
|
|
+ System.out.println(DateUtil.date() + ": -----------定时任务开启---------->");
|
|
List<ConfigEntity> all = configEntityRepo.findAll();
|
|
List<ConfigEntity> all = configEntityRepo.findAll();
|
|
- ConfigEntity configEntity = all.get(0);
|
|
|
|
- String propertyValue = configEntity.getValue();
|
|
|
|
|
|
+ ConfigEntity configEntity = null;
|
|
|
|
+ if (CollectionUtil.isNotEmpty(all)) {
|
|
|
|
+ configEntity = all.get(0);
|
|
|
|
+ }
|
|
|
|
+ String propertyValue = null;
|
|
|
|
+ if (configEntity != null) {
|
|
|
|
+ propertyValue = configEntity.getValue();
|
|
|
|
+ }
|
|
|
|
|
|
List<WarningParameter> warningParameterList = warningParameterEntityRepo.findAll();
|
|
List<WarningParameter> warningParameterList = warningParameterEntityRepo.findAll();
|
|
|
|
|
|
- //当前时间
|
|
|
|
- Date date = new Date();
|
|
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
|
|
|
|
+ headers.setContentType(type);
|
|
|
|
+ headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
|
|
|
- if ("true".equals(propertyValue)) {
|
|
|
|
- List<IndexParameter2Entity> localList = indexParameter2EntityRepo.findAll();
|
|
|
|
- List<IndexParameter2Entity> collect = localList.stream()
|
|
|
|
- .filter(localEntity -> warningParameterList.stream()
|
|
|
|
- .anyMatch(w -> w.getParameterName().equals(localEntity.getName())))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<IndexParameter2Entity> collect1 = collect.stream().filter(s -> warningParameterList.stream()
|
|
|
|
- .anyMatch(warningParameter -> warningParameter.getParameterName().equals(s.getName()) && warningParameter.getThresholdValue() >= Double.parseDouble(s.getData())))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- for (IndexParameter2Entity indexParameter2Entity : collect1) {
|
|
|
|
- WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
- warningInfoEntity.setUploadTime(new Date());
|
|
|
|
- warningInfoEntity.setWarningType(3);
|
|
|
|
- String type = "本地数据的 " + indexParameter2Entity.getName() + " 参数小于阈值";
|
|
|
|
- warningInfoEntity.setType(type);
|
|
|
|
- warningInfoEntityRepo.updatePreviousShowStatusByType(type);
|
|
|
|
- warningInfoEntityRepo.save(warningInfoEntity);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- collect.removeAll(collect1);
|
|
|
|
|
|
+ if ("true".equals(propertyValue)) {
|
|
|
|
|
|
- List<WarningInfoEntity> list = new ArrayList<>();
|
|
|
|
- for (IndexParameter2Entity indexParameter2Entity : collect) {
|
|
|
|
- List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("本地数据的 " + indexParameter2Entity.getName(), date);
|
|
|
|
- list.addAll(warningInfoEntityList);
|
|
|
|
- }
|
|
|
|
- for (WarningInfoEntity warningInfoEntity : list) {
|
|
|
|
- warningInfoEntity.setShowStatus(1);
|
|
|
|
- warningInfoEntityRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
|
|
+ List<IndexParameter2Entity> localList = indexParameter2EntityRepo.findAll();
|
|
|
|
+ if (CollectionUtil.isNotEmpty(localList)) {
|
|
|
|
+ List<IndexParameter2Entity> collect = localList.stream()
|
|
|
|
+ .filter(localEntity -> warningParameterList.stream()
|
|
|
|
+ .anyMatch(w -> w.getParameterName().equals(localEntity.getName())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<IndexParameter2Entity> collect1 = collect.stream().filter(s -> warningParameterList.stream()
|
|
|
|
+ .anyMatch(warningParameter -> warningParameter.getParameterName().equals(s.getName()) && warningParameter.getThresholdValue() >= Double.parseDouble(s.getData())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// for (IndexParameter2Entity indexParameter2Entity : collect1) {
|
|
|
|
+// WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
+// warningInfoEntity.setUploadTime(new Date());
|
|
|
|
+// warningInfoEntity.setWarningType(3);
|
|
|
|
+// String type = "本地数据的 " + indexParameter2Entity.getName() + " 参数小于阈值";
|
|
|
|
+// warningInfoEntity.setType(type);
|
|
|
|
+// warningInfoEntityRepo.updatePreviousShowStatusByType(type);
|
|
|
|
+// warningInfoEntityRepo.save(warningInfoEntity);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// List<IndexParameter2Entity> tempList = new ArrayList<>(collect);
|
|
|
|
+// tempList.removeAll(collect1);
|
|
|
|
+ collect.removeAll(collect1);
|
|
|
|
+
|
|
|
|
+ Map<String, List<IndexParameter2Entity>> param = new HashMap<>();
|
|
|
|
+ param.put("saveList", collect1);
|
|
|
|
+ param.put("updateList", collect);
|
|
|
|
+ HttpEntity httpEntity = new HttpEntity<>(param, headers);
|
|
|
|
+ restTemplate.postForObject("http://127.0.0.1:8085/productDataHandle/handleLocalWarningInfo", httpEntity, String.class);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if ("false".equals(propertyValue)) {
|
|
|
|
|
|
+// List<WarningInfoEntity> list = new ArrayList<>();
|
|
|
|
+// for (IndexParameter2Entity indexParameter2Entity : collect) {
|
|
|
|
+// List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("本地数据的 " + indexParameter2Entity.getName(), date);
|
|
|
|
+// list.addAll(warningInfoEntityList);
|
|
|
|
+// }
|
|
|
|
+// for (WarningInfoEntity warningInfoEntity : list) {
|
|
|
|
+// warningInfoEntity.setShowStatus(1);
|
|
|
|
+// warningInfoEntityRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
+// }
|
|
|
|
+ } else if ("false".equals(propertyValue)) {
|
|
List<IndexParameterEntity> localList = indexParameterEntityRepo.findAll();
|
|
List<IndexParameterEntity> localList = indexParameterEntityRepo.findAll();
|
|
- List<IndexParameterEntity> collect = localList.stream()
|
|
|
|
- .filter(localEntity -> warningParameterList.stream()
|
|
|
|
- .anyMatch(w -> w.getParameterName().equals(localEntity.getName())))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<IndexParameterEntity> collect1 = collect.stream().filter(s -> warningParameterList.stream()
|
|
|
|
- .anyMatch(warningParameter -> warningParameter.getParameterName().equals(s.getName()) && warningParameter.getThresholdValue() >= Double.parseDouble(s.getData())))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- for (IndexParameterEntity indexParameter2Entity : collect1) {
|
|
|
|
- WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
- warningInfoEntity.setUploadTime(new Date());
|
|
|
|
- warningInfoEntity.setWarningType(3);
|
|
|
|
- String type = "ERP数据的 " + indexParameter2Entity.getName() + " 参数小于阈值!";
|
|
|
|
- warningInfoEntity.setType(type);
|
|
|
|
- warningInfoEntityRepo.updatePreviousShowStatusByType(type);
|
|
|
|
- warningInfoEntityRepo.save(warningInfoEntity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- collect.removeAll(collect1);
|
|
|
|
-
|
|
|
|
- List<WarningInfoEntity> list = new ArrayList<>();
|
|
|
|
- for (IndexParameterEntity indexParameterEntity : collect) {
|
|
|
|
- List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("ERP数据的 " + indexParameterEntity.getName(), date);
|
|
|
|
- list.addAll(warningInfoEntityList);
|
|
|
|
- }
|
|
|
|
- for (WarningInfoEntity warningInfoEntity : list) {
|
|
|
|
- warningInfoEntity.setShowStatus(1);
|
|
|
|
- warningInfoEntityRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(localList)) {
|
|
|
|
+ List<IndexParameterEntity> collect = localList.stream()
|
|
|
|
+ .filter(localEntity -> warningParameterList.stream()
|
|
|
|
+ .anyMatch(w -> w.getParameterName().equals(localEntity.getName())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<IndexParameterEntity> collect1 = collect.stream().filter(s -> warningParameterList.stream()
|
|
|
|
+ .anyMatch(warningParameter -> warningParameter.getParameterName().equals(s.getName()) && warningParameter.getThresholdValue() >= Double.parseDouble(s.getData())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+// for (IndexParameterEntity indexParameter2Entity : collect1) {
|
|
|
|
+// WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
+// warningInfoEntity.setUploadTime(new Date());
|
|
|
|
+// warningInfoEntity.setWarningType(3);
|
|
|
|
+// String type = "ERP数据的 " + indexParameter2Entity.getName() + " 参数小于阈值!";
|
|
|
|
+// warningInfoEntity.setType(type);
|
|
|
|
+// warningInfoEntityRepo.updatePreviousShowStatusByType(type);
|
|
|
|
+// warningInfoEntityRepo.save(warningInfoEntity);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ collect.removeAll(collect1);
|
|
|
|
+ Map<String, List<IndexParameterEntity>> param = new HashMap<>();
|
|
|
|
+ param.put("saveLiSt", collect1);
|
|
|
|
+ param.put("updateList", collect);
|
|
|
|
+ HttpEntity httpEntity = new HttpEntity<>(param, headers);
|
|
|
|
+ restTemplate.postForObject("http://127.0.0.1:8085/productDataHandle/handleERPWarningInfo", httpEntity, String.class);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// List<WarningInfoEntity> list = new ArrayList<>();
|
|
|
|
+// for (IndexParameterEntity indexParameterEntity : collect) {
|
|
|
|
+// List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("ERP数据的 " + indexParameterEntity.getName(), date);
|
|
|
|
+// list.addAll(warningInfoEntityList);
|
|
|
|
+// }
|
|
|
|
+// for (WarningInfoEntity warningInfoEntity : list) {
|
|
|
|
+// warningInfoEntity.setShowStatus(1);
|
|
|
|
+// warningInfoEntityRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ System.out.println(DateUtil.date() + ": -----------定时任务执行完毕---------->");
|
|
}
|
|
}
|
|
}
|
|
}
|