From 83411ad1277f8d4dfbc95aff2f15900150e84db3 Mon Sep 17 00:00:00 2001
From: 64850858 <648540858@qq.com>
Date: 星期一, 07 六月 2021 15:11:53 +0800
Subject: [PATCH] 设备信息增加最近注册时间和最近心跳时间,心跳超时时间变为可配置

---
 src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 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 b9bb5b1..acdf272 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,7 @@
 package com.genersoft.iot.vmp.gb28181.event.online;
 
+import com.genersoft.iot.vmp.conf.SipConfig;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +11,9 @@
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 /**
  * @Description: 鍦ㄧ嚎浜嬩欢鐩戝惉鍣紝鐩戝惉鍒扮绾垮悗锛屼慨鏀硅澶囩鍦ㄧ嚎鐘舵�併�� 璁惧鍦ㄧ嚎鏈変袱涓潵婧愶細
@@ -28,39 +33,46 @@
 	@Autowired
     private RedisUtil redis;
 
+	@Autowired
+    private SipConfig sipConfig;
+
+	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();
+		String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDevice().getDeviceId();
 
 		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(new Date(System.currentTimeMillis())));
 			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(new Date(System.currentTimeMillis())));
+			break;
+		// 璁惧涓诲姩鍙戦�佹秷鎭Е鍙戠殑鍦ㄧ嚎浜嬩欢
+		case VideoManagerConstants.EVENT_ONLINE_MESSAGE:
+
 			break;
 		}
-		
-		if (needUpdateStorager) {
-			// 澶勭悊绂荤嚎鐩戝惉
-			storager.online(event.getDeviceId());
-		}
+
+		device.setOnline(1);
+		// 澶勭悊涓婄嚎鐩戝惉
+		storager.updateDevice(device);
 	}
 }

--
Gitblit v1.8.0