From 4f22994cdbf1254005def8bb7639cbfd3fd2b450 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 25 三月 2023 10:04:57 +0800
Subject: [PATCH] 优化国标级联的更新

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java |   52 -----------------
 web_src/src/components/dialog/platformEdit.vue                                        |    6 +-
 src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java                     |    6 ++
 src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java             |   80 +++++++++++++++++++++++++-
 4 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java
index 17f8b37..12a03b4 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java
@@ -26,6 +26,12 @@
     boolean add(ParentPlatform parentPlatform);
 
     /**
+     * 娣诲姞绾ц仈骞冲彴
+     * @param parentPlatform 绾ц仈骞冲彴
+     */
+    boolean update(ParentPlatform parentPlatform);
+
+    /**
      * 骞冲彴涓婄嚎
      * @param parentPlatform 骞冲彴淇℃伅
      */
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
index 136689c..d7d9f6c 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
@@ -11,8 +11,8 @@
 import com.genersoft.iot.vmp.service.IPlatformService;
 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
-import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
+import com.genersoft.iot.vmp.storager.dao.*;
+import com.genersoft.iot.vmp.utils.DateUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import org.slf4j.Logger;
@@ -40,6 +40,15 @@
 
     @Autowired
     private ParentPlatformMapper platformMapper;
+
+    @Autowired
+    private PlatformCatalogMapper catalogMapper;
+
+    @Autowired
+    private PlatformChannelMapper platformChannelMapper;
+
+    @Autowired
+    private PlatformGbStreamMapper platformGbStreamMapper;
 
     @Autowired
     private IRedisCatchStorage redisCatchStorage;
@@ -113,6 +122,69 @@
     }
 
     @Override
+    public boolean update(ParentPlatform parentPlatform) {
+        parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
+        ParentPlatform parentPlatformOld = platformMapper.getParentPlatById(parentPlatform.getId());
+        parentPlatform.setUpdateTime(DateUtil.getNow());
+        if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) {
+            // 鐩綍缁撴瀯鍙戠敓鍙樺寲锛屾竻绌轰箣鍓嶇殑鍏宠仈鍏崇郴
+            logger.info("淇濆瓨骞冲彴{}鏃跺彂鐜扮洰褰曠粨鏋勫彉鍖栵紝娓呯┖鍏宠仈鍏崇郴", parentPlatform.getDeviceGBId());
+            catalogMapper.delByPlatformId(parentPlatformOld.getServerGBId());
+            platformChannelMapper.delByPlatformId(parentPlatformOld.getServerGBId());
+            platformGbStreamMapper.delByPlatformId(parentPlatformOld.getServerGBId());
+        }
+
+        // 鍋滄蹇冭烦瀹氭椂
+        final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatformOld.getServerGBId();
+        dynamicTask.stop(keepaliveTaskKey);
+        // 鍋滄娉ㄥ唽瀹氭椂
+        final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatformOld.getServerGBId();
+        dynamicTask.stop(registerTaskKey);
+        // 娉ㄩ攢鏃х殑
+        try {
+            commanderForPlatform.unregister(parentPlatformOld, null, eventResult -> {
+                logger.info("[鍥芥爣绾ц仈] 娉ㄩ攢鎴愬姛锛� 骞冲彴锛歿}", parentPlatformOld.getServerGBId());
+            });
+        } catch (InvalidArgumentException | ParseException | SipException e) {
+            logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
+        }
+
+        // 鏇存柊鏁版嵁搴�
+        if (parentPlatform.getCatalogGroup() == 0) {
+            parentPlatform.setCatalogGroup(1);
+        }
+        if (parentPlatform.getAdministrativeDivision() == null) {
+            parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
+        }
+
+        platformMapper.updateParentPlatform(parentPlatform);
+        // 鏇存柊redis
+        redisCatchStorage.delPlatformCatchInfo(parentPlatformOld.getServerGBId());
+        ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
+        parentPlatformCatch.setParentPlatform(parentPlatform);
+        parentPlatformCatch.setId(parentPlatform.getServerGBId());
+        redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
+        // 娉ㄥ唽
+        if (parentPlatform.isEnable()) {
+            // 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
+            // 娉ㄥ唽鎴愬姛鏃剁敱绋嬪簭鐩存帴璋冪敤浜唎nline鏂规硶
+            try {
+                commanderForPlatform.register(parentPlatform, eventResult -> {
+                    logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
+                }, null);
+            } catch (InvalidArgumentException | ParseException | SipException e) {
+                logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈: {}", e.getMessage());
+            }
+        }
+        // 閲嶆柊寮�鍚畾鏃舵敞鍐岋紝 浣跨敤缁娑堟伅
+        // 閲嶆柊寮�濮嬪績璺充繚娲�
+
+
+        return false;
+    }
+
+
+    @Override
     public void online(ParentPlatform parentPlatform) {
         logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎/鏇存柊娉ㄥ唽", parentPlatform.getServerGBId());
         platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), true);
@@ -137,7 +209,7 @@
                 ()-> {
                     registerTask(parentPlatform);
                 },
-                (parentPlatform.getExpires() - 10) *1000);
+                (parentPlatform.getExpires()) *1000);
         }
 
 
@@ -183,7 +255,7 @@
                             logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�佸績璺�: {}", e.getMessage());
                         }
                     },
-                    (parentPlatform.getKeepTimeout() - 10)*1000);
+                    (parentPlatform.getKeepTimeout())*1000);
         }
     }
 
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
index 7628f7c..e233d1b 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -205,58 +205,8 @@
         ) {
             throw new ControllerException(ErrorCode.ERROR400);
         }
-        parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
-        ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
-        parentPlatform.setUpdateTime(DateUtil.getNow());
-        if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) {
-             // 鐩綍缁撴瀯鍙戠敓鍙樺寲锛屾竻绌轰箣鍓嶇殑鍏宠仈鍏崇郴
-             logger.info("淇濆瓨骞冲彴{}鏃跺彂鐜扮洰褰曠粨鏋勫彉鍖栵紝娓呯┖鍏宠仈鍏崇郴", parentPlatform.getDeviceGBId());
-             storager.cleanContentForPlatform(parentPlatform.getServerGBId());
 
-        }
-        boolean updateResult = storager.updateParentPlatform(parentPlatform);
-
-        if (updateResult) {
-            // 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
-            if (parentPlatform.isEnable()) {
-                if (parentPlatformOld != null && parentPlatformOld.isStatus()) {
-                    try {
-                        commanderForPlatform.unregister(parentPlatformOld, null, null);
-                    } catch (InvalidArgumentException | ParseException | SipException e) {
-                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
-                    }
-                    try {
-                        Thread.sleep(500);
-                    } catch (InterruptedException e) {
-                        logger.error("[绾跨▼浼戠湢澶辫触] : {}", e.getMessage());
-                    }
-                    //  鍙淇濆瓨灏卞彂閫佹敞鍐�
-                    try {
-                        commanderForPlatform.register(parentPlatform, null, null);
-                    } catch (InvalidArgumentException | ParseException | SipException e) {
-                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄥ唽: {}", e.getMessage());
-                    }
-
-                } else {
-                    //  鍙淇濆瓨灏卞彂閫佹敞鍐�
-                    try {
-                        commanderForPlatform.register(parentPlatform, null, null);
-                    } catch (InvalidArgumentException | ParseException | SipException e) {
-                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄥ唽: {}", e.getMessage());
-                    }
-                }
-            } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 鍏抽棴鍚敤鏃舵敞閿�
-                try {
-                    commanderForPlatform.unregister(parentPlatformOld, null, null);
-                } catch (InvalidArgumentException | ParseException | SipException e) {
-                    logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
-                }
-                // 鍋滄璁㈤槄鐩稿叧鐨勫畾鏃朵换鍔�
-                subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
-            }
-        } else {
-            throw new ControllerException(ErrorCode.ERROR100.getCode(),"鍐欏叆鏁版嵁搴撳け璐�");
-        }
+        platformService.update(parentPlatform);
     }
 
     /**
diff --git a/web_src/src/components/dialog/platformEdit.vue b/web_src/src/components/dialog/platformEdit.vue
index 2a41e6a..be7c505 100644
--- a/web_src/src/components/dialog/platformEdit.vue
+++ b/web_src/src/components/dialog/platformEdit.vue
@@ -157,7 +157,7 @@
         devicePort: null,
         username: null,
         password: null,
-        expires: 300,
+        expires: 3600,
         keepTimeout: 60,
         transport: "UDP",
         characterSet: "GB2312",
@@ -305,7 +305,7 @@
         devicePort: null,
         username: null,
         password: null,
-        expires: 300,
+        expires: 3600,
         keepTimeout: 60,
         transport: "UDP",
         characterSet: "GB2312",
@@ -332,7 +332,7 @@
     },
     checkExpires: function() {
       if (this.platform.enable && this.platform.expires === "0") {
-        this.platform.expires = "300";
+        this.platform.expires = "3600";
       }
     },
     rtcpCheckBoxChange: function (result){

--
Gitblit v1.8.0