diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/TopMsgMapper.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/TopMsgMapper.java index 72894ae91..b64d07155 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/TopMsgMapper.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/TopMsgMapper.java @@ -10,9 +10,9 @@ import org.apache.ibatis.annotations.Param; import java.util.List; public interface TopMsgMapper { - Page getTopMsg(Page page,@Param("lineGrade") String lineGrade, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); - List getTopMsgDetail(@Param("lineGrade") String lineGrade,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); + + List getTopMsgDetail(@Param("lineGrade") String lineGrade,@Param("startTime") DateTime startTime); diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/LineMapper.xml b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/LineMapper.xml index 55653e41d..504cbf416 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/LineMapper.xml +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/LineMapper.xml @@ -864,7 +864,9 @@ #{item} and - a.Create_Time between #{startTime} and #{endTime} + a.Create_Time between #{startTime} and #{endTime} + and + b.Run_Flag != 2 ) t ORDER BY flowProportion DESC diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TopMagMapper.xml b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TopMagMapper.xml index f25d347ba..922ec093b 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TopMagMapper.xml +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TopMagMapper.xml @@ -5,12 +5,12 @@ SELECT t.*, (t.statisValue)/t.flowMeal flowProportion - FROM - ( - SELECT device.Id AS Id, - device.id AS deviceId, - COUNT(ca.Id) AS alarmCount, - GROUP_CONCAT(ca.Remark) AS alarmDesc, - IFNULL(d.flow, (select flow from cld_flow_meal where type = 0 and flag = 1)) + ifnull(d1.flow, 0) flowMeal, - IFNULL(pmf.Actual_Value,0) statisValue - FROM pq_line line - INNER JOIN pq_line vol ON line.pid=vol.id - INNER JOIN pq_line device ON vol.pid=device.id - LEFT JOIN pq_device pd ON device.id=pd.id - LEFT JOIN pq_line_detail pld ON pld.id=line.id - LEFT JOIN cld_alarm ca ON ca.Line_Id=device.id - LEFT JOIN pqs_month_flow pmf ON pmf.Dev_Id=device.id - LEFT JOIN cld_dev_meal c ON device.id = c.line_id - LEFT JOIN cld_flow_meal d ON c.Base_Meal_Id = d.id - LEFT JOIN cld_flow_meal d1 ON c.Ream_Meal_Id = d1.id - WHERE - pd.Dev_Model = 1 - AND - pd.Run_Flag = 0 - AND - pld.Line_Grade is NOT NULL - AND - ca.Occurred_Time between #{startTime} and #{endTime} - GROUP BY deviceId - ) t + FROM + ( + SELECT device.Id AS Id, + device.id AS deviceId, + COUNT(ca.Id) AS alarmCount, + GROUP_CONCAT(ca.Remark) AS alarmDesc, + IFNULL(d.flow, (select flow from cld_flow_meal where type = 0 and flag = 1)) + ifnull(d1.flow, 0) flowMeal, + IFNULL(ANY_VALUE(pmf.Actual_Value),0) statisValue, + ANY_VALUE(device.Update_Time) AS updateTime + FROM pq_line line + INNER JOIN pq_line vol ON line.pid=vol.id + INNER JOIN pq_line device ON vol.pid=device.id + LEFT JOIN pq_device pd ON device.id=pd.id + LEFT JOIN pq_line_detail pld ON pld.id=line.id + LEFT JOIN cld_alarm ca ON ca.Line_Id=device.id + LEFT JOIN pqs_month_flow pmf ON pmf.Dev_Id=device.id + LEFT JOIN cld_dev_meal c ON device.id = c.line_id + LEFT JOIN cld_flow_meal d ON c.Base_Meal_Id = d.id + LEFT JOIN cld_flow_meal d1 ON c.Ream_Meal_Id = d1.id + WHERE + pd.Dev_Model = 1 + AND + pd.Run_Flag = 0 + AND + pld.Line_Grade is NOT NULL + AND + ca.Occurred_Time between #{startTime} and #{endTime} + GROUP BY deviceId + ) t ORDER BY flowProportion DESC diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/DeviceAbnormaStatisticsServiceImpl.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/DeviceAbnormaStatisticsServiceImpl.java index 18055bc52..680bb53ac 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/DeviceAbnormaStatisticsServiceImpl.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/DeviceAbnormaStatisticsServiceImpl.java @@ -2,23 +2,20 @@ package com.njcn.prepare.harmonic.service.mysql.Impl.device; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; -import com.njcn.device.pq.pojo.po.Communicate; import com.njcn.influxdb.param.InfluxDBPublicParam; import com.njcn.influxdb.utils.InfluxDbUtils; import com.njcn.prepare.harmonic.mapper.mysql.device.DeviceAbnormaStatisticsMapper; +import com.njcn.prepare.harmonic.pojo.influxdb.po.Communicate; import com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO; import com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmStrategyVO; -import com.njcn.prepare.harmonic.pojo.mysql.po.line.LinePO; import com.njcn.prepare.harmonic.pojo.mysql.po.line.TopMsgPO; import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam; import com.njcn.prepare.harmonic.service.mysql.device.DeviceAbnormalStatisticsService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.influxdb.dto.QueryResult; import org.influxdb.impl.InfluxDBResultMapper; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; @@ -37,33 +34,31 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist private final InfluxDbUtils influxDbUtils; @Override public boolean dailyDeviceAbnormaStatistics(DeviceAbnormaStatisticsParam param) { + Map> comMap = new HashMap<>();Map> devLineMap = new HashMap<>(); // 获取监测点告警 List lineAlarms = deviceAbnormaStatisticsMapper.getAlarmByLines( DateUtil.beginOfDay(DateUtil.parse(param.getBeginTime())), DateUtil.beginOfDay(DateUtil.parse(param.getEndTime()))); - Map> lineMap = new HashMap<>(); if (CollectionUtil.isNotEmpty(lineAlarms)){ // 根据装置分组 - lineMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); + devLineMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); } - // 获取设备流量 List deviceAlarms = deviceAbnormaStatisticsMapper.getAlarmByDevice( DateUtil.beginOfDay(DateUtil.parse(param.getBeginTime())), DateUtil.beginOfDay(DateUtil.parse(param.getEndTime()))); List devs = deviceAlarms.stream().map(AlarmPO::getId).collect(Collectors.toList()); - devs.add("6469e77fda42db12c7ca6620a092f03c"); - Map> comMap = new HashMap<>(); // 获取通信中断信息 - List communicate = getCommunicate(devs, param.getBeginTime(), param.getEndTime()); - if (CollectionUtil.isNotEmpty(communicate)){ - comMap = communicate.stream().collect(Collectors.groupingBy(Communicate::getId)); + List comMsgs = getCommunicate(devs, param.getBeginTime(), param.getEndTime()); + if (CollectionUtil.isNotEmpty(comMsgs)){ + comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId)); } + // 整合监测点告警信息、数据完整性以及监测点等级为设备信息 for (AlarmPO deviceAlarm : deviceAlarms) { - if (!lineMap.containsKey(deviceAlarm.getId())) { + if (!devLineMap.containsKey(deviceAlarm.getId())) { continue; } - AlarmPO lineAlarm = lineMap.get(deviceAlarm.getId()).get(0); + AlarmPO lineAlarm = devLineMap.get(deviceAlarm.getId()).get(0); deviceAlarm.setAlarmCount(deviceAlarm.getAlarmCount() + lineAlarm.getAlarmCount()); if (lineAlarm.getDue().compareTo(BigDecimal.ZERO) == 0) { deviceAlarm.setIntegrity(BigDecimal.ZERO); @@ -73,15 +68,14 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist if (lineAlarm.getLevel() != null) { deviceAlarm.setLevel(lineAlarm.getLevel()); } - if (CollectionUtil.isNotEmpty(comMap)) { - List communicates = comMap.get(deviceAlarm.getId()); - int comOut = communicates.stream().filter(t -> t.getType() == 0).collect(Collectors.toList()).size(); - deviceAlarm.setComOutNum(comOut); - } + TopMsgPO topMsgPO = comMap.get(deviceAlarm.getId()).get(0); + deviceAlarm.setComOutNum(topMsgPO.getComOutCount()); + deviceAlarm.setComOutDesc(String.join(",",topMsgPO.getComOutDesc())); } - Map> levelMap = deviceAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getLevel)); + // 比对告警策略并落表 List alarmStrategyVOS = deviceAbnormaStatisticsMapper.selectAlarmStrategy(); List alarmExceptions = new ArrayList<>(); + Map> levelMap = deviceAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getLevel)); for (AlarmStrategyVO strategyVO : alarmStrategyVOS) { if (!levelMap.containsKey(strategyVO.getAlgoDesc())){ continue; @@ -91,7 +85,7 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist TopMsgPO topMsg = new TopMsgPO(); topMsg.setDevId(alarmPO.getId()); topMsg.setFlowFlag(1); - topMsg.setComOutCount(alarmPO.getComOutNum() == 0 ? 0 : alarmPO.getComOutNum()); + topMsg.setComOutCount(alarmPO.getComOutNum() == null ? 0 : alarmPO.getComOutNum()); if (alarmPO.getIntegrity().intValue() getCommunicate(List devs, String startTime, String endTime) { + public List getCommunicate(List devs, String startTime, String endTime) { //组装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 "); @@ -126,7 +120,55 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist //获取暂降事件 QueryResult result = influxDbUtils.query(sql); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); - List communicateList = influxDBResultMapper.toPOJO(result, Communicate.class); - return communicateList; + List communicates = influxDBResultMapper.toPOJO(result, Communicate.class); + List comMsgs = new ArrayList<>(); + if (CollectionUtil.isEmpty(communicates)) { + return comMsgs; + } + Map> comMap = communicates.stream().collect(Collectors.groupingBy(Communicate::getDevId)); + for (Map.Entry> comEntry : comMap.entrySet()) { + TopMsgPO topMsgPO = new TopMsgPO(); List comOutDesc = new ArrayList<>(); + topMsgPO.setDevId(comEntry.getKey()); + // 根据日期排序 + List sortedList = comEntry.getValue().stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList()); + if (sortedList.size() == 1) { + if (sortedList.get(0).getType() == 0) { + comOutDesc.add(sortedList.get(0).getUpdateTime()+"至"+DateUtil.endOfDay(DateUtil.parse(endTime))); + } else { + comOutDesc.add((DateUtil.beginOfDay(DateUtil.parse(startTime)))+"至"+sortedList.get(0).getUpdateTime()); + } + } else { + switch (sortedList.get(0).getType()) { + case 0: + for (int i = 0; i a.getType() == 0).collect(Collectors.toList()).size()); + comMsgs.add(topMsgPO); + } + return comMsgs; } }