Browse Source

更新

feature_hph_新增rabbitmq_sink
1049970895@qniao.cn 3 years ago
parent
commit
fdf27b1c59
1 changed files with 22 additions and 32 deletions
  1. 54
      src/main/java/com/qniao/iot/IotMonitoringDataJob.java

54
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;

Loading…
Cancel
Save