diff --git a/src/main/java/com/qniao/iot/IotMonitoringDataJob.java b/src/main/java/com/qniao/iot/IotMonitoringDataJob.java index 283046e..6698d80 100644 --- a/src/main/java/com/qniao/iot/IotMonitoringDataJob.java +++ b/src/main/java/com/qniao/iot/IotMonitoringDataJob.java @@ -211,14 +211,7 @@ public class IotMonitoringDataJob { nowDeviceState.setJobTotal(onData.getJobTotal() + receivedEvent.getCurrJobCount()); } else { // 机智云 - Long jobTotal = lastedDeviceState.getJobTotal(); - Long workingJon; - if (accJobCount > jobTotal) { - workingJon = accJobCount - lastedDeviceState.getJobTotal(); - } else { - workingJon = 0L; - } - nowDeviceState.setTheDayJobCount(lastedDeviceState.getTheDayJobCount() + workingJon); + nowDeviceState.setTheDayJobCount(lastedDeviceState.getTheDayJobCount() + accJobCount); nowDeviceState.setJobTotal(lastedDeviceState.getJobTotal() + receivedEvent.getCurrJobCount()); } } @@ -240,14 +233,7 @@ public class IotMonitoringDataJob { nowDeviceState.setJobTotal(onData.getJobTotal() + receivedEvent.getCurrJobCount()); } else { // 机智云 - Long jobTotal = lastedDeviceState.getJobTotal(); - Long workingJon; - if (accJobCount > jobTotal) { - workingJon = accJobCount - lastedDeviceState.getJobTotal(); - } else { - workingJon = 0L; - } - nowDeviceState.setTheDayJobCount(lastedDeviceState.getTheDayJobCount() + workingJon); + nowDeviceState.setTheDayJobCount(lastedDeviceState.getTheDayJobCount() + accJobCount); nowDeviceState.setJobTotal(lastedDeviceState.getJobTotal() + receivedEvent.getCurrJobCount()); } nowDeviceState.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); @@ -270,7 +256,8 @@ public class IotMonitoringDataJob { } } // 如果上次是待机,并且这次也是待机,那么就不需要发送了 - if ((!(lastWorkingStat == 2 && machineWorkingStat == 2)) || !isExistEs) { + if (((!(lastWorkingStat == 2 && machineWorkingStat == 2)) + && (!(lastPwStat == 0 && machinePwrStat == 0))) || !isExistEs) { DeviceMonitoringData data = new DeviceMonitoringData(); data.setDataSource(receivedEvent.getDataSource()); data.setMachineIotMac(receivedEvent.getMachineIotMac()); @@ -311,34 +298,32 @@ public class IotMonitoringDataJob { // 上一次的数据 DeviceTotalData value = deviceTotalDataStat.value(); - // 用来存放这次的数据,作为下一个的上一次数据 - DeviceTotalData data = new DeviceTotalData(); Long reportTime = event.getReportTime(); LocalDate localDate = new Date(reportTime).toLocalDate(); if (value == null) { + value = new DeviceTotalData(); // 从es中获取 DeviceMonitoringData deviceMonitoringData = queryLatestDeviceMonitoringData(event.getMachineIotMac(), null); if (deviceMonitoringData != null) { - data.setJobDurationTotal(deviceMonitoringData.getAccJobCountDuration()); - data.setJobTotal(deviceMonitoringData.getAccJobCount()); + value.setJobDurationTotal(deviceMonitoringData.getAccJobCountDuration()); + value.setJobTotal(deviceMonitoringData.getAccJobCount()); // 单位秒 - data.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); - data.setTheDayJobDuration(deviceMonitoringData.getCurrJobDuration()); - data.setTheDayJobCount(deviceMonitoringData.getCurrJobCount()); - data.setLastBootTime(deviceMonitoringData.getLastBootTime()); - data.setTheDayDuration(deviceMonitoringData.getCurrDuration()); - data.setReportTime(deviceMonitoringData.getReportTime()); + value.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + value.setTheDayJobDuration(deviceMonitoringData.getCurrJobDuration()); + value.setTheDayJobCount(deviceMonitoringData.getCurrJobCount()); + value.setLastBootTime(deviceMonitoringData.getLastBootTime()); + value.setTheDayDuration(deviceMonitoringData.getCurrDuration()); + value.setReportTime(deviceMonitoringData.getReportTime()); } else { // es中也没有,直接从老接口拿 isExistEs = false; - data = queryDeviceMonitoringData(event.getMachineIotMac(), reportTime); + value = queryDeviceMonitoringData(event.getMachineIotMac(), reportTime); } - value = data; } // 是否日期是当天的,否则需要更新当天工作时长和当天工作量 if (LocalDate.parse(value.getCurrLocalDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).isBefore(localDate)) { // 先从es中拿昨天最新的 - DeviceMonitoringData deviceMonitoringData = queryLatestDeviceMonitoringData(event.getMachineIotMac(), + /*DeviceMonitoringData deviceMonitoringData = queryLatestDeviceMonitoringData(event.getMachineIotMac(), LocalDateTime.of(localDate, LocalTime.MIN).atZone(ZoneOffset.of("+8")).toEpochSecond()); if (deviceMonitoringData != null) { data.setJobTotal(deviceMonitoringData.getAccJobCount()); @@ -359,8 +344,13 @@ public class IotMonitoringDataJob { data.setLastBootTime(value.getLastBootTime()); data.setTheDayDuration(0L); data.setReportTime(reportTime); - } - value = data; + }*/ + // value有值,但是日期不对,说明到了第二天,那么,只需要对当天数据清零即可 + value.setTheDayJobDuration(0L); + value.setTheDayJobCount(0L); + value.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + value.setTheDayDuration(0L); + value.setReportTime(reportTime); } deviceTotalDataStat.update(value); return value;