From 7cb74dbe51bab0457048c27ddc9d7c5a17253e1a Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 26 一月 2022 10:55:36 +0800
Subject: [PATCH] Merge pull request #317 from nikmu/wvp-28181-2.0

---
 src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java |   44 ++++++++++++++++++++++
 src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java          |    2 
 pom.xml                                                                                                     |    4 ++
 src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java       |   24 ++++++++++++
 src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java                                       |   11 +++++
 5 files changed, 84 insertions(+), 1 deletions(-)

diff --git a/pom.xml b/pom.xml
index 991abc6..cf2c4cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -228,6 +228,10 @@
 			<artifactId>spring-boot-starter-test</artifactId>
 <!--			<scope>test</scope>-->
 		</dependency>
+		<dependency>
+			<groupId>org.projectlombok</groupId>
+			<artifactId>lombok</artifactId>
+		</dependency>
 	</dependencies>
 
 
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
index 76b4427..426e2e5 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
@@ -5,6 +5,7 @@
 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
 import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
 import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
+import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent;
 import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
 import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
@@ -67,6 +68,16 @@
 		platformNotRegisterEvent.setPlatformGbID(platformGbId);
         applicationEventPublisher.publishEvent(platformNotRegisterEvent);
 	}
+
+	/**
+	 * 骞冲彴鍛ㄦ湡娉ㄥ唽浜嬩欢
+	 * @param paltformGbId
+	 */
+	public void platformRegisterCycleEventPublish(String paltformGbId) {
+		PlatformCycleRegisterEvent platformCycleRegisterEvent = new PlatformCycleRegisterEvent(this);
+		platformCycleRegisterEvent.setPlatformGbID(paltformGbId);
+		applicationEventPublisher.publishEvent(platformCycleRegisterEvent);
+	}
 	
 	/**
 	 * 璁惧鎶ヨ浜嬩欢
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
index ea322d1..9ba0c05 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
@@ -66,7 +66,7 @@
         }else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) {
             String platformGBId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length());
 
-            publisher.platformNotRegisterEventPublish(platformGBId);
+            publisher.platformRegisterCycleEventPublish(platformGBId);
         }else if (expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){
             String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
             publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX);
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java
new file mode 100644
index 0000000..c2ff61f
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java
@@ -0,0 +1,24 @@
+package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
+
+import org.springframework.context.ApplicationEvent;
+
+public class PlatformCycleRegisterEvent extends ApplicationEvent {
+    /**
+     * Add default serial version ID
+     */
+    private static final long serialVersionUID = 1L;
+
+    private String platformGbID;
+
+    public String getPlatformGbID() {
+        return platformGbID;
+    }
+
+    public void setPlatformGbID(String platformGbID) {
+        this.platformGbID = platformGbID;
+    }
+
+    public PlatformCycleRegisterEvent(Object source) {
+        super(source);
+    }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java
new file mode 100644
index 0000000..996f65d
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java
@@ -0,0 +1,44 @@
+package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
+
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+@Slf4j
+@Component
+public class PlatformCycleRegisterEventLister implements ApplicationListener<PlatformCycleRegisterEvent> {
+    @Autowired
+    private IVideoManagerStorager storager;
+    @Autowired
+    private ISIPCommanderForPlatform sipCommanderFroPlatform;
+
+    @Override
+    public void onApplicationEvent(PlatformCycleRegisterEvent event) {
+        log.info("涓婄骇骞冲彴鍛ㄦ湡娉ㄥ唽浜嬩欢");
+        ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID());
+        if (parentPlatform == null) {
+            log.info("[ 骞冲彴鏈敞鍐屼簨浠� ] 骞冲彴宸茬粡鍒犻櫎!!! 骞冲彴鍥芥爣ID锛�" + event.getPlatformGbID());
+            return;
+        }
+        Timer timer = new Timer();
+        SipSubscribe.Event okEvent = (responseEvent)->{
+            timer.cancel();
+        };
+        sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
+        timer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                log.info("[骞冲彴娉ㄥ唽]鍐嶆鍚戝钩鍙版敞鍐岋紝骞冲彴鍥芥爣ID锛�" + event.getPlatformGbID());
+                sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
+            }
+        }, 15*1000 ,Long.parseLong(parentPlatform.getExpires())* 1000);
+    }
+}

--
Gitblit v1.8.0