From 0ac27b03ffd13370e2beec83ce7cb394091ae889 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 12 六月 2024 11:10:10 +0800
Subject: [PATCH] 增加设备上线判断双逻辑,兼容大华注册后不再发送注册的设备

---
 src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java                                                                     |   10 ++++++++++
 src/main/resources/all-application.yml                                                                                        |    4 ++++
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java |   12 ++++++++----
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
index 96253d6..cce9145 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
@@ -74,6 +74,8 @@
 
     private boolean registerKeepIntDialog = false;
 
+    private int gbDeviceOnline = 0;
+
     public Boolean getSavePositionHistory() {
         return savePositionHistory;
     }
@@ -325,4 +327,12 @@
     public void setDocEnable(Boolean docEnable) {
         this.docEnable = docEnable;
     }
+
+    public int getGbDeviceOnline() {
+        return gbDeviceOnline;
+    }
+
+    public void setGbDeviceOnline(int gbDeviceOnline) {
+        this.gbDeviceOnline = gbDeviceOnline;
+    }
 }
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 034e24f..bfc42f5 100755
--- 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
@@ -62,7 +62,10 @@
         }
         SIPRequest request = (SIPRequest) evt.getRequest();
         logger.info("[鏀跺埌蹇冭烦] device: {}, callId: {}", device.getDeviceId(), request.getCallIdHeader().getCallId());
-
+        if (userSetting.getGbDeviceOnline() == 0 && !device.isOnLine()) {
+            logger.warn("[鏀跺埌蹇冭烦] 璁惧绂荤嚎锛屽績璺充笉杩涜鍥炲锛� device: {}, callId: {}", device.getDeviceId(), request.getCallIdHeader().getCallId());
+            return;
+        }
         // 鍥炲200 OK
         try {
             responseAck(request, Response.OK);
@@ -101,9 +104,10 @@
         if (device.isOnLine()) {
             deviceService.updateDevice(device);
         }else {
-            // 瀵逛簬宸茬粡绂荤嚎鐨勮澶囧垽鏂粬鐨勬敞鍐屾槸鍚﹀凡缁忚繃鏈�
-            if (!deviceService.expire(device)){
-                device.setOnLine(false);
+            if (userSetting.getGbDeviceOnline() == 1) {
+                // 瀵逛簬宸茬粡绂荤嚎鐨勮澶囧垽鏂粬鐨勬敞鍐屾槸鍚﹀凡缁忚繃鏈�
+                device.setOnLine(true);
+                device.setRegisterTime(DateUtil.getNow());
                 deviceService.online(device, null);
             }
         }
diff --git a/src/main/resources/all-application.yml b/src/main/resources/all-application.yml
index f2fd504..ef5b244 100644
--- a/src/main/resources/all-application.yml
+++ b/src/main/resources/all-application.yml
@@ -247,6 +247,10 @@
     allowed-origins:
         - http://localhost:8008
         - http://192.168.1.3:8008
+    # 鍥芥爣璁惧绂荤嚎鍚庣殑涓婄嚎绛栫暐锛�
+    # 0锛� 鍥芥爣鏍囧噯瀹炵幇锛岃澶囩绾垮悗涓嶅洖澶嶅績璺筹紝鐭ラ亾璁惧閲嶆柊娉ㄥ唽涓婄嚎锛�
+    # 1锛� 瀵逛簬绂荤嚎璁惧锛屾敹鍒板績璺冲氨鎶婅澶囪缃负涓婄嚎锛屽苟鏇存柊娉ㄥ唽鏃堕棿涓轰笂娆¤繖娆″績璺崇殑鏃堕棿銆傞槻姝㈣繃鏈熸椂闂村垽鏂璾寮傚父
+    gb-device-online: 0
 
 # 鍏抽棴鍦ㄧ嚎鏂囨。锛堢敓浜х幆澧冨缓璁叧闂級
 springdoc:

--
Gitblit v1.8.0