|
@@ -0,0 +1,235 @@
|
|
|
+package org.jeecg.modules.interlockjob;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.modules.history.entity.InterlockDetailHistory;
|
|
|
+import org.jeecg.modules.history.entity.InterlockSummaryHistory;
|
|
|
+import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
|
|
|
+import org.jeecg.modules.history.service.IInterlockSummaryHistoryService;
|
|
|
+import org.jeecg.modules.interlockCount.entity.InterlockCount;
|
|
|
+import org.jeecg.modules.interlockCount.service.IInterlockCountService;
|
|
|
+import org.quartz.Job;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.quartz.JobExecutionException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author dzc
|
|
|
+ * @date 2024/6/14 10:00
|
|
|
+ * @package org.jeecg.modules.jod
|
|
|
+ * @project interlock_server
|
|
|
+ * @des 联锁 健康等级 仪表状态 投用率 日统计的定时任务
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class DayStatisticsJob implements Job {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockSummaryHistoryService summaryHistoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockCountService countService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockDetailHistoryService detailHistoryService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
+ // 日统计的定时任务 统计 每个系统下的每个联锁 健康等级(A/B/C/D)、联锁状态,每个联锁条件的仪表状态 的个数
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String currentDay = DateUtils.getDate("yyyy-MM-dd"); // 当前日期
|
|
|
+ LocalDate yesterDate = LocalDate.now().minusDays(1); // 当前 00:00:00 执行定时任务 减一天获取昨天的日期
|
|
|
+ //String yesterday = yesterDate.format(formatter); // 昨天的日期
|
|
|
+ String yesterday = "2024-06-12"; // 昨天的日期
|
|
|
+
|
|
|
+ // 统计健康等级 count_type = 0
|
|
|
+ List<InterlockCount> loopHealthLevelList = summaryHistoryService.getLoopHealthLevelByTagTime(yesterday);
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCount>> loopHealthLevelMap = new HashMap<>();
|
|
|
+ for (InterlockCount item:loopHealthLevelList) {
|
|
|
+ if (loopHealthLevelMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ loopHealthLevelMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ loopHealthLevelMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<InterlockCount> loopHealthLevelResultList = new ArrayList<>();
|
|
|
+ ArrayList<String> djList = new ArrayList<>();
|
|
|
+ djList.add("A");
|
|
|
+ djList.add("B");
|
|
|
+ djList.add("C");
|
|
|
+ djList.add("D");
|
|
|
+ for (String key:loopHealthLevelMap.keySet()){
|
|
|
+ List<InterlockCount> sonList = loopHealthLevelMap.get(key);
|
|
|
+ if (sonList.size() != 4){
|
|
|
+ ArrayList<String> jkdjList = new ArrayList<>();
|
|
|
+ for (InterlockCount son : sonList) {
|
|
|
+ jkdjList.add(son.getCountName());
|
|
|
+ }
|
|
|
+ List<String> difference = djList.stream()
|
|
|
+ .filter(item -> !jkdjList.contains(item))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (String d:difference) {
|
|
|
+ InterlockCount interlockCount = new InterlockCount();
|
|
|
+ interlockCount.setInterlockSystemId(key);
|
|
|
+ interlockCount.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCount.setCountName(d);
|
|
|
+ interlockCount.setCountNum("0");
|
|
|
+ interlockCount.setCountType("0");
|
|
|
+ interlockCount.setTimeType("10");
|
|
|
+ interlockCount.setDay(yesterday);
|
|
|
+ sonList.add(interlockCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loopHealthLevelResultList.addAll(sonList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量保存健康等级
|
|
|
+ //countService.saveBatch(loopHealthLevelResultList);
|
|
|
+
|
|
|
+ // 统计联锁状态(投用/未投用) count_type = 1
|
|
|
+ List<InterlockCount> interlockStatusList = summaryHistoryService.getInterlockStatusByTagTime(yesterday);
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCount>> interlockStatusMap = new HashMap<>();
|
|
|
+ for (InterlockCount item:interlockStatusList) {
|
|
|
+ if (interlockStatusMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ interlockStatusMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ interlockStatusMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<InterlockCount> interlockStatusResultList = new ArrayList<>();
|
|
|
+ ArrayList<String> lsList = new ArrayList<>();
|
|
|
+ lsList.add("0");
|
|
|
+ lsList.add("1");
|
|
|
+ for (String key:interlockStatusMap.keySet()){
|
|
|
+ List<InterlockCount> sonList = interlockStatusMap.get(key);
|
|
|
+ if (sonList.size() != 4){
|
|
|
+ ArrayList<String> lsStatusList = new ArrayList<>();
|
|
|
+ for (InterlockCount son : sonList) {
|
|
|
+ lsStatusList.add(son.getCountName());
|
|
|
+ }
|
|
|
+ List<String> difference = lsList.stream()
|
|
|
+ .filter(item -> !lsStatusList.contains(item))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (String d:difference) {
|
|
|
+ InterlockCount interlockCount = new InterlockCount();
|
|
|
+ interlockCount.setInterlockSystemId(key);
|
|
|
+ interlockCount.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCount.setCountName(d);
|
|
|
+ interlockCount.setCountNum("0");
|
|
|
+ interlockCount.setCountType("1");
|
|
|
+ interlockCount.setTimeType("10");
|
|
|
+ interlockCount.setDay(yesterday);
|
|
|
+ sonList.add(interlockCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ interlockStatusResultList.addAll(sonList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //countService.saveBatch(interlockStatusResultList);
|
|
|
+
|
|
|
+ // 统计投用率 count_type = 2
|
|
|
+ ArrayList<InterlockCount> tylResultList = new ArrayList<>();
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCount>> tylMap = new HashMap<>();
|
|
|
+ for (InterlockCount item:interlockStatusResultList) {
|
|
|
+ if (tylMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ tylMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ tylMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String key:tylMap.keySet()) {
|
|
|
+ List<InterlockCount> sonList = tylMap.get(key);
|
|
|
+ BigDecimal yty = BigDecimal.valueOf(0);
|
|
|
+ BigDecimal wty = BigDecimal.valueOf(0);
|
|
|
+ BigDecimal tyl = BigDecimal.valueOf(0);
|
|
|
+ for (InterlockCount son:sonList) {
|
|
|
+ if ("0".equals(son.getCountName())){
|
|
|
+ wty = wty.add(new BigDecimal(son.getCountNum()));
|
|
|
+ }
|
|
|
+ if ("1".equals(son.getCountName())){
|
|
|
+ yty = yty.add(new BigDecimal(son.getCountNum()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal total = yty.add(wty);
|
|
|
+ if ((total.compareTo(BigDecimal.valueOf(0)) != 0)){
|
|
|
+ tyl = yty.divide(total,2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
|
|
|
+ }
|
|
|
+ InterlockCount interlockCount = new InterlockCount();
|
|
|
+ interlockCount.setInterlockSystemId(key);
|
|
|
+ interlockCount.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCount.setCountName("投用率");
|
|
|
+ interlockCount.setCountNum(String.valueOf(tyl));
|
|
|
+ interlockCount.setCountType("2");
|
|
|
+ interlockCount.setTimeType("10");
|
|
|
+ interlockCount.setDay(yesterday);
|
|
|
+ tylResultList.add(interlockCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ //countService.saveBatch(tylResultList);
|
|
|
+
|
|
|
+ // 统计仪表状态 count_type = 3
|
|
|
+ List<InterlockCount> ybStatusList = summaryHistoryService.getYbStatusListByTagTime(yesterday);
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCount>> ybStatusMap = new HashMap<>();
|
|
|
+ for (InterlockCount item:ybStatusList) {
|
|
|
+ if (ybStatusMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ ybStatusMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ ybStatusMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String key : ybStatusMap.keySet()) {
|
|
|
+ List<InterlockCount> interlockList = ybStatusMap.get(key);
|
|
|
+ for (InterlockCount item : interlockList) {
|
|
|
+ List<InterlockDetailHistory> detailHistoryList = detailHistoryService.getYbStatusListBySummaryIdAndTagTime(item.getId(),yesterday);
|
|
|
+ // 遍历集合 查询仪表状态 是否异常 如果有一个异常的 联锁状态为异常
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 统计系统状态 count_type = 4
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 批量保存
|
|
|
+ List<InterlockCount> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), interlockStatusResultList.stream()), tylResultList.stream())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ countService.saveBatch(list);
|
|
|
+
|
|
|
+ log.info("日统计任务执行成功!");
|
|
|
+ }
|
|
|
+}
|