From acd767b47a4f78e905a3cbe89a4c82ffe88d73d9 Mon Sep 17 00:00:00 2001
From: hotcoffie <35990065+hotcoffie@users.noreply.github.com>
Date: 星期四, 21 四月 2022 10:04:50 +0800
Subject: [PATCH] Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java | 88 +++++++++++++++++++++++++++++++++-----------
1 files changed, 66 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
index 4f8d6ab..b97457a 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
@@ -1,5 +1,13 @@
package com.genersoft.iot.vmp.gb28181.event.online;
+import com.genersoft.iot.vmp.conf.SipConfig;
+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.event.EventPublisher;
+import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.service.IDeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -7,14 +15,17 @@
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
+import java.text.SimpleDateFormat;
+import java.util.List;
+
/**
- * @Description: 鍦ㄧ嚎浜嬩欢鐩戝惉鍣紝鐩戝惉鍒扮绾垮悗锛屼慨鏀硅澶囩鍦ㄧ嚎鐘舵�併�� 璁惧鍦ㄧ嚎鏈変袱涓潵婧愶細
- * 1銆佽澶囦富鍔ㄦ敞閿�锛屽彂閫佹敞閿�鎸囦护锛寋@link com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor}
- * 2銆佽澶囨湭鐭ュ師鍥犵绾匡紝蹇冭烦瓒呮椂,{@link com.genersoft.iot.vmp.gb28181.transmit.request.impl.MessageRequestProcessor}
- * @author: songww
+ * @description: 鍦ㄧ嚎浜嬩欢鐩戝惉鍣紝鐩戝惉鍒扮绾垮悗锛屼慨鏀硅澶囩鍦ㄧ嚎鐘舵�併�� 璁惧鍦ㄧ嚎鏈変袱涓潵婧愶細
+ * 1銆佽澶囦富鍔ㄦ敞閿�锛屽彂閫佹敞閿�鎸囦护
+ * 2銆佽澶囨湭鐭ュ師鍥犵绾匡紝蹇冭烦瓒呮椂
+ * @author: swwheihei
* @date: 2020骞�5鏈�6鏃� 涓嬪崍1:51:23
*/
@Component
@@ -23,44 +34,77 @@
private final static Logger logger = LoggerFactory.getLogger(OnlineEventListener.class);
@Autowired
- private IVideoManagerStorager storager;
+ private IVideoManagerStorage storager;
+
+ @Autowired
+ private IDeviceService deviceService;
@Autowired
private RedisUtil redis;
+
+ @Autowired
+ private SipConfig sipConfig;
+
+ @Autowired
+ private UserSetting userSetting;
+
+ @Autowired
+ private EventPublisher eventPublisher;
+
+ @Autowired
+ private SIPCommander cmder;
+
+
+ private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public void onApplicationEvent(OnlineEvent event) {
if (logger.isDebugEnabled()) {
- logger.debug("璁惧绂荤嚎浜嬩欢瑙﹀彂锛宒eviceId锛�" + event.getDeviceId() + ",from:" + event.getFrom());
+ logger.debug("璁惧涓婄嚎浜嬩欢瑙﹀彂锛宒eviceId锛�" + event.getDevice().getDeviceId() + ",from:" + event.getFrom());
}
-
- String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDeviceId();
- boolean needUpdateStorager = false;
-
+ Device device = event.getDevice();
+ if (device == null) return;
+ String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + event.getDevice().getDeviceId();
+ Device deviceInStore = storager.queryVideoDevice(device.getDeviceId());
+ device.setOnline(1);
switch (event.getFrom()) {
// 娉ㄥ唽鏃惰Е鍙戠殑鍦ㄧ嚎浜嬩欢锛屽厛鍦╮edis涓鍔犺秴鏃惰秴鏃剁洃鍚�
case VideoManagerConstants.EVENT_ONLINE_REGISTER:
- // TODO 瓒呮椂鏃堕棿鏆傛椂鍐欐涓�180绉�
- redis.set(key, event.getDeviceId(), 180);
- needUpdateStorager = true;
+ // 瓒呮椂鏃堕棿
+ redis.set(key, event.getDevice().getDeviceId(), sipConfig.getKeepaliveTimeOut());
+ device.setRegisterTime(format.format(System.currentTimeMillis()));
+ if (deviceInStore == null) { //绗竴娆′笂绾�
+ logger.info("[{}] 棣栨娉ㄥ唽锛屾煡璇㈣澶囦俊鎭互鍙婇�氶亾淇℃伅", device.getDeviceId());
+ cmder.deviceInfoQuery(device);
+ deviceService.sync(device);
+ }
break;
- // 璁惧涓诲姩鍙戦�佸績璺宠Е鍙戠殑绂荤嚎浜嬩欢
+ // 璁惧涓诲姩鍙戦�佸績璺宠Е鍙戠殑鍦ㄧ嚎浜嬩欢
case VideoManagerConstants.EVENT_ONLINE_KEEPLIVE:
boolean exist = redis.hasKey(key);
// 鍏堝垽鏂槸鍚﹁繕瀛樺湪锛屽綋璁惧鍏堝績璺宠秴鏃跺悗鍙堝彂閫佸績璺虫椂锛宺edis娌℃湁鐩戝惉锛岄渶瑕佸鍔�
if (!exist) {
- needUpdateStorager = true;
- redis.set(key, event.getDeviceId(), 180);
+ redis.set(key, event.getDevice().getDeviceId(), sipConfig.getKeepaliveTimeOut());
} else {
- redis.expire(key, 180);
+ redis.expire(key, sipConfig.getKeepaliveTimeOut());
}
+ device.setKeepaliveTime(format.format(System.currentTimeMillis()));
+ break;
+ // 璁惧涓诲姩鍙戦�佹秷鎭Е鍙戠殑鍦ㄧ嚎浜嬩欢
+ case VideoManagerConstants.EVENT_ONLINE_MESSAGE:
+
break;
}
-
- if (needUpdateStorager) {
- // 澶勭悊绂荤嚎鐩戝惉
- storager.online(event.getDeviceId());
+ // 澶勭悊涓婄嚎鐩戝惉
+ storager.updateDevice(device);
+ // 涓婄嚎娣诲姞璁㈤槄
+ if (device.getSubscribeCycleForCatalog() > 0) {
+ // 鏌ヨ鍦ㄧ嚎璁惧閭d簺寮�鍚簡璁㈤槄锛屼负璁惧寮�鍚畾鏃剁殑鐩綍璁㈤槄
+ deviceService.addCatalogSubscribe(device);
+ }
+ if (device.getSubscribeCycleForMobilePosition() > 0) {
+ deviceService.addMobilePositionSubscribe(device);
}
}
}
--
Gitblit v1.8.0