修复redis mobileposition 消息发送

pull/1642/head
648540858 2024-09-26 14:52:01 +08:00
parent 249bdf69be
commit 97b0616039
2 changed files with 18 additions and 14 deletions

View File

@ -386,7 +386,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
jsonObject.put("serial", mobilePosition.getDeviceId()); jsonObject.put("serial", mobilePosition.getDeviceId());
jsonObject.put("code", mobilePosition.getChannelId()); jsonObject.put("code", channel.getDeviceId());
jsonObject.put("longitude", mobilePosition.getLongitude()); jsonObject.put("longitude", mobilePosition.getLongitude());
jsonObject.put("latitude", mobilePosition.getLatitude()); jsonObject.put("latitude", mobilePosition.getLatitude());
jsonObject.put("altitude", mobilePosition.getAltitude()); jsonObject.put("altitude", mobilePosition.getAltitude());

View File

@ -97,13 +97,15 @@ public class NotifyRequestForMobilePositionProcessor extends SIPRequestProcessor
mobilePosition.setDeviceId(device.getDeviceId()); mobilePosition.setDeviceId(device.getDeviceId());
mobilePosition.setDeviceName(device.getName()); mobilePosition.setDeviceName(device.getName());
mobilePosition.setCreateTime(DateUtil.getNow()); mobilePosition.setCreateTime(DateUtil.getNow());
DeviceChannel deviceChannel = null;
List<Element> elements = rootElement.elements(); List<Element> elements = rootElement.elements();
for (Element element : elements) { for (Element element : elements) {
switch (element.getName()){ switch (element.getName()){
case "DeviceID": case "DeviceID":
String channelId = element.getStringValue(); String channelId = element.getStringValue();
if (!deviceId.equals(channelId)) { if (!deviceId.equals(channelId)) {
DeviceChannel deviceChannel = deviceChannelService.getOne(device.getDeviceId(), channelId); deviceChannel = deviceChannelService.getOne(device.getDeviceId(), channelId);
if (deviceChannel != null) { if (deviceChannel != null) {
mobilePosition.setChannelId(deviceChannel.getId()); mobilePosition.setChannelId(deviceChannel.getId());
} }
@ -162,13 +164,13 @@ public class NotifyRequestForMobilePositionProcessor extends SIPRequestProcessor
}catch (Exception e) { }catch (Exception e) {
log.error("[向上级转发移动位置失败] ", e); log.error("[向上级转发移动位置失败] ", e);
} }
if (mobilePosition.getChannelId() == null || mobilePosition.getChannelId().equals(mobilePosition.getDeviceId())) { if (mobilePosition.getChannelId() == null) {
List<DeviceChannel> channels = deviceChannelService.queryChaneListByDeviceId(mobilePosition.getDeviceId()); List<DeviceChannel> channels = deviceChannelService.queryChaneListByDeviceId(mobilePosition.getDeviceId());
channels.forEach(channel -> { channels.forEach(channel -> {
// 发送redis消息。 通知位置信息的变化 // 发送redis消息。 通知位置信息的变化
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
jsonObject.put("serial", channel.getDeviceId()); jsonObject.put("serial", device.getDeviceId());
jsonObject.put("code", channel.getDeviceId()); jsonObject.put("code", channel.getDeviceId());
jsonObject.put("longitude", mobilePosition.getLongitude()); jsonObject.put("longitude", mobilePosition.getLongitude());
jsonObject.put("latitude", mobilePosition.getLatitude()); jsonObject.put("latitude", mobilePosition.getLatitude());
@ -179,16 +181,18 @@ public class NotifyRequestForMobilePositionProcessor extends SIPRequestProcessor
}); });
}else { }else {
// 发送redis消息。 通知位置信息的变化 // 发送redis消息。 通知位置信息的变化
JSONObject jsonObject = new JSONObject(); if (deviceChannel != null) {
jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); JSONObject jsonObject = new JSONObject();
jsonObject.put("serial", mobilePosition.getDeviceId()); jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
jsonObject.put("code", mobilePosition.getChannelId()); jsonObject.put("serial", mobilePosition.getDeviceId());
jsonObject.put("longitude", mobilePosition.getLongitude()); jsonObject.put("code", deviceChannel.getDeviceId());
jsonObject.put("latitude", mobilePosition.getLatitude()); jsonObject.put("longitude", mobilePosition.getLongitude());
jsonObject.put("altitude", mobilePosition.getAltitude()); jsonObject.put("latitude", mobilePosition.getLatitude());
jsonObject.put("direction", mobilePosition.getDirection()); jsonObject.put("altitude", mobilePosition.getAltitude());
jsonObject.put("speed", mobilePosition.getSpeed()); jsonObject.put("direction", mobilePosition.getDirection());
redisCatchStorage.sendMobilePositionMsg(jsonObject); jsonObject.put("speed", mobilePosition.getSpeed());
redisCatchStorage.sendMobilePositionMsg(jsonObject);
}
} }
} catch (DocumentException e) { } catch (DocumentException e) {
log.error("未处理的异常 ", e); log.error("未处理的异常 ", e);