From dae67453c4449fbdd9afebd87de049c70c72418d Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 28 三月 2024 16:50:44 +0800
Subject: [PATCH] Merge branch 'master' into dev/abl支持

---
 src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java                              |   61 ++++++++++
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java |   18 --
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java     |   22 --
 src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java                                                                 |    6 +
 src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java                                                                       |   15 ++
 src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java                                                         |   77 ++++++++++++
 src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java                                                                  |   10 +
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java              |   20 --
 src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEvent.java                                    |   20 +++
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java                                    |   44 -------
 src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java                                                                  |   10 +
 src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java                                                              |    2 
 12 files changed, 210 insertions(+), 95 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java
index e7b7ab8..6557bba 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java
@@ -103,6 +103,16 @@
         return platforms;
     }
 
+    public List<String> getAllMobilePositionSubscribePlatform() {
+        List<String> platforms = new ArrayList<>();
+        if(!mobilePositionMap.isEmpty()) {
+            for (String key : mobilePositionMap.keySet()) {
+                platforms.add(mobilePositionMap.get(key).getId());
+            }
+        }
+        return platforms;
+    }
+
     public void removeAllSubscribe(String platformId) {
         removeMobilePositionSubscribe(platformId);
         removeCatalogSubscribe(platformId);
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
index ba538f1..5ca45bf 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
@@ -10,6 +10,9 @@
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
 import com.genersoft.iot.vmp.media.event.MediaServerOfflineEvent;
 import com.genersoft.iot.vmp.media.event.MediaServerOnlineEvent;
+import com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition.MobilePositionEvent;
+import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
+import com.genersoft.iot.vmp.media.zlm.event.ZLMOnlineEvent;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Component;
@@ -96,6 +99,13 @@
 	}
 
 
+	public void mobilePositionEventPublish(MobilePosition mobilePosition) {
+		MobilePositionEvent event = new MobilePositionEvent(this);
+		event.setMobilePosition(mobilePosition);
+		applicationEventPublisher.publishEvent(event);
+	}
+
+
 	public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) {
 		CatalogEvent outEvent = new CatalogEvent(this);
 		outEvent.setGbStreams(gbStreams);
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEvent.java
new file mode 100755
index 0000000..0686651
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEvent.java
@@ -0,0 +1,20 @@
+package com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition;
+
+import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
+import org.springframework.context.ApplicationEvent;
+
+public class MobilePositionEvent extends ApplicationEvent {
+    public MobilePositionEvent(Object source) {
+        super(source);
+    }
+
+    private MobilePosition mobilePosition;
+
+    public MobilePosition getMobilePosition() {
+        return mobilePosition;
+    }
+
+    public void setMobilePosition(MobilePosition mobilePosition) {
+        this.mobilePosition = mobilePosition;
+    }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java
new file mode 100755
index 0000000..7a96116
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java
@@ -0,0 +1,61 @@
+package com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition;
+
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
+import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
+import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+import javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
+import java.text.ParseException;
+import java.util.List;
+
+/**
+ * 绉诲姩浣嶇疆閫氱煡娑堟伅杞彂
+ */
+@Component
+public class MobilePositionEventLister implements ApplicationListener<MobilePositionEvent> {
+
+    private final static Logger logger = LoggerFactory.getLogger(MobilePositionEventLister.class);
+
+    @Autowired
+    private IVideoManagerStorage storager;
+
+    @Autowired
+    private SIPCommanderFroPlatform sipCommanderFroPlatform;
+
+    @Autowired
+    private SubscribeHolder subscribeHolder;
+
+    @Override
+    public void onApplicationEvent(MobilePositionEvent event) {
+        // 鑾峰彇鎵�鐢ㄨ闃�
+        List<String> platforms = subscribeHolder.getAllMobilePositionSubscribePlatform();
+        if (platforms.isEmpty()) {
+            return;
+        }
+        List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForGBWithGBId(event.getMobilePosition().getChannelId(), platforms);
+
+        for (ParentPlatform platform : parentPlatformsForGB) {
+            logger.info("[鍚戜笂绾у彂閫丮obilePosition] 閫氶亾锛歿}锛屽钩鍙帮細{}锛� 浣嶇疆锛� {}:{}", event.getMobilePosition().getChannelId(),
+                    platform.getServerGBId(), event.getMobilePosition().getLongitude(), event.getMobilePosition().getLatitude());
+            SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
+            try {
+                sipCommanderFroPlatform.sendNotifyMobilePosition(platform, GPSMsgInfo.getInstance(event.getMobilePosition()),
+                        subscribe);
+            } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
+                     IllegalAccessException e) {
+                logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 Catalog閫氱煡: {}", e.getMessage());
+            }
+        }
+
+    }
+}
+ 
\ No newline at end of file
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
index 435f35f..e54aa2d 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
@@ -1,7 +1,5 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
 
-import com.alibaba.fastjson2.JSONObject;
-import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -78,9 +76,6 @@
 	@Autowired
 	private NotifyRequestForCatalogProcessor notifyRequestForCatalogProcessor;
 
-	@Autowired
-	private CivilCodeFileConf civilCodeFileConf;
-
 	private ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>();
 
 	@Qualifier("taskExecutor")
@@ -98,7 +93,6 @@
 	@Override
 	public void process(RequestEvent evt) {
 		try {
-
 			if (taskQueue.size() >= userSetting.getMaxNotifyCountQueue()) {
 				responseAck((SIPRequest) evt.getRequest(), Response.BUSY_HERE, null, null);
 				logger.error("[notify] 寰呭鐞嗘秷鎭槦鍒楀凡婊� {}锛岃繑鍥�486 BUSY_HERE锛屾秷鎭笉鍋氬鐞�", userSetting.getMaxNotifyCountQueue());
@@ -234,25 +228,8 @@
 			mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
 			mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
 
-			if (userSetting.getSavePositionHistory()) {
-				storager.insertMobilePosition(mobilePosition);
-			}
+			deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
 
-			storager.updateChannelPosition(deviceChannel);
-			// 鍚戝叧鑱斾簡璇ラ�氶亾骞朵笖寮�鍚Щ鍔ㄤ綅缃闃呯殑涓婄骇骞冲彴鍙戦�佺Щ鍔ㄤ綅缃闃呮秷鎭�
-
-
-			// 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
-			JSONObject jsonObject = new JSONObject();
-			jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
-			jsonObject.put("serial", deviceId);
-			jsonObject.put("code", channelId);
-			jsonObject.put("longitude", mobilePosition.getLongitude());
-			jsonObject.put("latitude", mobilePosition.getLatitude());
-			jsonObject.put("altitude", mobilePosition.getAltitude());
-			jsonObject.put("direction", mobilePosition.getDirection());
-			jsonObject.put("speed", mobilePosition.getSpeed());
-			redisCatchStorage.sendMobilePositionMsg(jsonObject);
 		} catch (DocumentException  e) {
 			logger.error("鏈鐞嗙殑寮傚父 ", e);
 		}
@@ -340,25 +317,8 @@
 				mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
 				mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
 
-				if (userSetting.getSavePositionHistory()) {
-					storager.insertMobilePosition(mobilePosition);
-				}
-
-				storager.updateChannelPosition(deviceChannel);
-				// 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
-				JSONObject jsonObject = new JSONObject();
-				jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
-				jsonObject.put("serial", deviceChannel.getDeviceId());
-				jsonObject.put("code", deviceChannel.getChannelId());
-				jsonObject.put("longitude", mobilePosition.getLongitude());
-				jsonObject.put("latitude", mobilePosition.getLatitude());
-				jsonObject.put("altitude", mobilePosition.getAltitude());
-				jsonObject.put("direction", mobilePosition.getDirection());
-				jsonObject.put("speed", mobilePosition.getSpeed());
-				redisCatchStorage.sendMobilePositionMsg(jsonObject);
-
+				deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
 			}
-			// TODO: 闇�瑕佸疄鐜板瓨鍌ㄦ姤璀︿俊鎭�佹姤璀﹀垎绫�
 
 			// 鍥炲200 OK
 			if (redisCatchStorage.deviceIsOnline(deviceId)) {
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
index 2fc7ae0..ec4a399 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
@@ -75,6 +75,9 @@
     @Autowired
     private ThreadPoolTaskExecutor taskExecutor;
 
+    @Autowired
+    private EventPublisher eventPublisher;
+
 
     @Override
     public void afterPropertiesSet() throws Exception {
@@ -158,22 +161,7 @@
                                 mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
                                 mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
 
-                                if (userSetting.getSavePositionHistory()) {
-                                    storager.insertMobilePosition(mobilePosition);
-                                }
-                                storager.updateChannelPosition(deviceChannel);
-
-                                // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
-                                JSONObject jsonObject = new JSONObject();
-                                jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
-                                jsonObject.put("serial", deviceChannel.getDeviceId());
-                                jsonObject.put("code", deviceChannel.getChannelId());
-                                jsonObject.put("longitude", mobilePosition.getLongitude());
-                                jsonObject.put("latitude", mobilePosition.getLatitude());
-                                jsonObject.put("altitude", mobilePosition.getAltitude());
-                                jsonObject.put("direction", mobilePosition.getDirection());
-                                jsonObject.put("speed", mobilePosition.getSpeed());
-                                redisCatchStorage.sendMobilePositionMsg(jsonObject);
+                                deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
                             }
                         }
                         if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) {
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
index 9a82b8a..bc588c9 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
@@ -1,8 +1,8 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.*;
+import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
@@ -56,6 +56,9 @@
 
     @Autowired
     private IDeviceChannelService deviceChannelService;
+
+    @Autowired
+    private EventPublisher eventPublisher;
 
     private ConcurrentLinkedQueue<SipMsgInfo> taskQueue = new ConcurrentLinkedQueue<>();
 
@@ -137,22 +140,7 @@
                         mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
                         mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
 
-                        if (userSetting.getSavePositionHistory()) {
-                            storager.insertMobilePosition(mobilePosition);
-                        }
-                        storager.updateChannelPosition(deviceChannel);
-
-                        // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
-                        JSONObject jsonObject = new JSONObject();
-                        jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
-                        jsonObject.put("serial", deviceChannel.getDeviceId());
-                        jsonObject.put("code", deviceChannel.getChannelId());
-                        jsonObject.put("longitude", mobilePosition.getLongitude());
-                        jsonObject.put("latitude", mobilePosition.getLatitude());
-                        jsonObject.put("altitude", mobilePosition.getAltitude());
-                        jsonObject.put("direction", mobilePosition.getDirection());
-                        jsonObject.put("speed", mobilePosition.getSpeed());
-                        redisCatchStorage.sendMobilePositionMsg(jsonObject);
+                        deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
 
                     } catch (DocumentException e) {
                         logger.error("鏈鐞嗙殑寮傚父 ", e);
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
index 36a72bc..5c3d6d6 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
@@ -1,6 +1,5 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
@@ -131,11 +130,7 @@
             mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
             mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
 
-            if (userSetting.getSavePositionHistory()) {
-                storager.insertMobilePosition(mobilePosition);
-            }
-
-            storager.updateChannelPosition(deviceChannel);
+            deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition);
 
             String key = DeferredResultHolder.CALLBACK_CMD_MOBILE_POSITION + device.getDeviceId();
             RequestMessage msg = new RequestMessage();
@@ -143,17 +138,6 @@
             msg.setData(mobilePosition);
             resultHolder.invokeAllResult(msg);
 
-            // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
-            jsonObject.put("serial", deviceChannel.getDeviceId());
-            jsonObject.put("code", deviceChannel.getChannelId());
-            jsonObject.put("longitude", mobilePosition.getLongitude());
-            jsonObject.put("latitude", mobilePosition.getLatitude());
-            jsonObject.put("altitude", mobilePosition.getAltitude());
-            jsonObject.put("direction", mobilePosition.getDirection());
-            jsonObject.put("speed", mobilePosition.getSpeed());
-            redisCatchStorage.sendMobilePositionMsg(jsonObject);
             //鍥炲 200 OK
             try {
                 responseAck(request, Response.OK);
diff --git a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java
index 5a20841..c690f11 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java
@@ -2,6 +2,7 @@
 
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
 import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
 
@@ -92,4 +93,9 @@
      * 淇敼閫氶亾鐨勭爜娴佺被鍨�
      */
     void updateChannelStreamIdentification(DeviceChannel channel);
+
+    List<DeviceChannel> queryChaneListByDeviceId(String deviceId);
+
+    void updateChannelGPS(Device device, DeviceChannel deviceChannel, MobilePosition mobilePosition);
+
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java b/src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java
index b814c18..3b84420 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java
@@ -1,5 +1,8 @@
 package com.genersoft.iot.vmp.service.bean;
 
+import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
+import com.genersoft.iot.vmp.utils.DateUtil;
+
 public class GPSMsgInfo {
 
     /**
@@ -39,6 +42,18 @@
 
     private boolean stored;
 
+    public static GPSMsgInfo getInstance(MobilePosition mobilePosition) {
+        GPSMsgInfo gpsMsgInfo = new GPSMsgInfo();
+        gpsMsgInfo.setId(mobilePosition.getChannelId());
+        gpsMsgInfo.setAltitude(mobilePosition.getAltitude() + "");
+        gpsMsgInfo.setLng(mobilePosition.getLongitude());
+        gpsMsgInfo.setLat(mobilePosition.getLatitude());
+        gpsMsgInfo.setSpeed(mobilePosition.getSpeed());
+        gpsMsgInfo.setDirection(mobilePosition.getDirection() + "");
+        gpsMsgInfo.setTime(DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
+        return gpsMsgInfo;
+    }
+
 
     public String getId() {
         return id;
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
index 55fa5e9..632be91 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
@@ -1,16 +1,21 @@
 package com.genersoft.iot.vmp.service.impl;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.genersoft.iot.vmp.common.InviteInfo;
 import com.genersoft.iot.vmp.common.InviteSessionType;
+import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
+import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
 import com.genersoft.iot.vmp.service.IDeviceChannelService;
 import com.genersoft.iot.vmp.service.IInviteStreamService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
 import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
+import com.genersoft.iot.vmp.storager.dao.DeviceMobilePositionMapper;
 import com.genersoft.iot.vmp.utils.DateUtil;
 import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
@@ -35,7 +40,7 @@
     private final static Logger logger = LoggerFactory.getLogger(DeviceChannelServiceImpl.class);
 
     @Autowired
-    private IRedisCatchStorage redisCatchStorage;
+    private EventPublisher eventPublisher;
 
     @Autowired
     private IInviteStreamService inviteStreamService;
@@ -45,6 +50,15 @@
 
     @Autowired
     private DeviceMapper deviceMapper;
+
+    @Autowired
+    private DeviceMobilePositionMapper deviceMobilePositionMapper;
+
+    @Autowired
+    private UserSetting userSetting;
+
+    @Autowired
+    private IRedisCatchStorage redisCatchStorage;
 
     @Override
     public DeviceChannel updateGps(DeviceChannel deviceChannel, Device device) {
@@ -84,7 +98,6 @@
     public void updateChannel(String deviceId, DeviceChannel channel) {
         String channelId = channel.getChannelId();
         channel.setDeviceId(deviceId);
-//        StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
         InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
         if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
             channel.setStreamId(inviteInfo.getStreamInfo().getStream());
@@ -280,4 +293,64 @@
         }
         channelMapper.updateChannelStreamIdentification(channel);
     }
+
+    @Override
+    public List<DeviceChannel> queryChaneListByDeviceId(String deviceId) {
+        return channelMapper.queryAllChannels(deviceId);
+    }
+
+    @Override
+    public void updateChannelGPS(Device device, DeviceChannel deviceChannel, MobilePosition mobilePosition) {
+        if (userSetting.getSavePositionHistory()) {
+            deviceMobilePositionMapper.insertNewPosition(mobilePosition);
+        }
+
+        if (deviceChannel.getChannelId().equals(deviceChannel.getDeviceId())) {
+            deviceChannel.setChannelId(null);
+        }
+        if (deviceChannel.getGpsTime() == null) {
+            deviceChannel.setGpsTime(DateUtil.getNow());
+        }
+
+        int updated = channelMapper.updatePosition(deviceChannel);
+        if (updated == 0) {
+            return;
+        }
+
+        List<DeviceChannel> deviceChannels = new ArrayList<>();
+        if (deviceChannel.getChannelId() == null) {
+            // 鏈夌殑璁惧杩欓噷涓婃姤鐨刣eviceId涓庨�氶亾Id鏄竴鏍凤紝杩欑鎯呭喌鏇存柊璁惧涓嬬殑鍏ㄩ儴閫氶亾
+            List<DeviceChannel> deviceChannelsInDb = queryChaneListByDeviceId(device.getDeviceId());
+            deviceChannels.addAll(deviceChannelsInDb);
+        }else {
+            deviceChannels.add(deviceChannel);
+        }
+        if (deviceChannels.isEmpty()) {
+            return;
+        }
+        if (deviceChannels.size() > 100) {
+            logger.warn("[鏇存柊閫氶亾浣嶇疆淇℃伅鍚庡彂閫侀�氱煡] 璁惧鍙兘鏄钩鍙帮紝涓婃姤鐨勪綅缃俊鎭湭鏍囨槑閫氶亾缂栧彿锛�" +
+                    "瀵艰嚧鎵�鏈夐�氶亾琚洿鏂颁綅缃紝 deviceId:{}", device.getDeviceId());
+        }
+        for (DeviceChannel channel : deviceChannels) {
+            // 鍚戝叧鑱斾簡璇ラ�氶亾骞朵笖寮�鍚Щ鍔ㄤ綅缃闃呯殑涓婄骇骞冲彴鍙戦�佺Щ鍔ㄤ綅缃闃呮秷鎭�
+            mobilePosition.setChannelId(channel.getChannelId());
+            try {
+                eventPublisher.mobilePositionEventPublish(mobilePosition);
+            }catch (Exception e) {
+                logger.error("[鍚戜笂绾ц浆鍙戠Щ鍔ㄤ綅缃け璐 ", e);
+            }
+            // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
+            jsonObject.put("serial", mobilePosition.getDeviceId());
+            jsonObject.put("code", mobilePosition.getChannelId());
+            jsonObject.put("longitude", mobilePosition.getLongitude());
+            jsonObject.put("latitude", mobilePosition.getLatitude());
+            jsonObject.put("altitude", mobilePosition.getAltitude());
+            jsonObject.put("direction", mobilePosition.getDirection());
+            jsonObject.put("speed", mobilePosition.getSpeed());
+            redisCatchStorage.sendMobilePositionMsg(jsonObject);
+        }
+    }
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
index c751b91..c03d73a 100755
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -395,7 +395,7 @@
             "WHERE device_id=#{deviceId} " +
             " <if test='channelId != null' >  AND channel_id=#{channelId}</if>" +
             " </script>"})
-    void updatePosition(DeviceChannel deviceChannel);
+    int updatePosition(DeviceChannel deviceChannel);
 
     @Select("SELECT * FROM wvp_device_channel WHERE length(trim(stream_id)) > 0")
     List<DeviceChannel> getAllChannelInPlay();

--
Gitblit v1.8.0