diff --git a/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/DeviceAbnormalStatisticsJob.java b/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/DeviceAbnormalStatisticsJob.java index cb26a2036..50dc7b3ab 100644 --- a/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/DeviceAbnormalStatisticsJob.java +++ b/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/DeviceAbnormalStatisticsJob.java @@ -21,7 +21,7 @@ public class DeviceAbnormalStatisticsJob { @XxlJob("deviceAbnormalStatisticsJob") public void deviceAbnormalStatisticsJob () { - String time = LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + String time = LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); log.info("执行日期deviceAbnormalStatisticsJob===============>"+time); DeviceAbnormaStatisticsParam param =new DeviceAbnormaStatisticsParam(); param.setTime(time); 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 d14b8b172..55fab72d5 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 @@ -136,18 +136,8 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist List abnormalDesc = abnormals.stream().map(Communicate::getDesc).collect(Collectors.toList()); topMsg.setComOutDescription(String.join(",",abnormalDesc)); } else { - 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 { - topMsg.setOfftimeFlag(1); - topMsg.setComOutCount(0); - } - } catch (ParseException e) { - log.error("ParseException "+e); - } + topMsg.setOfftimeFlag(1); + topMsg.setComOutCount(0); } if (topMsg.getFlowFlag() ==0 || topMsg.getIntegrityFlag() ==0 || topMsg.getOfftimeFlag() == 0 || topMsg.getAlarmCountFlag() ==0 || topMsg.getOnlineRateFlag() ==0) { @@ -155,6 +145,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist } } + for (TopMsgPO topMsgPO : topMsgPOS) { + System.out.println(topMsgPO); + } return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS); } @@ -174,46 +167,76 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist QueryResult result = influxDbUtils.query(sql); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); List communicates = influxDBResultMapper.toPOJO(result, Communicate.class); + // 通讯状态统计结果集 List comMsgs = new ArrayList<>(); - if (CollectionUtil.isEmpty(communicates)) { - return comMsgs; - } SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Map> comMap = communicates.stream().collect(Collectors.groupingBy(Communicate::getDevId)); - for (Map.Entry> entry : comMap.entrySet()) { - String key = entry.getKey(); - List value = entry.getValue(); - TopMsgPO topMsgPO = new TopMsgPO(); - List comOuts = new ArrayList<>(); - topMsgPO.setDevId(key); - // 根据日期排序 - List sortedList = value.stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList()); - if (sortedList.get(0).getType() == 1) { - 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) { + if (CollectionUtil.isNotEmpty(communicates)) { + for (Map.Entry> entry : comMap.entrySet()) { + String key = entry.getKey(); + List value = entry.getValue(); + TopMsgPO topMsgPO = new TopMsgPO(); + List comOuts = new ArrayList<>(); + topMsgPO.setDevId(key); + // 根据日期排序 + List sortedList = value.stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList()); + if (sortedList.get(0).getType() == 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; + int durationTime = (int) (Date.from(sortedList.get(0).getUpdateTime()).getTime() - DateUtil.beginOfDay(DateUtil.parse(time)).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); + 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) { + 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.setCommunicates(comOuts); + comMsgs.add(topMsgPO); + } + } + + List coms = new ArrayList<>(comMap.keySet()); + // 计算influxdb中当天无记录装置id + List extraComs = devs.stream().filter(t -> !coms.contains(t)).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(extraComs)) { + for (String devId : extraComs) { + TopMsgPO topMsgPO = new TopMsgPO(); + List comOuts = new ArrayList<>(); + topMsgPO.setDevId(devId); + // 组装sql语句 + StringBuilder builder = new StringBuilder(); + builder.append("dev_id ='").append(devId).append("'"); + builder.append(" AND time <= '").append(DateUtil.beginOfDay(DateUtil.parse(time))).append("'").append(" order by time DESC ").append("limit 1 "); + String sql1 = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where "+builder.toString() + InfluxDBPublicParam.TIME_ZONE; + // 获取暂降事件 + QueryResult result1 = influxDbUtils.query(sql1); + InfluxDBResultMapper influxDBResultMapper1 = new InfluxDBResultMapper(); + List earlyData = influxDBResultMapper1.toPOJO(result1, Communicate.class); + Communicate early = earlyData.get(0); + Communicate communicate = new Communicate(); + if (early.getType() == 0) { + int durationTime = (int) (DateUtil.endOfDay(DateUtil.parse(time)).getTime() - Date.from(early.getUpdateTime()).getTime()) / 1000 / 60; + communicate.setDuration(durationTime); + communicate.setDesc(formatter.format(Date.from(early.getUpdateTime())) + "至" + DateUtil.endOfDay(DateUtil.parse(time))); + comOuts.add(communicate); + } + topMsgPO.setCommunicates(comOuts); + comMsgs.add(topMsgPO); } - topMsgPO.setCommunicates(comOuts); - comMsgs.add(topMsgPO); } return comMsgs; }