Commit 7e058801 by 姚冰

[add] 设备离线正常处理

1 parent a9f661be
...@@ -29,6 +29,7 @@ import vion.service.monitor.IRAgentEventService; ...@@ -29,6 +29,7 @@ import vion.service.monitor.IRAgentEventService;
import vion.utils.JsonUtil; import vion.utils.JsonUtil;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static vion.constant.MqttMessageType.WHOLEDAYA_ANALYZE; import static vion.constant.MqttMessageType.WHOLEDAYA_ANALYZE;
...@@ -112,20 +113,33 @@ public class MqttClientMessageListener implements IMqttClientMessageListener { ...@@ -112,20 +113,33 @@ public class MqttClientMessageListener implements IMqttClientMessageListener {
EventRecord eventRecord = JsonUtil.parseObject(payloadStr, EventRecord.class); EventRecord eventRecord = JsonUtil.parseObject(payloadStr, EventRecord.class);
String list = (String) eventRecord.getData(); String list = (String) eventRecord.getData();
List<OfflineDevice> deviceList = JsonUtil.parseArray(list, OfflineDevice.class); List<OfflineDevice> deviceList = JsonUtil.parseArray(list, OfflineDevice.class);
for (int i = 0; i < deviceList.size(); i++) { List<EventRecord> records = new ArrayList<>();
OfflineDevice device = deviceList.get(i); if (deviceList == null || deviceList.isEmpty()) {
EventRecord eventRecord1 = new EventRecord(); EventRecord eventRecord1 = new EventRecord();
BeanUtil.copyProperties(eventRecord, eventRecord1); BeanUtil.copyProperties(eventRecord, eventRecord1);
eventRecord1.setEventUid(eventRecord.getEventUid()); eventRecord1.setEventUid(eventRecord.getEventUid());
eventRecord1.setData(JsonUtil.toJsonString(device));
eventRecord1.setMallUid(deviceList.get(i).getMallUid());
if (StringUtils.isEmpty(device.getDevices())) {
eventRecord1.setStatus(EventStatusEnum.SUCCESS.getCode());
} else {
eventRecord1.setStatus(EventStatusEnum.FAIL.getCode());
}
//入库 //入库
recordService.save(eventRecord1); records.add(eventRecord1);
} else {
for (int i = 0; i < deviceList.size(); i++) {
OfflineDevice device = deviceList.get(i);
EventRecord eventRecord1 = new EventRecord();
BeanUtil.copyProperties(eventRecord, eventRecord1);
eventRecord1.setEventUid(eventRecord.getEventUid());
eventRecord1.setData(JsonUtil.toJsonString(device));
eventRecord1.setMallUid(deviceList.get(i).getMallUid());
if (StringUtils.isEmpty(device.getDevices())) {
eventRecord1.setStatus(EventStatusEnum.SUCCESS.getCode());
} else {
eventRecord1.setStatus(EventStatusEnum.FAIL.getCode());
}
//入库
records.add(eventRecord1);
}
}
if (!records.isEmpty()) {
recordService.saveBatch(records);
} }
// logger.info("设备离线:{}", JSON.toJSONString(eventRecord)); // logger.info("设备离线:{}", JSON.toJSONString(eventRecord));
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!