From 7de353fa99cfe82101c434b5d080f6a5a1945aac Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 12 四月 2024 10:24:06 +0800
Subject: [PATCH] 提交部分备份

---
 ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java |  251 ++++++++++++++++++++++++++------------------------
 1 files changed, 131 insertions(+), 120 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java b/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java
index 4ffb4d8..e7ce57e 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java
@@ -86,145 +86,156 @@
      * @return
      */
     @Override
-
-    public boolean login(ArdCameras camera) {
-        LoginModule.init(disConnect, haveReConnect);
-        NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
-        NetSDKLib.LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), m_stDeviceInfo);
-        if (loginId.longValue() <= 0) {
-            camera.setChanNum(0);
-            camera.setLoginId(-1);
-            camera.setState("0");
-            ardCamerasService.updateArdCameras(camera);
+    public AjaxResult login(ArdCameras camera) {
+        try {
+            LoginModule.init(disConnect, haveReConnect);
+            NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
+            NetSDKLib.LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), m_stDeviceInfo);
+            if (loginId.longValue() <= 0) {
+                camera.setChanNum(0);
+                camera.setLoginId(-1);
+                camera.setState("0");
+                ardCamerasService.updateArdCameras(camera);
+                //鍒犻櫎绠$悊閫氶亾
+                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
+                log.error("璁惧[" + camera.getIp() + ":" + camera.getPort() + "]鐧诲綍澶辫触:" + getErrorCodePrint());
+                return AjaxResult.error(ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()));
+            }
+            if (GlobalVariable.loginMap.containsKey(camera.getId())) {
+                GlobalVariable.loginMap.remove(camera.getId());
+            }
             //鍒犻櫎绠$悊閫氶亾
             ardChannelService.deleteArdChannelByDeviceId(camera.getId());
-            return false;
-        }
-        if (GlobalVariable.loginMap.containsKey(camera.getId())) {
-            GlobalVariable.loginMap.remove(camera.getId());
-        }
-        //鍒犻櫎绠$悊閫氶亾
-        ardChannelService.deleteArdChannelByDeviceId(camera.getId());
-        camera.setState("1");
-        camera.setChanNum(m_stDeviceInfo.byChanNum);
-        camera.setStartDChan(1);
-        camera.setLoginId((int) loginId.longValue());
-        ardCamerasService.updateArdCameras(camera);
-        GlobalVariable.loginMap.put(camera.getId(), loginId);
+            camera.setState("1");
+            camera.setChanNum(m_stDeviceInfo.byChanNum);
+            camera.setStartDChan(1);
+            camera.setLoginId((int) loginId.longValue());
+            ardCamerasService.updateArdCameras(camera);
+            GlobalVariable.loginMap.put(camera.getId(), loginId);
 
-        //鑾峰彇鏈�鏂伴�氶亾
-        for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
-            ArdChannel channel = new ArdChannel();
-            NetSDKLib.AV_CFG_ChannelName av_cfg_channelName = new NetSDKLib.AV_CFG_ChannelName();
-            boolean b = ConfigModule.GetNewDevConfig(loginId, i - 1, CFG_CMD_CHANNELTITLE, av_cfg_channelName);
-            if (b) {
-                String chanName = null;
-                try {
-                    chanName = new String(av_cfg_channelName.szName, "GBK").trim();
-                } catch (UnsupportedEncodingException e) {
-                    e.printStackTrace();
-                }
-                channel.setName(chanName);
-            } else {
-                channel.setName("閫氶亾" + i);
-            }
-            channel.setDeviceId(camera.getId());
-            channel.setChanNo(i);
-            ardChannelService.insertArdChannel(channel);
-        }
-        //閰嶇疆鍒版祦濯掍綋
-        for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
-            String name = camera.getId() + "_" + i;
-            String rtspSource = "rtsp://" + camera.getUsername() + ":" + camera.getPassword() + "@" + camera.getIp() + ":" + camera.getRtspPort() + "/cam/realmonitor?channel=" + i + "&subtype=0";
-            Vtdu vtdu = vtduService.selectVtduByName(name);
-            if (vtdu != null) {
-                vtduService.deleteVtduByName(name);
-            }
-            //娣诲姞鍒版祦濯掍綋
-            CameraCmd cmd = new CameraCmd(camera.getId(), i);
-            Map<String, Object> videoCompressionCfg = getVideoCompressionCfg(cmd);
-            vtdu = new Vtdu();
-            if (videoCompressionCfg.get("videoEncType") != null) {
-                if (videoCompressionCfg.get("videoEncType").equals("鏍囧噯h264")) {
-                    vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
+            //鑾峰彇鏈�鏂伴�氶亾
+            for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
+                ArdChannel channel = new ArdChannel();
+                NetSDKLib.AV_CFG_ChannelName av_cfg_channelName = new NetSDKLib.AV_CFG_ChannelName();
+                boolean b = ConfigModule.GetNewDevConfig(loginId, i - 1, CFG_CMD_CHANNELTITLE, av_cfg_channelName);
+                if (b) {
+                    String chanName = null;
+                    try {
+                        chanName = new String(av_cfg_channelName.szName, "GBK").trim();
+                    } catch (UnsupportedEncodingException e) {
+                        e.printStackTrace();
+                    }
+                    channel.setName(chanName);
                 } else {
-                    vtdu.setIsCode("1");//榛樿杞爜
+                    channel.setName("閫氶亾" + i);
                 }
-            } else {
-                vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
+                channel.setDeviceId(camera.getId());
+                channel.setChanNo(i);
+                ardChannelService.insertArdChannel(channel);
             }
-            vtdu.setRtspSource(rtspSource);
-            vtdu.setName(camera.getId() + "_" + i);
-            vtdu.setMode("1");//榛樿CPU杞В鐮�
-            vtdu.setCameraId(camera.getId());
-            vtduService.insertVtdu(vtdu);
-        }
+            //閰嶇疆鍒版祦濯掍綋
+            for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
+                String name = camera.getId() + "_" + i;
+                String rtspSource = "rtsp://" + camera.getUsername() + ":" + camera.getPassword() + "@" + camera.getIp() + ":" + camera.getRtspPort() + "/cam/realmonitor?channel=" + i + "&subtype=0";
+                Vtdu vtdu = vtduService.selectVtduByName(name);
+                if (vtdu != null) {
+                    vtduService.deleteVtduByName(name);
+                }
+                //娣诲姞鍒版祦濯掍綋
+                CameraCmd cmd = new CameraCmd(camera.getId(), i);
+                Map<String, Object> videoCompressionCfg = getVideoCompressionCfg(cmd);
+                vtdu = new Vtdu();
+                if (videoCompressionCfg.get("videoEncType") != null) {
+                    if (videoCompressionCfg.get("videoEncType").equals("鏍囧噯h264")) {
+                        vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
+                    } else {
+                        vtdu.setIsCode("1");//榛樿杞爜
+                    }
+                } else {
+                    vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
+                }
+                vtdu.setRtspSource(rtspSource);
+                vtdu.setName(camera.getId() + "_" + i);
+                vtdu.setMode("1");//榛樿CPU杞В鐮�
+                vtdu.setCameraId(camera.getId());
+                vtduService.insertVtdu(vtdu);
+            }
 
-        //鍒涘缓寮曞闃熷垪
-        //鍒涘缓寮曞闃熷垪
-        if (camera.getCamAlarmGuideEnable() == 1) {
-            if (!GuidePriorityQueue.cameraQueueMap.containsKey(camera.getId())) {
-                Comparator<GuideTask> comparator = GuidePriorityQueue.getComparator();
-                PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000, comparator);
-                GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue);
+            //鍒涘缓寮曞闃熷垪
+            if (camera.getCamAlarmGuideEnable() != null && camera.getCamAlarmGuideEnable() == 1) {
+                if (!GuidePriorityQueue.cameraQueueMap.containsKey(camera.getId())) {
+                    Comparator<GuideTask> comparator = GuidePriorityQueue.getComparator();
+                    PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000, comparator);
+                    GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue);
+                }
+                //鍚姩闃熷垪澶勭悊鍣�
+                queueHandler.process(camera.getId());
             }
-            //鍚姩闃熷垪澶勭悊鍣�
-            queueHandler.process(camera.getId());
+            return AjaxResult.success("璁惧鐧诲綍鎴愬姛");
+        } catch (Exception ex) {
+            log.error("璁惧鐧诲綍寮傚父:" + ex.getMessage());
+            return AjaxResult.error("璁惧鐧诲綍寮傚父:" + ex.getMessage());
         }
-        return true;
     }
 
     @Override
     @Async("loginExecutor")
-    public void asyncLogin(ArdCameras camera) {
-        LoginModule.init(disConnect, haveReConnect);
-        NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
-        NetSDKLib.LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), m_stDeviceInfo);
-        if (loginId.longValue() <= 0) {
-            camera.setChanNum(0);
-            camera.setLoginId(-1);
-            camera.setState("0");
-            ardCamerasService.updateArdCameras(camera);
+    public AjaxResult asyncLogin(ArdCameras camera) {
+        try {
+            LoginModule.init(disConnect, haveReConnect);
+            NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
+            NetSDKLib.LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), m_stDeviceInfo);
+            if (loginId.longValue() <= 0) {
+                camera.setChanNum(0);
+                camera.setLoginId(-1);
+                camera.setState("0");
+                ardCamerasService.updateArdCameras(camera);
+                //鍒犻櫎绠$悊閫氶亾
+                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
+                log.error("璁惧[" + camera.getIp() + ":" + camera.getPort() + "]鐧诲綍澶辫触:" + getErrorCodePrint());
+                return AjaxResult.error(ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()));
+            }
+            if (GlobalVariable.loginMap.containsKey(camera.getId())) {
+                GlobalVariable.loginMap.remove(camera.getId());
+            }
             //鍒犻櫎绠$悊閫氶亾
             ardChannelService.deleteArdChannelByDeviceId(camera.getId());
-            return;
-        }
-        if (GlobalVariable.loginMap.containsKey(camera.getId())) {
-            GlobalVariable.loginMap.remove(camera.getId());
-        }
-        //鍒犻櫎绠$悊閫氶亾
-        ardChannelService.deleteArdChannelByDeviceId(camera.getId());
-        camera.setState("1");
-        camera.setChanNum(m_stDeviceInfo.byChanNum);
-        camera.setStartDChan(1);
-        camera.setLoginId((int) loginId.longValue());
-        ardCamerasService.updateArdCameras(camera);
-        GlobalVariable.loginMap.put(camera.getId(), loginId);
+            camera.setState("1");
+            camera.setChanNum(m_stDeviceInfo.byChanNum);
+            camera.setStartDChan(1);
+            camera.setLoginId((int) loginId.longValue());
+            ardCamerasService.updateArdCameras(camera);
+            GlobalVariable.loginMap.put(camera.getId(), loginId);
 
-        //鑾峰彇鏈�鏂伴�氶亾
-        for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
-            ArdChannel channel = new ArdChannel();
-            NetSDKLib.AV_CFG_ChannelName av_cfg_channelName = new NetSDKLib.AV_CFG_ChannelName();
-            boolean b = ConfigModule.GetNewDevConfig(loginId, i - 1, CFG_CMD_CHANNELTITLE, av_cfg_channelName);
-            if (b) {
-                String chanName = null;
-                try {
-                    chanName = new String(av_cfg_channelName.szName, "GBK").trim();
-                } catch (UnsupportedEncodingException e) {
-                    e.printStackTrace();
+            //鑾峰彇鏈�鏂伴�氶亾
+            for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
+                ArdChannel channel = new ArdChannel();
+                NetSDKLib.AV_CFG_ChannelName av_cfg_channelName = new NetSDKLib.AV_CFG_ChannelName();
+                boolean b = ConfigModule.GetNewDevConfig(loginId, i - 1, CFG_CMD_CHANNELTITLE, av_cfg_channelName);
+                if (b) {
+                    String chanName = null;
+                    try {
+                        chanName = new String(av_cfg_channelName.szName, "GBK").trim();
+                    } catch (UnsupportedEncodingException e) {
+                        e.printStackTrace();
+                    }
+                    channel.setName(chanName);
+                } else {
+                    channel.setName("閫氶亾" + i);
                 }
-                channel.setName(chanName);
-            } else {
-                channel.setName("閫氶亾" + i);
+                channel.setDeviceId(camera.getId());
+                channel.setChanNo(i);
+                ardChannelService.insertArdChannel(channel);
             }
-            channel.setDeviceId(camera.getId());
-            channel.setChanNo(i);
-            ardChannelService.insertArdChannel(channel);
+            //閰嶇疆鍒版祦濯掍綋
+            addVtdu(camera);
+            //鍒涘缓寮曞闃熷垪
+            createGuideQueue(camera);
+            return AjaxResult.success("鐧诲綍鎴愬姛");
+        } catch (Exception ex) {
+            log.error("鐧诲綍寮傚父:" + ex.getMessage());
+            return AjaxResult.error("鐧诲綍寮傚父:" + ex.getMessage());
         }
-        //閰嶇疆鍒版祦濯掍綋
-        addVtdu(camera);
-        //鍒涘缓寮曞闃熷垪
-        createGuideQueue(camera);
     }
 
     //娣诲姞鍒版祦濯掍綋

--
Gitblit v1.9.3