|
|
|
|
@@ -22,6 +22,7 @@ import java.math.RoundingMode;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.*;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@@ -48,6 +49,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
List<String> monotorIds = lines.stream().map(AlarmPO::getId).collect(Collectors.toList());
|
|
|
|
|
// 装置id集合
|
|
|
|
|
List<String> devIds = new ArrayList<>(devMap.keySet());
|
|
|
|
|
// 获取异常告警策略
|
|
|
|
|
List<AlarmStrategyVO> alarmStrategyVOS = deviceAbnormaStatisticsMapper.selectAlarmStrategy();
|
|
|
|
|
Map<Integer, List<AlarmStrategyVO>> levMap = alarmStrategyVOS.stream().collect(Collectors.groupingBy(AlarmStrategyVO::getAlgoDesc));
|
|
|
|
|
// 获取监测点数据完整性
|
|
|
|
|
List<AlarmPO> lineIntegritys = deviceAbnormaStatisticsMapper.getIntegrityByLineIds(
|
|
|
|
|
monotorIds,
|
|
|
|
|
@@ -68,41 +72,45 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
if (CollectionUtil.isNotEmpty(deviceFlowAndOnlineRate)) {
|
|
|
|
|
deviceFlowAndOnlineRateMap = deviceFlowAndOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取通信中断信息
|
|
|
|
|
// List<String> list = Arrays.asList("025fa0e4c91f72ad7f1c1bd29026f20a");
|
|
|
|
|
List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime(), param.getTime());
|
|
|
|
|
List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime());
|
|
|
|
|
if (CollectionUtil.isNotEmpty(comMsgs)) {
|
|
|
|
|
comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId));
|
|
|
|
|
}
|
|
|
|
|
// 比对告警策略并落表
|
|
|
|
|
List<AlarmStrategyVO> alarmStrategyVOS = deviceAbnormaStatisticsMapper.selectAlarmStrategy();
|
|
|
|
|
Map<Integer, List<AlarmStrategyVO>> levMap = alarmStrategyVOS.stream().collect(Collectors.groupingBy(AlarmStrategyVO::getAlgoDesc));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 整合装置信息
|
|
|
|
|
List<TopMsgPO> topMsgPOS = new ArrayList<>();
|
|
|
|
|
for (Map.Entry<String, List<AlarmPO>> alarmEntry : devMap.entrySet()) {
|
|
|
|
|
if (!lineIntegrityMap.containsKey(alarmEntry.getKey()) && !lineAlarmsMap.containsKey(alarmEntry.getKey())
|
|
|
|
|
&& !deviceFlowAndOnlineRateMap.containsKey(alarmEntry.getKey()) && !comMap.containsKey(alarmEntry.getKey())) {
|
|
|
|
|
for (Map.Entry<String, List<AlarmPO>> devEntry : devMap.entrySet()) {
|
|
|
|
|
if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey())
|
|
|
|
|
&& !deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
TopMsgPO topMsg = new TopMsgPO();
|
|
|
|
|
topMsg.setDevId(alarmEntry.getKey());
|
|
|
|
|
int deviceLevel = alarmEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1);
|
|
|
|
|
topMsg.setDevId(devEntry.getKey());
|
|
|
|
|
topMsg.setIntegrityFlag(1);
|
|
|
|
|
topMsg.setOfftimeFlag(1);
|
|
|
|
|
topMsg.setFlowFlag(1);
|
|
|
|
|
topMsg.setOnlineRateFlag(1);
|
|
|
|
|
topMsg.setAlarmCountFlag(1);
|
|
|
|
|
int deviceLevel = devEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1);
|
|
|
|
|
// 装置等级
|
|
|
|
|
topMsg.setDeviceLevel(deviceLevel);
|
|
|
|
|
// 等级对应的告警策略
|
|
|
|
|
AlarmStrategyVO alarmStrategyVO = levMap.get(deviceLevel).get(0);
|
|
|
|
|
// 数据完整性
|
|
|
|
|
if (lineIntegrityMap.containsKey(alarmEntry.getKey())) {
|
|
|
|
|
Integer due = lineIntegrityMap.get(alarmEntry.getKey()).get(0).getDue();
|
|
|
|
|
Integer real = lineIntegrityMap.get(alarmEntry.getKey()).get(0).getReal();
|
|
|
|
|
if (lineIntegrityMap.containsKey(devEntry.getKey())) {
|
|
|
|
|
Integer due = lineIntegrityMap.get(devEntry.getKey()).get(0).getDue();
|
|
|
|
|
Integer real = lineIntegrityMap.get(devEntry.getKey()).get(0).getReal();
|
|
|
|
|
float integrity = BigDecimal.valueOf((float) real *100 / due).setScale(2, RoundingMode.HALF_UP).floatValue();
|
|
|
|
|
topMsg.setIntegrityFlag(integrity < alarmStrategyVO.getIntegrityValue() ? 0 : 1);
|
|
|
|
|
topMsg.setIntegrityValue(integrity);
|
|
|
|
|
} else {
|
|
|
|
|
topMsg.setIntegrityFlag(-1);
|
|
|
|
|
}
|
|
|
|
|
// 装置告警
|
|
|
|
|
if (lineAlarmsMap.containsKey(alarmEntry.getKey())) {
|
|
|
|
|
List<AlarmPO> lineAlarmPOS = lineAlarmsMap.get(alarmEntry.getKey());
|
|
|
|
|
if (lineAlarmsMap.containsKey(devEntry.getKey())) {
|
|
|
|
|
List<AlarmPO> lineAlarmPOS = lineAlarmsMap.get(devEntry.getKey());
|
|
|
|
|
int alarmCount = lineAlarmPOS.stream().mapToInt(AlarmPO::getAlarmCount).sum();
|
|
|
|
|
String alarmDesc = String.join(",", lineAlarmPOS.stream().map(AlarmPO::getAlarmDesc).collect(Collectors.toList()));
|
|
|
|
|
topMsg.setAlarmCountFlag(alarmCount > alarmStrategyVO.getWarnValue() ? 0 : 1);
|
|
|
|
|
@@ -112,8 +120,8 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
topMsg.setAlarmCount(0);
|
|
|
|
|
}
|
|
|
|
|
// 流量和在线率
|
|
|
|
|
if (deviceFlowAndOnlineRateMap.containsKey(alarmEntry.getKey())) {
|
|
|
|
|
AlarmPO alarmPO = deviceFlowAndOnlineRateMap.get(alarmEntry.getKey()).get(0);
|
|
|
|
|
if (deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey())) {
|
|
|
|
|
AlarmPO alarmPO = deviceFlowAndOnlineRateMap.get(devEntry.getKey()).get(0);
|
|
|
|
|
topMsg.setFlowFlag(alarmPO.getActualValue() > alarmPO.getFlowMeal() ? 0 : 1);
|
|
|
|
|
topMsg.setOnlineRateFlag(alarmPO.getOnlineRate() *100 < alarmStrategyVO.getOnlineValue() ? 0 : 1);
|
|
|
|
|
topMsg.setFlowValue(alarmPO.getFlowProportion());
|
|
|
|
|
@@ -123,29 +131,34 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
topMsg.setOnlineRateFlag(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comMap.containsKey(alarmEntry.getKey())) {
|
|
|
|
|
TopMsgPO comOutPO = comMap.get(alarmEntry.getKey()).get(0);
|
|
|
|
|
topMsg.setOfftimeFlag(comOutPO.getOfftimeValue() > alarmStrategyVO.getOffTimeValue() ? 0 :1);
|
|
|
|
|
topMsg.setComOutCount(comOutPO.getComOutCount());
|
|
|
|
|
topMsg.setComOutDescription(String.join(",",comOutPO.getComOutDesc()));
|
|
|
|
|
if (comMap.containsKey(devEntry.getKey())) {
|
|
|
|
|
TopMsgPO comOutPO = comMap.get(devEntry.getKey()).get(0);
|
|
|
|
|
List<Communicate> abnormals = comOutPO.getCommunicates().stream().filter(t -> t.getDuration() > alarmStrategyVO.getOffTimeValue()).collect(Collectors.toList());
|
|
|
|
|
topMsg.setOfftimeFlag(abnormals.size() > 0 ? 0 :1);
|
|
|
|
|
topMsg.setComOutCount(abnormals.size());
|
|
|
|
|
List<String> abnormalDesc = abnormals.stream().map(Communicate::getDesc).collect(Collectors.toList());
|
|
|
|
|
topMsg.setComOutDescription(String.join(",",abnormalDesc));
|
|
|
|
|
} else {
|
|
|
|
|
topMsg.setOfftimeFlag(0);
|
|
|
|
|
String updateTime = localDateTimeFormat(alarmEntry.getValue().get(0).getUpdateTime());
|
|
|
|
|
long time = DateUtil.endOfDay(DateUtil.parse(param.getTime())).getTime() -
|
|
|
|
|
alarmEntry.getValue().get(0).getUpdateTime().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
|
|
|
|
|
topMsg.setOfftimeValue((int)(time/1000/60));
|
|
|
|
|
topMsg.setComOutCount(1);
|
|
|
|
|
topMsg.setComOutDescription(updateTime+"至"+DateUtil.endOfDay(DateUtil.parse(param.getTime())));
|
|
|
|
|
try {
|
|
|
|
|
if (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(devEntry.getValue().get(0).getUpdateTime()).after(DateUtil.endOfDay(DateUtil.parse(param.getTime())))) {
|
|
|
|
|
topMsg.setOfftimeFlag(0);
|
|
|
|
|
topMsg.setComOutCount(1);
|
|
|
|
|
topMsg.setComOutDescription(DateUtil.beginOfDay(DateUtil.parse(param.getTime()))+"至"+devEntry.getValue().get(0).getUpdateTime());
|
|
|
|
|
} else if (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(devEntry.getValue().get(0).getUpdateTime()).before(DateUtil.beginOfDay(DateUtil.parse(param.getTime())))) {
|
|
|
|
|
topMsg.setOfftimeFlag(1);
|
|
|
|
|
topMsg.setComOutCount(0);
|
|
|
|
|
}
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
log.error("ParseException "+e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (topMsg.getFlowFlag() != 1 || topMsg.getIntegrityFlag() != 1 || topMsg.getOfftimeFlag() != 0
|
|
|
|
|
|| topMsg.getAlarmCountFlag() != 1 || topMsg.getOnlineRateFlag() != 1) {
|
|
|
|
|
if (topMsg.getFlowFlag() !=1 || topMsg.getIntegrityFlag() !=1 || topMsg.getOfftimeFlag() != 1
|
|
|
|
|
|| topMsg.getAlarmCountFlag() !=1 || topMsg.getOnlineRateFlag() !=1) {
|
|
|
|
|
topMsgPOS.add(topMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String localDateTimeFormat(LocalDateTime localDateTime) {
|
|
|
|
|
@@ -156,12 +169,10 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(instant.toEpochMilli());
|
|
|
|
|
return format;
|
|
|
|
|
}
|
|
|
|
|
public List<TopMsgPO> getCommunicate(List<String> devs, String startTime, String endTime) {
|
|
|
|
|
// startTime ="2023-04-02";
|
|
|
|
|
// endTime = "2023-04-02";
|
|
|
|
|
//组装sql语句
|
|
|
|
|
public List<TopMsgPO> getCommunicate(List<String> devs, String time) {
|
|
|
|
|
// 组装sql语句
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
|
|
|
|
|
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(time))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(time))).append("' and ");
|
|
|
|
|
for (int i = 0; i < devs.size(); i++) {
|
|
|
|
|
if (devs.size() - i != 1) {
|
|
|
|
|
stringBuilder.append("dev_id ='").append(devs.get(i)).append("' or ");
|
|
|
|
|
@@ -170,7 +181,7 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String sql = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where " + stringBuilder.toString() + InfluxDBPublicParam.TIME_ZONE;
|
|
|
|
|
//获取暂降事件
|
|
|
|
|
// 获取暂降事件
|
|
|
|
|
QueryResult result = influxDbUtils.query(sql);
|
|
|
|
|
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
|
|
|
|
|
List<Communicate> communicates = influxDBResultMapper.toPOJO(result, Communicate.class);
|
|
|
|
|
@@ -180,34 +191,39 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
|
|
|
|
}
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
Map<String, List<Communicate>> comMap = communicates.stream().collect(Collectors.groupingBy(Communicate::getDevId));
|
|
|
|
|
for (Map.Entry<String, List<Communicate>> comEntry : comMap.entrySet()) {
|
|
|
|
|
TopMsgPO topMsgPO = new TopMsgPO(); List<String> comOutDesc = new ArrayList<>();
|
|
|
|
|
topMsgPO.setDevId(comEntry.getKey());
|
|
|
|
|
for (Map.Entry<String, List<Communicate>> entry : comMap.entrySet()) {
|
|
|
|
|
String key = entry.getKey();
|
|
|
|
|
List<Communicate> value = entry.getValue();
|
|
|
|
|
TopMsgPO topMsgPO = new TopMsgPO();
|
|
|
|
|
List<Communicate> comOuts = new ArrayList<>();
|
|
|
|
|
topMsgPO.setDevId(key);
|
|
|
|
|
// 根据日期排序
|
|
|
|
|
List<Communicate> sortedList = comEntry.getValue().stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList());
|
|
|
|
|
Long mills = 0l;
|
|
|
|
|
List<Communicate> sortedList = value.stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList());
|
|
|
|
|
if (sortedList.get(0).getType() == 1) {
|
|
|
|
|
long time = Date.from(sortedList.get(0).getUpdateTime()).getTime() - DateUtil.beginOfDay(DateUtil.parse(startTime)).getTime();
|
|
|
|
|
mills += time;
|
|
|
|
|
comOutDesc.add((DateUtil.beginOfDay(DateUtil.parse(startTime)))+"至"+formatter.format(Date.from(sortedList.get(0).getUpdateTime())));
|
|
|
|
|
Communicate communicate = new Communicate();
|
|
|
|
|
int durationTime = (int) (Date.from(sortedList.get(0).getUpdateTime()).getTime() - DateUtil.beginOfDay(DateUtil.parse(time)).getTime())/1000/60;
|
|
|
|
|
communicate.setDuration(durationTime);
|
|
|
|
|
communicate.setDesc((DateUtil.beginOfDay(DateUtil.parse(time))) + "至" + formatter.format(Date.from(sortedList.get(0).getUpdateTime())));
|
|
|
|
|
comOuts.add(communicate);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i <sortedList.size() ; i++) {
|
|
|
|
|
if (sortedList.get(i).getType()==0 && i<sortedList.size()-1) {
|
|
|
|
|
long time = Date.from(sortedList.get(i+1).getUpdateTime()).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime();
|
|
|
|
|
mills += time;
|
|
|
|
|
String comOutTime =formatter.format(Date.from(sortedList.get(i).getUpdateTime()))+"至"+ formatter.format(Date.from(sortedList.get(i+1).getUpdateTime()));
|
|
|
|
|
comOutDesc.add(comOutTime);
|
|
|
|
|
} else if (sortedList.get(i).getType()==0 && i==sortedList.size()-1) {
|
|
|
|
|
long time = DateUtil.endOfDay(DateUtil.parse(endTime)).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime();
|
|
|
|
|
mills += time;
|
|
|
|
|
String comOutTime = formatter.format(Date.from(sortedList.get(i).getUpdateTime())) +"至"+ DateUtil.endOfDay(DateUtil.parse(endTime));
|
|
|
|
|
comOutDesc.add(comOutTime);
|
|
|
|
|
for (int i = 0; i < sortedList.size(); i++) {
|
|
|
|
|
if (sortedList.get(i).getType() == 0 && i < sortedList.size() - 1) {
|
|
|
|
|
Communicate communicate = new Communicate();
|
|
|
|
|
int durationTime = (int) (Date.from(sortedList.get(i + 1).getUpdateTime()).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime())/1000/60;
|
|
|
|
|
communicate.setDuration(durationTime);
|
|
|
|
|
String comOut = formatter.format(Date.from(sortedList.get(i).getUpdateTime())) + "至" + formatter.format(Date.from(sortedList.get(i + 1).getUpdateTime()));
|
|
|
|
|
communicate.setDesc(comOut);
|
|
|
|
|
comOuts.add(communicate);
|
|
|
|
|
} else if (sortedList.get(i).getType() == 0 && i == sortedList.size() - 1) {
|
|
|
|
|
Communicate communicate = new Communicate();
|
|
|
|
|
int durationTime = (int) (DateUtil.endOfDay(DateUtil.parse(time)).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime()) / 1000 / 60;
|
|
|
|
|
communicate.setDuration(durationTime);
|
|
|
|
|
String comOut = formatter.format(Date.from(sortedList.get(i).getUpdateTime())) + "至" + DateUtil.endOfDay(DateUtil.parse(time));
|
|
|
|
|
communicate.setDesc(comOut);
|
|
|
|
|
comOuts.add(communicate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
topMsgPO.setOfftimeValue( (int)(mills / 1000 / 60));
|
|
|
|
|
topMsgPO.setComOutDesc(comOutDesc);
|
|
|
|
|
// 通信中断次数
|
|
|
|
|
topMsgPO.setComOutCount(comOutDesc.size());
|
|
|
|
|
topMsgPO.setCommunicates(comOuts);
|
|
|
|
|
comMsgs.add(topMsgPO);
|
|
|
|
|
}
|
|
|
|
|
return comMsgs;
|
|
|
|
|
|