From d9cfe061b9b501511f5d769f751c8ff6bbcb1bf9 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 17 八月 2023 15:20:25 +0800
Subject: [PATCH] 优化对讲释放流程

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
index 98c1a96..5526e15 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
@@ -33,7 +33,7 @@
 public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
 
 
-    private Logger logger = LoggerFactory.getLogger(KeepaliveNotifyMessageHandler.class);
+    private final Logger logger = LoggerFactory.getLogger(KeepaliveNotifyMessageHandler.class);
     private final static String cmdType = "Keepalive";
 
     @Autowired
@@ -60,15 +60,22 @@
             return;
         }
         SIPRequest request = (SIPRequest) evt.getRequest();
+        logger.info("[鏀跺埌蹇冭烦]锛� device: {}, callId: {}", device.getDeviceId(), request.getCallIdHeader().getCallId());
+
         // 鍥炲200 OK
         try {
             responseAck(request, Response.OK);
         } catch (SipException | InvalidArgumentException | ParseException e) {
             logger.error("[鍛戒护鍙戦�佸け璐 蹇冭烦鍥炲: {}", e.getMessage());
         }
+        if (device.getKeepaliveTime() != null && DateUtil.getDifferenceForNow(device.getKeepaliveTime()) <= 3000L){
+            logger.info("[鏀跺埌蹇冭烦] 蹇冭烦鍙戦�佽繃浜庨绻侊紝宸插拷鐣� device: {}, callId: {}", device.getDeviceId(), request.getCallIdHeader().getCallId());
+            return;
+        }
 
         RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, userSetting.getSipUseSourceIpAsRemoteAddress());
         if (!device.getIp().equalsIgnoreCase(remoteAddressInfo.getIp()) || device.getPort() != remoteAddressInfo.getPort()) {
+            logger.info("[蹇冭烦] 璁惧{}鍦板潃鍙樺寲, 杩滅▼鍦板潃涓�: {}:{}", device.getDeviceId(), remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
             device.setPort(remoteAddressInfo.getPort());
             device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort())));
             device.setIp(remoteAddressInfo.getIp());
@@ -77,24 +84,26 @@
             device.setKeepaliveIntervalTime(60);
         }else {
             long lastTime = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(device.getKeepaliveTime());
-            device.setKeepaliveIntervalTime(new Long(System.currentTimeMillis()/1000-lastTime).intValue());
+            if (System.currentTimeMillis()/1000-lastTime > 10) {
+                device.setKeepaliveIntervalTime(Long.valueOf(System.currentTimeMillis()/1000-lastTime).intValue());
+            }
         }
 
         device.setKeepaliveTime(DateUtil.getNow());
 
-        if (device.getOnline() == 1) {
+        if (device.isOnLine()) {
             deviceService.updateDevice(device);
         }else {
             // 瀵逛簬宸茬粡绂荤嚎鐨勮澶囧垽鏂粬鐨勬敞鍐屾槸鍚﹀凡缁忚繃鏈�
             if (!deviceService.expire(device)){
-                device.setOnline(0);
-                deviceService.online(device);
+                device.setOnLine(false);
+                deviceService.online(device, null);
             }
         }
         // 鍒锋柊杩囨湡浠诲姟
         String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
         // 濡傛灉涓夋蹇冭烦澶辫触锛屽垯璁剧疆璁惧绂荤嚎
-        dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId()), device.getKeepaliveIntervalTime()*1000*3);
+        dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId(), "涓夋蹇冭烦澶辫触"), device.getKeepaliveIntervalTime()*1000*3);
 
     }
 

--
Gitblit v1.8.0