Browse Source

更新

feature_hph_新增rabbitmq_sink
hupenghui@qniao.cn 3 years ago
parent
commit
a7e8cbd0e0
2 changed files with 30 additions and 26 deletions
  1. 54
      src/main/java/com/qniao/iot/IotMonitoringDataJob.java
  2. 2
      src/main/resources/META-INF/app.properties

54
src/main/java/com/qniao/iot/IotMonitoringDataJob.java

@ -113,8 +113,22 @@ public class IotMonitoringDataJob {
// 数据过滤
SingleOutputStreamOperator<MachineIotDataReceivedEvent> streamOperator = dataStreamSource
.filter((FilterFunction<MachineIotDataReceivedEvent>) value -> value.getReportTime() != null
&& value.getDataSource() != null && value.getMachinePwrStat() != null);
.filter((FilterFunction<MachineIotDataReceivedEvent>) value -> {
Long reportTime = value.getReportTime();
if(reportTime != null
&& value.getDataSource() != null && value.getMachinePwrStat() != null) {
String reportTimeStr = StrUtil.toString(reportTime);
if(reportTimeStr.length() == 10) {
// 机智云那边的设备可能是秒或毫秒
reportTime = reportTime * 1000;
}
long nowTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
// 晚30分钟的数据就不要了
return nowTime - reportTime <= (30*60*1000);
}
return false;
});
// mac分组并进行工作时长的集合操作
DataStream<DeviceMonitoringData> machineIotDataReceivedEventDataStream = streamOperator
@ -223,16 +237,17 @@ public class IotMonitoringDataJob {
nowDeviceState.setJobTotal(lastedDeviceState.getJobTotal() + receivedEvent.getCurrJobCount());
}
}
nowDeviceState.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
nowDeviceState.setLastBootTime(onData.getReportTime());
nowDeviceState.setReportTime(reportTime);
} else {
nowDeviceState = lastedDeviceState;
}
} else {
nowDeviceState = lastedDeviceState;
}
deviceTotalDataStat.update(nowDeviceState);
nowDeviceState.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
nowDeviceState.setLastBootTime(onData.getReportTime());
nowDeviceState.setReportTime(reportTime);
nowDeviceState.setMachinePwrStat(machinePwrStat);
nowDeviceState.setMachineWorkingStat(machineWorkingStat);
} else {
if (machineWorkingStat.equals(1)) {
// 工作
@ -249,9 +264,6 @@ public class IotMonitoringDataJob {
nowDeviceState.setTheDayJobDuration(lastedDeviceState.getTheDayJobDuration() + receivedEvent.getCurrJobDuration());
nowDeviceState.setJobDurationTotal(lastedDeviceState.getJobDurationTotal() + receivedEvent.getCurrJobDuration());
}
nowDeviceState.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
nowDeviceState.setLastBootTime(onData.getReportTime());
nowDeviceState.setReportTime(reportTime);
} else {
// 待机或开机
nowDeviceState = lastedDeviceState;
@ -262,16 +274,19 @@ public class IotMonitoringDataJob {
}else {
nowDeviceState.setTheDayDuration(lastedDeviceState.getTheDayDuration() + receivedEvent.getCurrJobDuration());
}
nowDeviceState.setCurrLocalDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
nowDeviceState.setLastBootTime(onData.getReportTime());
nowDeviceState.setReportTime(reportTime);
nowDeviceState.setMachinePwrStat(machinePwrStat);
nowDeviceState.setMachineWorkingStat(machineWorkingStat);
if (lastPwStat == 0) {
// 如果上次是关机消息那么这次就是开机消息
// 记录本次开机作为上次开机时间
nowDeviceState.setReportTime(reportTime);
// 记录一个周期的开机时间
onDataState.update(nowDeviceState);
onData = nowDeviceState;
}
deviceTotalDataStat.update(nowDeviceState);
}
deviceTotalDataStat.update(nowDeviceState);
// 如果上次是待机并且这次也是待机那么就不需要发送了
if (((!(lastWorkingStat == 2 && machineWorkingStat == 2))
&& (!(lastPwStat == 0 && machinePwrStat == 0))) || !isExistEs) {
@ -300,17 +315,6 @@ public class IotMonitoringDataJob {
}
}
private DeviceState getDeviceStateListJson(Long machineIotMac) throws SQLException {
// 查询数据库最新的设备状态
List<DeviceState> list = Db.use().query(SQL, DeviceState.class, machineIotMac);
if (CollUtil.isNotEmpty(list)) {
return list.get(0);
}
return null;
}
private DeviceTotalData getLastDeviceTotalData(MachineIotDataReceivedEvent event) throws Exception {
// 上一次的数据
@ -332,12 +336,13 @@ public class IotMonitoringDataJob {
value.setMachinePwrStat(deviceMonitoringData.getMachinePwrStat());
value.setMachineWorkingStat(deviceMonitoringData.getMachineWorkingStat());
value.setTheDayDuration(deviceMonitoringData.getCurrDuration());
value.setReportTime(deviceMonitoringData.getReportTime());
} else {
// es中也没有直接从老接口拿
isExistEs = false;
value = queryDeviceMonitoringData(event.getMachineIotMac(), reportTime);
}
// 因为ReportTime参与后面的计算所以如果是第一次取这个数据需要设置为当前消息的时间要不然会有很大的差值
value.setReportTime(reportTime);
}
// 是否日期是当天的否则需要更新当天工作时长和当天工作量
if (LocalDate.parse(value.getCurrLocalDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).isBefore(localDate)) {
@ -408,7 +413,6 @@ public class IotMonitoringDataJob {
deviceTotalData.setMachinePwrStat(0);
deviceTotalData.setMachineWorkingStat(0);
}
deviceTotalData.setReportTime(reportTime);
stop = true;
break;
}

2
src/main/resources/META-INF/app.properties

@ -2,4 +2,4 @@ app.id=iot-device-monitoring-data
# test 8.135.8.221
# prod 47.112.164.224
apollo.meta=http://47.112.164.224:5000
apollo.meta=http://8.135.8.221:5000
Loading…
Cancel
Save