Commit f1e902af7fd88138c76abcf1a17d04efb8d3293a

Authored by 648540858
1 parent f1fed36c

支持级联移动位置订阅通知转发

src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java
... ... @@ -103,6 +103,16 @@ public class SubscribeHolder {
103 103 return platforms;
104 104 }
105 105  
  106 + public List<String> getAllMobilePositionSubscribePlatform() {
  107 + List<String> platforms = new ArrayList<>();
  108 + if(!mobilePositionMap.isEmpty()) {
  109 + for (String key : mobilePositionMap.keySet()) {
  110 + platforms.add(mobilePositionMap.get(key).getId());
  111 + }
  112 + }
  113 + return platforms;
  114 + }
  115 +
106 116 public void removeAllSubscribe(String platformId) {
107 117 removeMobilePositionSubscribe(platformId);
108 118 removeCatalogSubscribe(platformId);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
... ... @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.*;
4 4 import com.genersoft.iot.vmp.gb28181.event.device.RequestTimeoutEvent;
5 5 import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent;
6 6 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
  7 +import com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition.MobilePositionEvent;
7 8 import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
8 9 import com.genersoft.iot.vmp.media.zlm.event.ZLMOnlineEvent;
9 10 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -94,6 +95,13 @@ public class EventPublisher {
94 95 }
95 96  
96 97  
  98 + public void mobilePositionEventPublish(MobilePosition mobilePosition) {
  99 + MobilePositionEvent event = new MobilePositionEvent(this);
  100 + event.setMobilePosition(mobilePosition);
  101 + applicationEventPublisher.publishEvent(event);
  102 + }
  103 +
  104 +
97 105 public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) {
98 106 CatalogEvent outEvent = new CatalogEvent(this);
99 107 outEvent.setGbStreams(gbStreams);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEvent.java 0 → 100755
  1 +package com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
  4 +import org.springframework.context.ApplicationEvent;
  5 +
  6 +public class MobilePositionEvent extends ApplicationEvent {
  7 + public MobilePositionEvent(Object source) {
  8 + super(source);
  9 + }
  10 +
  11 + private MobilePosition mobilePosition;
  12 +
  13 + public MobilePosition getMobilePosition() {
  14 + return mobilePosition;
  15 + }
  16 +
  17 + public void setMobilePosition(MobilePosition mobilePosition) {
  18 + this.mobilePosition = mobilePosition;
  19 + }
  20 +}
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java 0 → 100755
  1 +package com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  4 +import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
  5 +import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
  6 +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
  7 +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
  8 +import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.context.ApplicationListener;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import javax.sip.InvalidArgumentException;
  16 +import javax.sip.SipException;
  17 +import java.text.ParseException;
  18 +import java.util.List;
  19 +
  20 +/**
  21 + * 移动位置通知消息转发
  22 + */
  23 +@Component
  24 +public class MobilePositionEventLister implements ApplicationListener<MobilePositionEvent> {
  25 +
  26 + private final static Logger logger = LoggerFactory.getLogger(MobilePositionEventLister.class);
  27 +
  28 + @Autowired
  29 + private IVideoManagerStorage storager;
  30 +
  31 + @Autowired
  32 + private SIPCommanderFroPlatform sipCommanderFroPlatform;
  33 +
  34 + @Autowired
  35 + private SubscribeHolder subscribeHolder;
  36 +
  37 + @Override
  38 + public void onApplicationEvent(MobilePositionEvent event) {
  39 + // 获取所用订阅
  40 + List<String> platforms = subscribeHolder.getAllMobilePositionSubscribePlatform();
  41 + if (platforms.isEmpty()) {
  42 + return;
  43 + }
  44 + List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForGBWithGBId(event.getMobilePosition().getChannelId(), platforms);
  45 +
  46 + for (ParentPlatform platform : parentPlatformsForGB) {
  47 + logger.info("[向上级发送MobilePosition] 通道:{},平台:{}, 位置: {}:{}", event.getMobilePosition().getChannelId(),
  48 + platform.getServerGBId(), event.getMobilePosition().getLongitude(), event.getMobilePosition().getLatitude());
  49 + SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
  50 + try {
  51 + sipCommanderFroPlatform.sendNotifyMobilePosition(platform, GPSMsgInfo.getInstance(event.getMobilePosition()),
  52 + subscribe);
  53 + } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
  54 + IllegalAccessException e) {
  55 + logger.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage());
  56 + }
  57 + }
  58 +
  59 + }
  60 +}
  61 +
0 62 \ No newline at end of file
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
2 2  
3   -import com.alibaba.fastjson2.JSONObject;
4   -import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
5 3 import com.genersoft.iot.vmp.conf.SipConfig;
6 4 import com.genersoft.iot.vmp.conf.UserSetting;
7 5 import com.genersoft.iot.vmp.gb28181.bean.*;
... ... @@ -78,9 +76,6 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
78 76 @Autowired
79 77 private NotifyRequestForCatalogProcessor notifyRequestForCatalogProcessor;
80 78  
81   - @Autowired
82   - private CivilCodeFileConf civilCodeFileConf;
83   -
84 79 private ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>();
85 80  
86 81 @Qualifier("taskExecutor")
... ... @@ -98,7 +93,6 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
98 93 @Override
99 94 public void process(RequestEvent evt) {
100 95 try {
101   -
102 96 if (taskQueue.size() >= userSetting.getMaxNotifyCountQueue()) {
103 97 responseAck((SIPRequest) evt.getRequest(), Response.BUSY_HERE, null, null);
104 98 logger.error("[notify] 待处理消息队列已满 {},返回486 BUSY_HERE,消息不做处理", userSetting.getMaxNotifyCountQueue());
... ... @@ -234,25 +228,8 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
234 228 mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
235 229 mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
236 230  
237   - if (userSetting.getSavePositionHistory()) {
238   - storager.insertMobilePosition(mobilePosition);
239   - }
  231 + deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
240 232  
241   - storager.updateChannelPosition(deviceChannel);
242   - // 向关联了该通道并且开启移动位置订阅的上级平台发送移动位置订阅消息
243   -
244   -
245   - // 发送redis消息。 通知位置信息的变化
246   - JSONObject jsonObject = new JSONObject();
247   - jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
248   - jsonObject.put("serial", deviceId);
249   - jsonObject.put("code", channelId);
250   - jsonObject.put("longitude", mobilePosition.getLongitude());
251   - jsonObject.put("latitude", mobilePosition.getLatitude());
252   - jsonObject.put("altitude", mobilePosition.getAltitude());
253   - jsonObject.put("direction", mobilePosition.getDirection());
254   - jsonObject.put("speed", mobilePosition.getSpeed());
255   - redisCatchStorage.sendMobilePositionMsg(jsonObject);
256 233 } catch (DocumentException e) {
257 234 logger.error("未处理的异常 ", e);
258 235 }
... ... @@ -340,25 +317,8 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
340 317 mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
341 318 mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
342 319  
343   - if (userSetting.getSavePositionHistory()) {
344   - storager.insertMobilePosition(mobilePosition);
345   - }
346   -
347   - storager.updateChannelPosition(deviceChannel);
348   - // 发送redis消息。 通知位置信息的变化
349   - JSONObject jsonObject = new JSONObject();
350   - jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
351   - jsonObject.put("serial", deviceChannel.getDeviceId());
352   - jsonObject.put("code", deviceChannel.getChannelId());
353   - jsonObject.put("longitude", mobilePosition.getLongitude());
354   - jsonObject.put("latitude", mobilePosition.getLatitude());
355   - jsonObject.put("altitude", mobilePosition.getAltitude());
356   - jsonObject.put("direction", mobilePosition.getDirection());
357   - jsonObject.put("speed", mobilePosition.getSpeed());
358   - redisCatchStorage.sendMobilePositionMsg(jsonObject);
359   -
  320 + deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
360 321 }
361   - // TODO: 需要实现存储报警信息、报警分类
362 322  
363 323 // 回复200 OK
364 324 if (redisCatchStorage.deviceIsOnline(deviceId)) {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
... ... @@ -75,6 +75,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
75 75 @Autowired
76 76 private ThreadPoolTaskExecutor taskExecutor;
77 77  
  78 + @Autowired
  79 + private EventPublisher eventPublisher;
  80 +
78 81  
79 82 @Override
80 83 public void afterPropertiesSet() throws Exception {
... ... @@ -158,22 +161,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
158 161 mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
159 162 mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
160 163  
161   - if (userSetting.getSavePositionHistory()) {
162   - storager.insertMobilePosition(mobilePosition);
163   - }
164   - storager.updateChannelPosition(deviceChannel);
165   -
166   - // 发送redis消息。 通知位置信息的变化
167   - JSONObject jsonObject = new JSONObject();
168   - jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
169   - jsonObject.put("serial", deviceChannel.getDeviceId());
170   - jsonObject.put("code", deviceChannel.getChannelId());
171   - jsonObject.put("longitude", mobilePosition.getLongitude());
172   - jsonObject.put("latitude", mobilePosition.getLatitude());
173   - jsonObject.put("altitude", mobilePosition.getAltitude());
174   - jsonObject.put("direction", mobilePosition.getDirection());
175   - jsonObject.put("speed", mobilePosition.getSpeed());
176   - redisCatchStorage.sendMobilePositionMsg(jsonObject);
  164 + deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
177 165 }
178 166 }
179 167 if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
2 2  
3   -import com.alibaba.fastjson2.JSONObject;
4 3 import com.genersoft.iot.vmp.conf.UserSetting;
5 4 import com.genersoft.iot.vmp.gb28181.bean.*;
  5 +import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
6 6 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
7 7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
8 8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
... ... @@ -57,6 +57,9 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
57 57 @Autowired
58 58 private IDeviceChannelService deviceChannelService;
59 59  
  60 + @Autowired
  61 + private EventPublisher eventPublisher;
  62 +
60 63 private ConcurrentLinkedQueue<SipMsgInfo> taskQueue = new ConcurrentLinkedQueue<>();
61 64  
62 65 @Qualifier("taskExecutor")
... ... @@ -137,22 +140,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
137 140 mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
138 141 mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
139 142  
140   - if (userSetting.getSavePositionHistory()) {
141   - storager.insertMobilePosition(mobilePosition);
142   - }
143   - storager.updateChannelPosition(deviceChannel);
144   -
145   - // 发送redis消息。 通知位置信息的变化
146   - JSONObject jsonObject = new JSONObject();
147   - jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
148   - jsonObject.put("serial", deviceChannel.getDeviceId());
149   - jsonObject.put("code", deviceChannel.getChannelId());
150   - jsonObject.put("longitude", mobilePosition.getLongitude());
151   - jsonObject.put("latitude", mobilePosition.getLatitude());
152   - jsonObject.put("altitude", mobilePosition.getAltitude());
153   - jsonObject.put("direction", mobilePosition.getDirection());
154   - jsonObject.put("speed", mobilePosition.getSpeed());
155   - redisCatchStorage.sendMobilePositionMsg(jsonObject);
  143 + deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
156 144  
157 145 } catch (DocumentException e) {
158 146 logger.error("未处理的异常 ", e);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
2 2  
3   -import com.alibaba.fastjson2.JSONObject;
4 3 import com.genersoft.iot.vmp.conf.UserSetting;
5 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
6 5 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
... ... @@ -131,11 +130,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
131 130 mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
132 131 mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
133 132  
134   - if (userSetting.getSavePositionHistory()) {
135   - storager.insertMobilePosition(mobilePosition);
136   - }
137   -
138   - storager.updateChannelPosition(deviceChannel);
  133 + deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
139 134  
140 135 String key = DeferredResultHolder.CALLBACK_CMD_MOBILE_POSITION + device.getDeviceId();
141 136 RequestMessage msg = new RequestMessage();
... ... @@ -143,17 +138,6 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
143 138 msg.setData(mobilePosition);
144 139 resultHolder.invokeAllResult(msg);
145 140  
146   - // 发送redis消息。 通知位置信息的变化
147   - JSONObject jsonObject = new JSONObject();
148   - jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
149   - jsonObject.put("serial", deviceChannel.getDeviceId());
150   - jsonObject.put("code", deviceChannel.getChannelId());
151   - jsonObject.put("longitude", mobilePosition.getLongitude());
152   - jsonObject.put("latitude", mobilePosition.getLatitude());
153   - jsonObject.put("altitude", mobilePosition.getAltitude());
154   - jsonObject.put("direction", mobilePosition.getDirection());
155   - jsonObject.put("speed", mobilePosition.getSpeed());
156   - redisCatchStorage.sendMobilePositionMsg(jsonObject);
157 141 //回复 200 OK
158 142 try {
159 143 responseAck(request, Response.OK);
... ...
src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.bean.Device;
4 4 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  5 +import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
5 6 import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
6 7 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
7 8  
... ... @@ -92,4 +93,9 @@ public interface IDeviceChannelService {
92 93 * 修改通道的码流类型
93 94 */
94 95 void updateChannelStreamIdentification(DeviceChannel channel);
  96 +
  97 + List<DeviceChannel> queryChaneListByDeviceId(String deviceId);
  98 +
  99 + void updateChannelGPS(Device device, DeviceChannel deviceChannel, MobilePosition mobilePosition);
  100 +
95 101 }
... ...
src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java
1 1 package com.genersoft.iot.vmp.service.bean;
2 2  
  3 +import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
  4 +import com.genersoft.iot.vmp.utils.DateUtil;
  5 +
3 6 public class GPSMsgInfo {
4 7  
5 8 /**
... ... @@ -39,6 +42,18 @@ public class GPSMsgInfo {
39 42  
40 43 private boolean stored;
41 44  
  45 + public static GPSMsgInfo getInstance(MobilePosition mobilePosition) {
  46 + GPSMsgInfo gpsMsgInfo = new GPSMsgInfo();
  47 + gpsMsgInfo.setId(mobilePosition.getChannelId());
  48 + gpsMsgInfo.setAltitude(mobilePosition.getAltitude() + "");
  49 + gpsMsgInfo.setLng(mobilePosition.getLongitude());
  50 + gpsMsgInfo.setLat(mobilePosition.getLatitude());
  51 + gpsMsgInfo.setSpeed(mobilePosition.getSpeed());
  52 + gpsMsgInfo.setDirection(mobilePosition.getDirection() + "");
  53 + gpsMsgInfo.setTime(DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
  54 + return gpsMsgInfo;
  55 + }
  56 +
42 57  
43 58 public String getId() {
44 59 return id;
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
1 1 package com.genersoft.iot.vmp.service.impl;
2 2  
  3 +import com.alibaba.fastjson2.JSONObject;
3 4 import com.baomidou.dynamic.datasource.annotation.DS;
4 5 import com.genersoft.iot.vmp.common.InviteInfo;
5 6 import com.genersoft.iot.vmp.common.InviteSessionType;
  7 +import com.genersoft.iot.vmp.conf.UserSetting;
6 8 import com.genersoft.iot.vmp.gb28181.bean.Device;
7 9 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  10 +import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
  11 +import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
8 12 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
9 13 import com.genersoft.iot.vmp.service.IDeviceChannelService;
10 14 import com.genersoft.iot.vmp.service.IInviteStreamService;
11 15 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
12 16 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
13 17 import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
  18 +import com.genersoft.iot.vmp.storager.dao.DeviceMobilePositionMapper;
14 19 import com.genersoft.iot.vmp.utils.DateUtil;
15 20 import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
16 21 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
... ... @@ -35,7 +40,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
35 40 private final static Logger logger = LoggerFactory.getLogger(DeviceChannelServiceImpl.class);
36 41  
37 42 @Autowired
38   - private IRedisCatchStorage redisCatchStorage;
  43 + private EventPublisher eventPublisher;
39 44  
40 45 @Autowired
41 46 private IInviteStreamService inviteStreamService;
... ... @@ -46,6 +51,15 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
46 51 @Autowired
47 52 private DeviceMapper deviceMapper;
48 53  
  54 + @Autowired
  55 + private DeviceMobilePositionMapper deviceMobilePositionMapper;
  56 +
  57 + @Autowired
  58 + private UserSetting userSetting;
  59 +
  60 + @Autowired
  61 + private IRedisCatchStorage redisCatchStorage;
  62 +
49 63 @Override
50 64 public DeviceChannel updateGps(DeviceChannel deviceChannel, Device device) {
51 65 if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) {
... ... @@ -84,7 +98,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
84 98 public void updateChannel(String deviceId, DeviceChannel channel) {
85 99 String channelId = channel.getChannelId();
86 100 channel.setDeviceId(deviceId);
87   -// StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
88 101 InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
89 102 if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
90 103 channel.setStreamId(inviteInfo.getStreamInfo().getStream());
... ... @@ -280,4 +293,64 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
280 293 }
281 294 channelMapper.updateChannelStreamIdentification(channel);
282 295 }
  296 +
  297 + @Override
  298 + public List<DeviceChannel> queryChaneListByDeviceId(String deviceId) {
  299 + return channelMapper.queryAllChannels(deviceId);
  300 + }
  301 +
  302 + @Override
  303 + public void updateChannelGPS(Device device, DeviceChannel deviceChannel, MobilePosition mobilePosition) {
  304 + if (userSetting.getSavePositionHistory()) {
  305 + deviceMobilePositionMapper.insertNewPosition(mobilePosition);
  306 + }
  307 +
  308 + if (deviceChannel.getChannelId().equals(deviceChannel.getDeviceId())) {
  309 + deviceChannel.setChannelId(null);
  310 + }
  311 + if (deviceChannel.getGpsTime() == null) {
  312 + deviceChannel.setGpsTime(DateUtil.getNow());
  313 + }
  314 +
  315 + int updated = channelMapper.updatePosition(deviceChannel);
  316 + if (updated == 0) {
  317 + return;
  318 + }
  319 +
  320 + List<DeviceChannel> deviceChannels = new ArrayList<>();
  321 + if (deviceChannel.getChannelId() == null) {
  322 + // 有的设备这里上报的deviceId与通道Id是一样,这种情况更新设备下的全部通道
  323 + List<DeviceChannel> deviceChannelsInDb = queryChaneListByDeviceId(device.getDeviceId());
  324 + deviceChannels.addAll(deviceChannelsInDb);
  325 + }else {
  326 + deviceChannels.add(deviceChannel);
  327 + }
  328 + if (deviceChannels.isEmpty()) {
  329 + return;
  330 + }
  331 + if (deviceChannels.size() > 100) {
  332 + logger.warn("[更新通道位置信息后发送通知] 设备可能是平台,上报的位置信息未标明通道编号," +
  333 + "导致所有通道被更新位置, deviceId:{}", device.getDeviceId());
  334 + }
  335 + for (DeviceChannel channel : deviceChannels) {
  336 + // 向关联了该通道并且开启移动位置订阅的上级平台发送移动位置订阅消息
  337 + mobilePosition.setChannelId(channel.getChannelId());
  338 + try {
  339 + eventPublisher.mobilePositionEventPublish(mobilePosition);
  340 + }catch (Exception e) {
  341 + logger.error("[向上级转发移动位置失败] ", e);
  342 + }
  343 + // 发送redis消息。 通知位置信息的变化
  344 + JSONObject jsonObject = new JSONObject();
  345 + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
  346 + jsonObject.put("serial", mobilePosition.getDeviceId());
  347 + jsonObject.put("code", mobilePosition.getChannelId());
  348 + jsonObject.put("longitude", mobilePosition.getLongitude());
  349 + jsonObject.put("latitude", mobilePosition.getLatitude());
  350 + jsonObject.put("altitude", mobilePosition.getAltitude());
  351 + jsonObject.put("direction", mobilePosition.getDirection());
  352 + jsonObject.put("speed", mobilePosition.getSpeed());
  353 + redisCatchStorage.sendMobilePositionMsg(jsonObject);
  354 + }
  355 + }
283 356 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
... ... @@ -395,7 +395,7 @@ public interface DeviceChannelMapper {
395 395 "WHERE device_id=#{deviceId} " +
396 396 " <if test='channelId != null' > AND channel_id=#{channelId}</if>" +
397 397 " </script>"})
398   - void updatePosition(DeviceChannel deviceChannel);
  398 + int updatePosition(DeviceChannel deviceChannel);
399 399  
400 400 @Select("SELECT * FROM wvp_device_channel WHERE length(trim(stream_id)) > 0")
401 401 List<DeviceChannel> getAllChannelInPlay();
... ...