From c3ce2bc5d069ba57309567aee4ae418bc0cf75ed Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 17 三月 2023 13:22:05 +0800
Subject: [PATCH] 优化异常处理以及级联设备状态查询

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java |   99 +++++++++++++++++++++++++++++++++++--------------
 1 files changed, 71 insertions(+), 28 deletions(-)

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 bf42189..7628f7c 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
@@ -1,7 +1,7 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.platform;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.conf.DynamicTask;
 import com.genersoft.iot.vmp.conf.UserSetting;
@@ -10,8 +10,7 @@
 import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
 import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
-import com.genersoft.iot.vmp.service.IPlatformChannelService;
-import com.genersoft.iot.vmp.service.IPlatformService;
+import com.genersoft.iot.vmp.service.*;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.utils.DateUtil;
@@ -29,13 +28,16 @@
 import org.springframework.web.bind.annotation.*;
 import com.genersoft.iot.vmp.conf.SipConfig;
 
+import javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
+import java.text.ParseException;
 import java.util.List;
 
 /**
  * 绾ц仈骞冲彴绠$悊
  */
 @Tag(name  = "绾ц仈骞冲彴绠$悊")
-@CrossOrigin
+
 @RestController
 @RequestMapping("/api/platform")
 public class PlatformController {
@@ -68,6 +70,12 @@
 
 	@Autowired
 	private IPlatformService platformService;
+
+	@Autowired
+	private IDeviceChannelService deviceChannelService;
+
+	@Autowired
+	private IGbStreamService gbStreamService;
 
     /**
      * 鑾峰彇鍥芥爣鏈嶅姟鐨勯厤缃�
@@ -212,20 +220,37 @@
             // 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
             if (parentPlatform.isEnable()) {
                 if (parentPlatformOld != null && parentPlatformOld.isStatus()) {
-                    commanderForPlatform.unregister(parentPlatformOld, null, null);
+                    try {
+                        commanderForPlatform.unregister(parentPlatformOld, null, null);
+                    } catch (InvalidArgumentException | ParseException | SipException e) {
+                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
+                    }
                     try {
                         Thread.sleep(500);
                     } catch (InterruptedException e) {
-                        e.printStackTrace();
+                        logger.error("[绾跨▼浼戠湢澶辫触] : {}", e.getMessage());
                     }
                     //  鍙淇濆瓨灏卞彂閫佹敞鍐�
-                    commanderForPlatform.register(parentPlatform, null, null);
+                    try {
+                        commanderForPlatform.register(parentPlatform, null, null);
+                    } catch (InvalidArgumentException | ParseException | SipException e) {
+                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄥ唽: {}", e.getMessage());
+                    }
+
                 } else {
                     //  鍙淇濆瓨灏卞彂閫佹敞鍐�
-                    commanderForPlatform.register(parentPlatform, null, null);
+                    try {
+                        commanderForPlatform.register(parentPlatform, null, null);
+                    } catch (InvalidArgumentException | ParseException | SipException e) {
+                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄥ唽: {}", e.getMessage());
+                    }
                 }
             } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 鍏抽棴鍚敤鏃舵敞閿�
-                commanderForPlatform.unregister(parentPlatformOld, null, null);
+                try {
+                    commanderForPlatform.unregister(parentPlatformOld, null, null);
+                } catch (InvalidArgumentException | ParseException | SipException e) {
+                    logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
+                }
                 // 鍋滄璁㈤槄鐩稿叧鐨勫畾鏃朵换鍔�
                 subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
             }
@@ -244,7 +269,7 @@
     @Parameter(name = "serverGBId", description = "涓婄骇骞冲彴鐨勫浗鏍囩紪鍙�")
     @DeleteMapping("/delete/{serverGBId}")
     @ResponseBody
-    public String deletePlatform(@PathVariable String serverGBId) {
+    public void deletePlatform(@PathVariable String serverGBId) {
 
         if (logger.isDebugEnabled()) {
             logger.debug("鍒犻櫎涓婄骇骞冲彴API璋冪敤");
@@ -258,17 +283,21 @@
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "骞冲彴涓嶅瓨鍦�");
         }
         // 鍙戦�佺绾挎秷鎭�,鏃犺鏄惁鎴愬姛閮藉垹闄ょ紦瀛�
-        commanderForPlatform.unregister(parentPlatform, (event -> {
-            // 娓呯┖redis缂撳瓨
-            redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
-            redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
-            redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
-        }), (event -> {
-            // 娓呯┖redis缂撳瓨
-            redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
-            redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
-            redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
-        }));
+        try {
+            commanderForPlatform.unregister(parentPlatform, (event -> {
+                // 娓呯┖redis缂撳瓨
+                redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
+                redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
+                redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
+            }), (event -> {
+                // 娓呯┖redis缂撳瓨
+                redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
+                redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
+                redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
+            }));
+        } catch (InvalidArgumentException | ParseException | SipException e) {
+            logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
+        }
 
         boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
         storager.delCatalogByPlatformId(parentPlatform.getServerGBId());
@@ -278,9 +307,7 @@
         dynamicTask.stop(key);
         // 鍒犻櫎缂撳瓨鐨勮闃呬俊鎭�
         subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
-        if (deleteResult) {
-            return null;
-        } else {
+        if (!deleteResult) {
             throw new ControllerException(ErrorCode.ERROR100);
         }
     }
@@ -357,7 +384,16 @@
         if (logger.isDebugEnabled()) {
             logger.debug("缁欎笂绾у钩鍙版坊鍔犲浗鏍囬�氶亾API璋冪敤");
         }
-        int result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
+        int result = 0;
+        if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) {
+            if (param.isAll()) {
+                logger.info("[鍥芥爣绾ц仈]娣诲姞鎵�鏈夐�氶亾鍒颁笂绾у钩鍙帮紝 {}", param.getPlatformId());
+                List<ChannelReduce> allChannelForDevice = deviceChannelService.queryAllChannelList(param.getPlatformId());
+                result = platformChannelService.updateChannelForGB(param.getPlatformId(), allChannelForDevice, param.getCatalogId());
+            }
+        }else {
+            result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
+        }
         if (result <= 0) {
             throw new ControllerException(ErrorCode.ERROR100);
         }
@@ -377,8 +413,15 @@
         if (logger.isDebugEnabled()) {
             logger.debug("缁欎笂绾у钩鍙板垹闄ゅ浗鏍囬�氶亾API璋冪敤");
         }
-        int result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
-
+        int result = 0;
+        if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) {
+            if (param.isAll()) {
+                logger.info("[鍥芥爣绾ц仈]绉婚櫎鎵�鏈夐�氶亾锛屼笂绾у钩鍙帮紝 {}", param.getPlatformId());
+                result = platformChannelService.delAllChannelForGB(param.getPlatformId(), param.getCatalogId());
+            }
+        }else {
+            result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
+        }
         if (result <= 0) {
             throw new ControllerException(ErrorCode.ERROR100);
         }

--
Gitblit v1.8.0