From 1d753b48c023090430c2931fd8e3a45a382eddf8 Mon Sep 17 00:00:00 2001
From: hotcoffie <35990065+hotcoffie@users.noreply.github.com>
Date: 星期二, 17 五月 2022 11:53:42 +0800
Subject: [PATCH] Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java |   60 +++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 31 insertions(+), 29 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 08a7751..d5d4c1d 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
@@ -1,14 +1,15 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
 
-import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
 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;
+import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import com.genersoft.iot.vmp.utils.DateUtil;
 import org.dom4j.Element;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,19 +29,13 @@
 public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
 
     private Logger logger = LoggerFactory.getLogger(KeepaliveNotifyMessageHandler.class);
-    private final String cmdType = "Keepalive";
+    private final static String cmdType = "Keepalive";
 
     @Autowired
     private NotifyMessageHandler notifyMessageHandler;
 
     @Autowired
-    private EventPublisher publisher;
-
-    @Autowired
-    private IVideoManagerStorage videoManagerStorager;
-
-    @Autowired
-    private IRedisCatchStorage redisCatchStorage;
+    private IDeviceService deviceService;
 
     @Override
     public void afterPropertiesSet() throws Exception {
@@ -49,29 +44,36 @@
 
     @Override
     public void handForDevice(RequestEvent evt, Device device, Element element) {
-        // 妫�鏌ヨ澶囨槸鍚﹀瓨鍦ㄥ苟鍦ㄧ嚎锛� 涓嶅湪绾垮垯璁剧疆涓哄湪绾�
+        if (device == null) {
+            // 鏈敞鍐岀殑璁惧涓嶅仛澶勭悊
+            return;
+        }
         try {
-            if (device != null ) {
+            if (device.getOnline() == 1) {
                 // 鍥炲200 OK
                 responseAck(evt, Response.OK);
-                // 鍒ゆ柇RPort鏄惁鏀瑰彉锛屾敼鍙樺垯璇存槑璺敱nat淇℃伅鍙樺寲锛屼慨鏀硅澶囦俊鎭�
-                // 鑾峰彇鍒伴�氫俊鍦板潃绛変俊鎭�
-                ViaHeader viaHeader = (ViaHeader) evt.getRequest().getHeader(ViaHeader.NAME);
-                String received = viaHeader.getReceived();
-                int rPort = viaHeader.getRPort();
-                // 瑙f瀽鏈湴鍦板潃鏇夸唬
-                if (StringUtils.isEmpty(received) || rPort == -1) {
-                    received = viaHeader.getHost();
-                    rPort = viaHeader.getPort();
-                }
-                if (device.getPort() != rPort) {
-                    device.setPort(rPort);
-                    device.setHostAddress(received.concat(":").concat(String.valueOf(rPort)));
-                    videoManagerStorager.updateDevice(device);
-                    redisCatchStorage.updateDevice(device);
-                }
-                if (!redisCatchStorage.deviceIsOnline(device.getDeviceId())) {
-                    publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
+            }else {
+                // 瀵逛簬宸茬粡绂荤嚎鐨勮澶囧垽鏂粬鐨勬敞鍐屾槸鍚﹀凡缁忚繃鏈�
+                if (!deviceService.expire(device)){
+                    device.setKeepaliveTime(DateUtil.getNow());
+                    // 鍒ゆ柇RPort鏄惁鏀瑰彉锛屾敼鍙樺垯璇存槑璺敱nat淇℃伅鍙樺寲锛屼慨鏀硅澶囦俊鎭�
+                    // 鑾峰彇鍒伴�氫俊鍦板潃绛変俊鎭�
+                    ViaHeader viaHeader = (ViaHeader) evt.getRequest().getHeader(ViaHeader.NAME);
+                    String received = viaHeader.getReceived();
+                    int rPort = viaHeader.getRPort();
+                    // 瑙f瀽鏈湴鍦板潃鏇夸唬
+                    if (StringUtils.isEmpty(received) || rPort == -1) {
+                        received = viaHeader.getHost();
+                        rPort = viaHeader.getPort();
+                    }
+                    if (device.getPort() != rPort) {
+                        device.setPort(rPort);
+                        device.setHostAddress(received.concat(":").concat(String.valueOf(rPort)));
+                    }
+                    device.setKeepaliveTime(DateUtil.getNow());
+                    deviceService.online(device);
+                    // 鍥炲200 OK
+                    responseAck(evt, Response.OK);
                 }
             }
         } catch (SipException e) {

--
Gitblit v1.8.0