diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/DeviceAbnormaStatisticsMapper.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/DeviceAbnormaStatisticsMapper.java index 6e0e3ebc2..17cb07874 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/DeviceAbnormaStatisticsMapper.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/DeviceAbnormaStatisticsMapper.java @@ -18,15 +18,23 @@ public interface DeviceAbnormaStatisticsMapper { */ List getLines(); - List getFlowAndOnlineRateByDevice(@Param("list") List list,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); + List getFlowByDevice(@Param("list") List list, @Param("time") String startTime); - List getIntegrityByLines(@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); - - List getIntegrityByLineIds(@Param("list") List list,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); + List getIntegrityByLineIds(@Param("list") List list, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); + /** + * 告警信息 + * @param monitorIds + * @param devIds + * @param startTime + * @param endTime + * @return + */ List getAlarmByLines(@Param("monitorIds") List monitorIds,@Param("devIds") List devIds,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime); Boolean insertTopMsg(@Param("list") List topMsgPOS); List selectAlarmStrategy(); + + List getOnlineRateByDevice(@Param("list") List devIds, @Param("startTime") DateTime beginOfDay, @Param("endTime") DateTime endOfDay); } diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/mapping/DeviceAbnormaStatisticsMapper.xml b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/mapping/DeviceAbnormaStatisticsMapper.xml index 417d00994..e5456b06f 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/mapping/DeviceAbnormaStatisticsMapper.xml +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/device/mapping/DeviceAbnormaStatisticsMapper.xml @@ -55,33 +55,12 @@ pld.Line_Grade is NOT NULL - - - SELECT t.*, (t.actualValue)/(t.flowMeal) flowProportion FROM ( SELECT - device.id deviceId, + cmf.Dev_Id deviceId, + DATE_FORMAT(cmf.Time_Id,'%Y-%m') updateTime, IFNULL(d.flow, (select flow from cld_flow_meal where type = 0 and flag = 1)) + IFNULL(d1.flow, 0) flowMeal, - IFNULL(cmf.Actual_Value/1024/1024,0) actualValue, - rsod.online_min/(rsod.online_min+rsod.offline_min) onlineRate - FROM pq_line device - LEFT JOIN cld_month_flow cmf ON cmf.Dev_Id = device.id + IFNULL(cmf.Actual_Value/1024/1024,0) actualValue + FROM cld_month_flow cmf LEFT JOIN cld_dev_meal c ON cmf.Dev_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 - LEFT JOIN r_stat_onlinerate_d rsod ON rsod.dev_index = device.id - WHERE device.id IN + WHERE cmf.Dev_Id IN #{item} AND - cmf.Time_Id BETWEEN #{startTime} AND #{endTime} + DATE_FORMAT(cmf.Time_Id,'%Y-%m') =#{time} ) t ORDER BY flowProportion DESC @@ -171,4 +148,17 @@ WHERE A.State = 1 + + \ No newline at end of file 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 e8372be1c..97074cf60 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 @@ -1,6 +1,7 @@ package com.njcn.prepare.harmonic.service.mysql.Impl.device; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.njcn.influxdb.param.InfluxDBPublicParam; import com.njcn.influxdb.utils.InfluxDbUtils; @@ -38,9 +39,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist private final InfluxDbUtils influxDbUtils; @Override - public boolean dailyDeviceAbnormaStatistics(DeviceAbnormaStatisticsParam param) { + public boolean dailyDeviceAbnormaStatistics (DeviceAbnormaStatisticsParam param) { Map> comMap = new HashMap<>(); - Map> deviceFlowAndOnlineRateMap = new HashMap<>(); + Map> deviceFlowMap = new HashMap<>(); // 获取所有装置以及下属监测点 List lines = deviceAbnormaStatisticsMapper.getLines(); // 根据装置id分组 @@ -58,36 +59,37 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist DateUtil.beginOfDay(DateUtil.parse(param.getTime())), DateUtil.endOfDay(DateUtil.parse(param.getTime()))); Map> lineIntegrityMap = lineIntegritys.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); + // 告警信息统计 List lineAlarms = deviceAbnormaStatisticsMapper.getAlarmByLines( monotorIds, devIds, DateUtil.beginOfDay(DateUtil.parse(param.getTime())), DateUtil.endOfDay(DateUtil.parse(param.getTime()))); Map> lineAlarmsMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); - // 获取设备流量 - List deviceFlowAndOnlineRate = deviceAbnormaStatisticsMapper.getFlowAndOnlineRateByDevice( + // 获取终端在线率 + List deviceOnlineRate = deviceAbnormaStatisticsMapper.getOnlineRateByDevice( devIds, DateUtil.beginOfDay(DateUtil.parse(param.getTime())), DateUtil.endOfDay(DateUtil.parse(param.getTime()))); - if (CollectionUtil.isNotEmpty(deviceFlowAndOnlineRate)) { - deviceFlowAndOnlineRateMap = deviceFlowAndOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); + Map> deviceOnlineMap = deviceOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); + // 获取设备流量 + List deviceFlow = deviceAbnormaStatisticsMapper.getFlowByDevice(devIds,param.getTime().substring(0,6)); + if (CollectionUtil.isNotEmpty(deviceFlow)) { + deviceFlowMap = deviceFlow.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); } - // 获取通信中断信息 // List list = Arrays.asList("025fa0e4c91f72ad7f1c1bd29026f20a"); List comMsgs = getCommunicate(devIds, param.getTime()); if (CollectionUtil.isNotEmpty(comMsgs)) { comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId)); } - - // 整合装置信息 List topMsgPOS = new ArrayList<>(); for (Map.Entry> devEntry : devMap.entrySet()) { - if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey()) - && !deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey())) { - continue; - } +// if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey()) +// && !deviceFlowMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey()) && !deviceOnlineMap.containsKey(devEntry.getKey())) { +// continue; +// } TopMsgPO topMsg = new TopMsgPO(); topMsg.setDevId(devEntry.getKey()); topMsg.setIntegrityFlag(1); @@ -95,12 +97,6 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist topMsg.setFlowFlag(1); topMsg.setOnlineRateFlag(1); topMsg.setAlarmCountFlag(1); - try { - topMsg.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(param.getTime())); - } catch (ParseException e) { - log.error("ParseException: "+e); - e.printStackTrace(); - } int deviceLevel = devEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1); // 装置等级 topMsg.setDeviceLevel(deviceLevel); @@ -108,11 +104,10 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist AlarmStrategyVO alarmStrategyVO = levMap.get(deviceLevel).get(0); // 数据完整性 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); + topMsg.setIntegrityFlag(lineIntegrityMap.get(devEntry.getKey()).get(0).getIntegrity() < alarmStrategyVO.getIntegrityValue() ? 0 : 1); + topMsg.setIntegrityValue(lineIntegrityMap.get(devEntry.getKey()).get(0).getIntegrity()); + } else { + topMsg.setIntegrityFlag(-1); } // 装置告警 if (lineAlarmsMap.containsKey(devEntry.getKey())) { @@ -125,17 +120,22 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist } else { topMsg.setAlarmCount(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()); + // 在线率 + if (deviceOnlineMap.containsKey(devEntry.getKey())) { + AlarmPO alarmPO = deviceOnlineMap.get(devEntry.getKey()).get(0); + topMsg.setOnlineRateFlag(alarmPO.getOnlineRate() * 100 < alarmStrategyVO.getOnlineValue() ? 0 : 1); topMsg.setOnlineRateValue(alarmPO.getOnlineRate() *100); } else { - topMsg.setFlowFlag(-1); topMsg.setOnlineRateFlag(-1); } + // 流量 + if (deviceFlowMap.containsKey(devEntry.getKey()) && Objects.nonNull(deviceFlowMap.get(devEntry.getKey()).get(0).getFlowProportion())) { + AlarmPO alarmPO = deviceFlowMap.get(devEntry.getKey()).get(0); + topMsg.setFlowFlag(alarmPO.getActualValue() > alarmPO.getFlowMeal() ? 0 : 1); + topMsg.setFlowValue(alarmPO.getFlowProportion()); + } else { + topMsg.setFlowFlag(-1); + } if (comMap.containsKey(devEntry.getKey())) { TopMsgPO comOutPO = comMap.get(devEntry.getKey()).get(0); @@ -167,14 +167,6 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS); } - public String localDateTimeFormat(LocalDateTime localDateTime) { - // 通过LocalDateTime.atZone方法,使用系统默认时区ZonId.systemDefault()获取Instant实例 - ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); - Instant instant = zonedDateTime.toInstant(); - // 日期格式化 - String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(instant.toEpochMilli()); - return format; - } public List getCommunicate(List devs, String time) { // 组装sql语句 StringBuilder stringBuilder = new StringBuilder();