|
@@ -1,15 +1,17 @@
|
|
|
package org.jeecg.modules.interlockjob;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.modules.base.entity.InterlockBase;
|
|
|
+import org.jeecg.modules.base.entity.InterlockBaseHy;
|
|
|
+import org.jeecg.modules.base.service.IInterlockBaseHyService;
|
|
|
import org.jeecg.modules.base.service.IInterlockBaseService;
|
|
|
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.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
|
|
|
+import org.jeecg.modules.interlockCountDay.service.IInterlockCountDayService;
|
|
|
import org.quartz.Job;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
import org.quartz.JobExecutionException;
|
|
@@ -18,7 +20,6 @@ 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;
|
|
@@ -44,7 +45,7 @@ public class DayStatisticsJob implements Job {
|
|
|
|
|
|
@Autowired
|
|
|
@SuppressWarnings("all")
|
|
|
- private IInterlockCountService countService;
|
|
|
+ private IInterlockCountDayService countService;
|
|
|
|
|
|
@Autowired
|
|
|
@SuppressWarnings("all")
|
|
@@ -54,54 +55,58 @@ public class DayStatisticsJob implements Job {
|
|
|
@SuppressWarnings("all")
|
|
|
private IInterlockBaseService baseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockBaseHyService baseHyService;
|
|
|
+
|
|
|
@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"); // 当前日期
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String currentDay = DateUtils.getDate("yyyy-MM-dd HH:mm:ss"); // 当前日期
|
|
|
LocalDate yesterDate = LocalDate.now().minusDays(1); // 当前 00:00:00 执行定时任务 减一天获取昨天的日期
|
|
|
- //String yesterday = yesterDate.format(formatter); // 昨天的日期
|
|
|
- String yesterday = "2024-06-26"; // 测试模拟的昨天日期
|
|
|
+ String yesterday = yesterDate.format(formatter); // 昨天的日期
|
|
|
+ //String yesterday = "2024-06-28 00:00:00"; // 测试模拟的昨天日期
|
|
|
|
|
|
// 统计健康等级 count_type = 0
|
|
|
- List<InterlockCount> loopHealthLevelList = summaryHistoryService.getLoopHealthLevelByTagTime(yesterday);
|
|
|
+ List<InterlockCountDay> loopHealthLevelList = summaryHistoryService.getLoopHealthLevelByTagTime(yesterday);
|
|
|
|
|
|
- HashMap<String, List<InterlockCount>> loopHealthLevelMap = new HashMap<>();
|
|
|
- for (InterlockCount item:loopHealthLevelList) {
|
|
|
+ HashMap<String, List<InterlockCountDay>> loopHealthLevelMap = new HashMap<>();
|
|
|
+ for (InterlockCountDay item:loopHealthLevelList) {
|
|
|
if (loopHealthLevelMap.containsKey(item.getInterlockSystemId())){
|
|
|
loopHealthLevelMap.get(item.getInterlockSystemId()).add(item);
|
|
|
}else {
|
|
|
- ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ ArrayList<InterlockCountDay> countList = new ArrayList<>();
|
|
|
countList.add(item);
|
|
|
loopHealthLevelMap.put(item.getInterlockSystemId(),countList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ArrayList<InterlockCount> loopHealthLevelResultList = new ArrayList<>();
|
|
|
+ ArrayList<InterlockCountDay> 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);
|
|
|
+ List<InterlockCountDay> sonList = loopHealthLevelMap.get(key);
|
|
|
if (sonList.size() != 4){
|
|
|
ArrayList<String> jkdjList = new ArrayList<>();
|
|
|
- for (InterlockCount son : sonList) {
|
|
|
+ for (InterlockCountDay 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();
|
|
|
+ InterlockCountDay interlockCount = new InterlockCountDay();
|
|
|
interlockCount.setInterlockSystemId(key);
|
|
|
+ interlockCount.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
interlockCount.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
interlockCount.setCountName(d);
|
|
|
interlockCount.setCountNum("0");
|
|
|
interlockCount.setCountType("0");
|
|
|
- interlockCount.setTimeType("10");
|
|
|
- interlockCount.setDay(yesterday);
|
|
|
+ interlockCount.setTime(yesterday);
|
|
|
sonList.add(interlockCount);
|
|
|
}
|
|
|
}
|
|
@@ -112,20 +117,20 @@ public class DayStatisticsJob implements Job {
|
|
|
//countService.saveBatch(loopHealthLevelResultList);
|
|
|
|
|
|
// 统计联锁状态(投用/未投用) count_type = 1
|
|
|
- List<InterlockCount> interlockStatusList = summaryHistoryService.getInterlockStatusByTagTime(yesterday);
|
|
|
+ List<InterlockCountDay> interlockStatusList = summaryHistoryService.getInterlockStatusByTagTime(yesterday);
|
|
|
|
|
|
- HashMap<String, List<InterlockCount>> interlockStatusMap = new HashMap<>();
|
|
|
- for (InterlockCount item:interlockStatusList) {
|
|
|
+ HashMap<String, List<InterlockCountDay>> interlockStatusMap = new HashMap<>();
|
|
|
+ for (InterlockCountDay item:interlockStatusList) {
|
|
|
if (interlockStatusMap.containsKey(item.getInterlockSystemId())){
|
|
|
interlockStatusMap.get(item.getInterlockSystemId()).add(item);
|
|
|
}else {
|
|
|
- ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ ArrayList<InterlockCountDay> countList = new ArrayList<>();
|
|
|
countList.add(item);
|
|
|
interlockStatusMap.put(item.getInterlockSystemId(),countList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ArrayList<InterlockCount> interlockStatusResultList = new ArrayList<>();
|
|
|
+ ArrayList<InterlockCountDay> interlockStatusResultList = new ArrayList<>();
|
|
|
//ArrayList<String> lsList = new ArrayList<>();
|
|
|
//lsList.add("0");
|
|
|
//lsList.add("1");
|
|
@@ -134,41 +139,45 @@ public class DayStatisticsJob implements Job {
|
|
|
ArrayList<String> lsList = new ArrayList<>();
|
|
|
lsList.add(base.getInterlockStatusTy());
|
|
|
lsList.add(inversionStatus(base.getInterlockStatusTy()));
|
|
|
- List<InterlockCount> sonList = interlockStatusMap.get(key);
|
|
|
+ List<InterlockCountDay> sonList = interlockStatusMap.get(key);
|
|
|
if (sonList.size() != 2){
|
|
|
ArrayList<String> lsStatusList = new ArrayList<>();
|
|
|
- for (InterlockCount son : sonList) {
|
|
|
+ for (InterlockCountDay 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();
|
|
|
+ InterlockCountDay interlockCount = new InterlockCountDay();
|
|
|
interlockCount.setInterlockSystemId(key);
|
|
|
+ interlockCount.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
interlockCount.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
interlockCount.setCountName(d);
|
|
|
interlockCount.setCountNum("0");
|
|
|
interlockCount.setCountType("1");
|
|
|
- interlockCount.setTimeType("10");
|
|
|
- interlockCount.setDay(yesterday);
|
|
|
+ interlockCount.setTime(yesterday);
|
|
|
sonList.add(interlockCount);
|
|
|
}
|
|
|
}
|
|
|
+ for (InterlockCountDay son : sonList) {
|
|
|
+ InterlockBaseHy baseHy = getBaseHyByQuery("interlock_status",key,son.getCountName());
|
|
|
+ son.setCountName(baseHy.getInterlockStatusName());
|
|
|
+ }
|
|
|
interlockStatusResultList.addAll(sonList);
|
|
|
}
|
|
|
|
|
|
//countService.saveBatch(interlockStatusResultList);
|
|
|
|
|
|
// 统计投用率 count_type = 2
|
|
|
- ArrayList<InterlockCount> tylResultList = new ArrayList<>();
|
|
|
+ ArrayList<InterlockCountDay> tylResultList = new ArrayList<>();
|
|
|
|
|
|
- HashMap<String, List<InterlockCount>> tylMap = new HashMap<>();
|
|
|
- for (InterlockCount item:interlockStatusResultList) {
|
|
|
+ HashMap<String, List<InterlockCountDay>> tylMap = new HashMap<>();
|
|
|
+ for (InterlockCountDay item:interlockStatusResultList) {
|
|
|
if (tylMap.containsKey(item.getInterlockSystemId())){
|
|
|
tylMap.get(item.getInterlockSystemId()).add(item);
|
|
|
}else {
|
|
|
- ArrayList<InterlockCount> countList = new ArrayList<>();
|
|
|
+ ArrayList<InterlockCountDay> countList = new ArrayList<>();
|
|
|
countList.add(item);
|
|
|
tylMap.put(item.getInterlockSystemId(),countList);
|
|
|
}
|
|
@@ -176,15 +185,17 @@ public class DayStatisticsJob implements Job {
|
|
|
|
|
|
for (String key:tylMap.keySet()) {
|
|
|
InterlockBase base = baseService.getById(key);
|
|
|
- List<InterlockCount> sonList = tylMap.get(key);
|
|
|
+ List<InterlockCountDay> sonList = tylMap.get(key);
|
|
|
BigDecimal yty = BigDecimal.valueOf(0);
|
|
|
BigDecimal wty = BigDecimal.valueOf(0);
|
|
|
BigDecimal tyl = BigDecimal.valueOf(0);
|
|
|
- for (InterlockCount son:sonList) {
|
|
|
- if (inversionStatus(base.getInterlockStatusTy()).equals(son.getCountName())){
|
|
|
+ for (InterlockCountDay son:sonList) {
|
|
|
+ InterlockBaseHy baseHy1 = getBaseHyByQuery("interlock_status",key,inversionStatus(base.getInterlockStatusTy()));
|
|
|
+ InterlockBaseHy baseHy2 = getBaseHyByQuery("interlock_status",key,base.getInterlockStatusTy());
|
|
|
+ if (baseHy1.getInterlockStatusName().equals(son.getCountName())){
|
|
|
wty = wty.add(new BigDecimal(son.getCountNum()));
|
|
|
}
|
|
|
- if (base.getInterlockStatusTy().equals(son.getCountName())){
|
|
|
+ if (baseHy2.getInterlockStatusName().equals(son.getCountName())){
|
|
|
yty = yty.add(new BigDecimal(son.getCountNum()));
|
|
|
}
|
|
|
}
|
|
@@ -192,92 +203,100 @@ public class DayStatisticsJob implements Job {
|
|
|
if ((total.compareTo(BigDecimal.valueOf(0)) != 0)){
|
|
|
tyl = yty.divide(total,2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
|
|
|
}
|
|
|
- InterlockCount interlockCount = new InterlockCount();
|
|
|
+ InterlockCountDay interlockCount = new InterlockCountDay();
|
|
|
interlockCount.setInterlockSystemId(key);
|
|
|
+ interlockCount.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
interlockCount.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
interlockCount.setCountName("投用率");
|
|
|
interlockCount.setCountNum(String.valueOf(tyl));
|
|
|
interlockCount.setCountType("2");
|
|
|
- interlockCount.setTimeType("10");
|
|
|
- interlockCount.setDay(yesterday);
|
|
|
+ interlockCount.setTime(yesterday);
|
|
|
tylResultList.add(interlockCount);
|
|
|
}
|
|
|
|
|
|
//countService.saveBatch(tylResultList);
|
|
|
|
|
|
// 统计仪表状态 count_type = 3
|
|
|
- List<InterlockCount> ybStatusList = summaryHistoryService.getYbStatusListByTagTime(yesterday);
|
|
|
-
|
|
|
- ArrayList<InterlockCount> ybResultList = new ArrayList<>();
|
|
|
-
|
|
|
- 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()) {
|
|
|
- InterlockBase base = baseService.getById(key);
|
|
|
- List<InterlockCount> interlockList = ybStatusMap.get(key);
|
|
|
- for (InterlockCount item : interlockList) {
|
|
|
- int count = 0;
|
|
|
- List<InterlockDetailHistory> detailHistoryList = detailHistoryService.getYbStatusListBySummaryIdAndTagTime(item.getId(),yesterday);
|
|
|
- // 遍历集合 查询仪表状态 是否异常 如果有一个异常的 总的仪表状态为异常
|
|
|
- for (InterlockDetailHistory detail : detailHistoryList) {
|
|
|
- if (inversionStatus(base.getInstrumentStatusNormal()).equals(detail.getInstrumentStatus())){
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (count != 0){
|
|
|
- item.setCountNum("1");
|
|
|
- }
|
|
|
- }
|
|
|
- int totalCount1 = 0; // 异常的数量
|
|
|
- int totalCount2 = 0; // 正常的数量
|
|
|
- for (InterlockCount item : interlockList) {
|
|
|
- if ("1".equals(item.getCountNum())){
|
|
|
- totalCount1++;
|
|
|
- }else {
|
|
|
- totalCount2++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- InterlockCount interlockCount1 = new InterlockCount();
|
|
|
- interlockCount1.setInterlockSystemId(key);
|
|
|
- interlockCount1.setInterlockName(interlockList.get(0).getInterlockName());
|
|
|
- interlockCount1.setCountName(base.getInstrumentStatusNormal());
|
|
|
- interlockCount1.setCountNum(String.valueOf(totalCount2));
|
|
|
- interlockCount1.setCountType("3");
|
|
|
- interlockCount1.setTimeType("10");
|
|
|
- interlockCount1.setDay(yesterday);
|
|
|
-
|
|
|
- InterlockCount interlockCount2 = new InterlockCount();
|
|
|
- interlockCount2.setInterlockSystemId(key);
|
|
|
- interlockCount2.setInterlockName(interlockList.get(0).getInterlockName());
|
|
|
- interlockCount2.setCountName(inversionStatus(base.getInstrumentStatusNormal()));
|
|
|
- interlockCount2.setCountNum(String.valueOf(totalCount1));
|
|
|
- interlockCount2.setCountType("3");
|
|
|
- interlockCount2.setTimeType("10");
|
|
|
- interlockCount2.setDay(yesterday);
|
|
|
-
|
|
|
- ybResultList.add(interlockCount1);
|
|
|
- ybResultList.add(interlockCount2);
|
|
|
- }
|
|
|
+ //List<InterlockCountDay> ybStatusList = summaryHistoryService.getYbStatusListByTagTime(yesterday);
|
|
|
+ //
|
|
|
+ //ArrayList<InterlockCountDay> ybResultList = new ArrayList<>();
|
|
|
+ //
|
|
|
+ //HashMap<String, List<InterlockCountDay>> ybStatusMap = new HashMap<>();
|
|
|
+ //for (InterlockCountDay item:ybStatusList) {
|
|
|
+ // if (ybStatusMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ // ybStatusMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ // }else {
|
|
|
+ // ArrayList<InterlockCountDay> countList = new ArrayList<>();
|
|
|
+ // countList.add(item);
|
|
|
+ // ybStatusMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //for (String key : ybStatusMap.keySet()) {
|
|
|
+ // InterlockBase base = baseService.getById(key);
|
|
|
+ // List<InterlockCountDay> interlockList = ybStatusMap.get(key);
|
|
|
+ // for (InterlockCountDay item : interlockList) {
|
|
|
+ // int count = 0;
|
|
|
+ // List<InterlockDetailHistory> detailHistoryList = detailHistoryService.getYbStatusListBySummaryIdAndTagTime(item.getId(),yesterday);
|
|
|
+ // // 遍历集合 查询仪表状态 是否异常 如果有一个异常的 总的仪表状态为异常
|
|
|
+ // for (InterlockDetailHistory detail : detailHistoryList) {
|
|
|
+ // if (inversionStatus(base.getInstrumentStatusNormal()).equals(detail.getInstrumentStatus())){
|
|
|
+ // count++;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (count != 0){
|
|
|
+ // item.setCountNum("1");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // int totalCount1 = 0; // 异常的数量
|
|
|
+ // int totalCount2 = 0; // 正常的数量
|
|
|
+ // for (InterlockCountDay item : interlockList) {
|
|
|
+ // if ("1".equals(item.getCountNum())){
|
|
|
+ // totalCount1++;
|
|
|
+ // }else {
|
|
|
+ // totalCount2++;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // InterlockBaseHy ybHy1 = getBaseHyByQuery("instrument_status", key, base.getInstrumentStatusNormal());
|
|
|
+ //
|
|
|
+ // InterlockCountDay interlockCount1 = new InterlockCountDay();
|
|
|
+ // interlockCount1.setInterlockSystemId(key);
|
|
|
+ // interlockCount1.setDeviceId(interlockList.get(0).getDeviceId());
|
|
|
+ // interlockCount1.setInterlockName(interlockList.get(0).getInterlockName());
|
|
|
+ // interlockCount1.setCountName(ybHy1.getInstrumentStatusName());
|
|
|
+ // interlockCount1.setCountNum(String.valueOf(totalCount2));
|
|
|
+ // interlockCount1.setCountType("3");
|
|
|
+ // interlockCount1.setTime(yesterday);
|
|
|
+ //
|
|
|
+ // InterlockBaseHy ybHy2 = getBaseHyByQuery("instrument_status", key, inversionStatus(base.getInstrumentStatusNormal()));
|
|
|
+ //
|
|
|
+ // InterlockCountDay interlockCount2 = new InterlockCountDay();
|
|
|
+ // interlockCount2.setInterlockSystemId(key);
|
|
|
+ // interlockCount2.setDeviceId(interlockList.get(0).getDeviceId());
|
|
|
+ // interlockCount2.setInterlockName(interlockList.get(0).getInterlockName());
|
|
|
+ // interlockCount2.setCountName(ybHy2.getInstrumentStatusName());
|
|
|
+ // interlockCount2.setCountNum(String.valueOf(totalCount1));
|
|
|
+ // interlockCount2.setCountType("3");
|
|
|
+ // interlockCount2.setTime(yesterday);
|
|
|
+ //
|
|
|
+ // ybResultList.add(interlockCount1);
|
|
|
+ // ybResultList.add(interlockCount2);
|
|
|
+ //}
|
|
|
|
|
|
|
|
|
// 统计系统状态 count_type = 4
|
|
|
+ //ArrayList<InterlockCountDay> xtStatusResultList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 批量保存
|
|
|
- List<InterlockCount> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), Stream.concat(interlockStatusResultList.stream(),ybResultList.stream())), tylResultList.stream())
|
|
|
+ //List<InterlockCountDay> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), Stream.concat(Stream.concat(interlockStatusResultList.stream(),xtStatusResultList.stream()),ybResultList.stream())), tylResultList.stream())
|
|
|
+ // .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<InterlockCountDay> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), interlockStatusResultList.stream()),tylResultList.stream())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
countService.saveBatch(list);
|
|
@@ -285,6 +304,12 @@ public class DayStatisticsJob implements Job {
|
|
|
log.info("日统计任务执行成功!");
|
|
|
}
|
|
|
|
|
|
+ private InterlockBaseHy getBaseHyByQuery(String field, String systemId, String status) {
|
|
|
+ QueryWrapper<InterlockBaseHy> query = new QueryWrapper<>();
|
|
|
+ query.eq("interlock_system_id",systemId).eq(field,status);
|
|
|
+ return baseHyService.getOne(query);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* author: dzc
|
|
|
* version: 1.0
|