From cd538c205628f28839323b49b7f77f33196a601f Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期四, 11 七月 2024 15:50:42 +0800
Subject: [PATCH] 电磁锁操控加入判断速度为0提交

---
 ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java |  109 +++++++++++++++++++++++++++---------------------------
 1 files changed, 55 insertions(+), 54 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 5f1695a..3957ce6 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
@@ -4,7 +4,10 @@
 import com.ruoyi.alarm.global.domain.GuideTask;
 import com.ruoyi.alarm.global.service.impl.QueueHandler;
 import com.ruoyi.common.annotation.SdkOperate;
+import com.ruoyi.common.config.ARDConfig;
+import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.common.utils.file.MimeTypeUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
@@ -13,6 +16,7 @@
 import com.ruoyi.device.camera.domain.ArdCameras;
 import com.ruoyi.device.camera.domain.CameraCmd;
 import com.ruoyi.device.camera.service.IArdCamerasService;
+import com.ruoyi.device.camera.service.ICameraSdkService;
 import com.ruoyi.device.channel.domain.ArdChannel;
 import com.ruoyi.device.channel.service.IArdChannelService;
 import com.ruoyi.media.domain.Vtdu;
@@ -71,6 +75,9 @@
     private IArdChannelService ardChannelService;
     @Resource
     private IVtduService vtduService;
+
+    @Resource
+    ICameraSdkService cameraSdkService;
     @Value("${minio.endpoint}")
     private String minioEndPoint;
     @Resource
@@ -105,9 +112,7 @@
                 log.error("璁惧[" + camera.getIp() + ":" + camera.getPort() + "]鐧诲綍澶辫触:" + getErrorCodePrint());
                 return AjaxResult.warn(ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()));
             }
-//            if (GlobalVariable.loginMap.containsKey(camera.getId())) {
-//                GlobalVariable.loginMap.remove(camera.getId());
-//            }
+
             camera.setState("1");
             camera.setChanNum(m_stDeviceInfo.byChanNum);
             camera.setStartDChan(1);
@@ -116,7 +121,12 @@
             //鑾峰彇鏈�鏂伴�氶亾
             List<ArdChannel> ardChannelList = getChannels(camera);
             if (ardChannelList.size() > 0) {
+                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
+                ardChannelList.stream().forEach(channel -> {
+                    ardChannelService.insertArdChannel(channel);
+                });
                 camera.setChanNum(ardChannelList.size());
+                camera.setChannelList(ardChannelList);
                 ardCamerasService.updateArdCameras(camera);
                 //閰嶇疆鍒版祦濯掍綋
                 addVtdu(camera);
@@ -147,9 +157,6 @@
                 log.error("璁惧[" + camera.getIp() + ":" + camera.getPort() + "]鐧诲綍澶辫触:" + getErrorCodePrint());
                 return AjaxResult.warn(getErrorCodePrint());
             }
-//            if (GlobalVariable.loginMap.containsKey(camera.getId())) {
-//                GlobalVariable.loginMap.remove(camera.getId());
-//            }
             camera.setState("1");
             camera.setChanNum(m_stDeviceInfo.byChanNum);
             camera.setStartDChan(1);
@@ -160,7 +167,12 @@
             //鑾峰彇鏈�鏂伴�氶亾
             List<ArdChannel> ardChannelList = getChannels(camera);
             if (ardChannelList.size() > 0) {
+                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
+                ardChannelList.stream().forEach(channel -> {
+                    ardChannelService.insertArdChannel(channel);
+                });
                 camera.setChanNum(ardChannelList.size());
+                camera.setChannelList(ardChannelList);
                 ardCamerasService.updateArdCameras(camera);
                 //閰嶇疆鍒版祦濯掍綋
                 addVtdu(camera);
@@ -176,17 +188,17 @@
 
     //娣诲姞鍒版祦濯掍綋
     private void addVtdu(ArdCameras camera) {
-        for (int i = 1; i < camera.getChanNum() + 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) {
+        camera.getChannelList().stream().forEach(channel -> {
+            String name = camera.getId() + "_" + channel.getChanNo();
+            String rtspSource = "rtsp://" + camera.getUsername() + ":" + camera.getPassword() + "@" + camera.getIp() + ":" + camera.getRtspPort() + "/cam/realmonitor?channel=" + channel.getChanNo() + "&subtype=0";
+             //鍒犻櫎娴佸獟浣�
+            if (vtduService.selectVtduByName(name) != null) {
                 vtduService.deleteVtduByName(name);
             }
             //娣诲姞鍒版祦濯掍綋
-            CameraCmd cmd = new CameraCmd(camera.getId(), i);
+            CameraCmd cmd = new CameraCmd(camera.getId(), channel.getChanNo());
             Map<String, Object> videoCompressionCfg = getVideoCompressionCfg(cmd);
-            vtdu = new Vtdu();
+            Vtdu vtdu = new Vtdu();
             if (videoCompressionCfg.get("videoEncType") != null) {
                 if (videoCompressionCfg.get("videoEncType").equals("鏍囧噯h264")) {
                     vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
@@ -197,11 +209,11 @@
                 vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
             }
             vtdu.setRtspSource(rtspSource);
-            vtdu.setName(camera.getId() + "_" + i);
+            vtdu.setName(name);
             vtdu.setMode("1");//榛樿CPU杞В鐮�
             vtdu.setCameraId(camera.getId());
             vtduService.insertVtdu(vtdu);
-        }
+        });
     }
 
     //鍒涘缓寮曞闃熷垪
@@ -219,23 +231,12 @@
 
     //鑾峰彇閫氶亾
     public List<ArdChannel> getChannels(ArdCameras camera) {
-        ardChannelService.deleteArdChannelByDeviceId(camera.getId());
         LLong loginId = new LLong(camera.getLoginId());
         List<ArdChannel> ardChannelList = new ArrayList<>();
         for (int i = 1; i < camera.getChanNum() + 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) {
-                log.error("鑾峰彇閰嶇疆澶辫触,璇风◢鍚庨噸璇�" + getErrorCodePrint());
-                // return AjaxResult.warn(ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()));
-            }
-            String chanName = "";
-            try {
-                chanName = new String(av_cfg_channelName.szName, "GBK").trim();
-            } catch (UnsupportedEncodingException e) {
-                e.printStackTrace();
-            }
+            String chanName = ConfigModule.getChannelName(loginId, i - 1).trim();
+            log.debug("鑾峰彇閫氶亾鍚嶇О锛�" + chanName);
             channel.setName(chanName.equals("") ? "閫氶亾" + i : chanName);
             channel.setDeviceId(camera.getId());
             channel.setChanNo(i);
@@ -246,7 +247,6 @@
                 }
             }
             ardChannelList.add(channel);
-            ardChannelService.insertArdChannel(channel);
         }
         return ardChannelList;
     }
@@ -527,7 +527,9 @@
                 return AjaxResult.warn("璁惧鏈櫥褰�");
             }
             LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId);
-            String imagePath = FileUtils.createFile("D:/LocalCaptureTemp/" + cameraId + ".jpeg");
+            // 鏈湴涓存椂褰曞儚鍦板潃
+            String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+            String imagePath = FileUtils.createFile(tempPath + "/" + cameraId + ".jpeg");
             fCaptureReceiveCB1 m_CaptureReceiveCB = new fCaptureReceiveCB1(imagePath);
             CapturePictureModule.setSnapRevCallBack(m_CaptureReceiveCB);
             boolean b = CapturePictureModule.remoteCapturePicture(loginId, chanNo - 1);
@@ -552,6 +554,7 @@
     @Override
     public AjaxResult localRecordStart(CameraCmd cmd) {
         try {
+            String operator = cmd.getOperator();
             String cameraId = cmd.getCameraId();
             Integer chanNo = cmd.getChanNo();
 
@@ -565,7 +568,10 @@
             //    GlobalVariable.previewMap.remove(cameraId);
             //    log.debug("鍋滄褰撳墠褰曞儚");
             //}
-            String path = FileUtils.createFile("D:/LocalRecordTemp/" + cameraId + ".mp4");
+
+            // 鏈湴涓存椂褰曞儚鍦板潃
+            String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+            String path = FileUtils.createFile(tempPath + "/" + operator + "/" + cameraId + ".mp4");
             LLong lRealHandle = RealPlayModule.startRealPlay(loginId, chanNo - 1, path);
             if (lRealHandle.longValue() <= 0) {
                 log.error("鍙栨祦澶辫触" + getErrorCodePrint());
@@ -589,33 +595,19 @@
     @Override
     public AjaxResult localRecordStop(CameraCmd cmd) {
         try {
+            String operator = cmd.getOperator();
             String cameraId = cmd.getCameraId();
             LLong lRealHandle = new LLong(cmd.getRecordId());
             if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                 return AjaxResult.warn("璁惧鏈櫥褰�");
             }
-
             RealPlayModule.stopRealPlay(lRealHandle);
             log.debug("鏈湴褰曞儚鍋滄");
-            String recordPath = FileUtils.createFile("D:/LocalRecordTemp/" + cameraId + ".mp4");
+            // 鏈湴涓存椂褰曞儚鍦板潃
+            String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+            String recordPath = FileUtils.createFile(tempPath + "/" + operator + "/" + cameraId + ".mp4");
             byte[] imageBytes = Files.readAllBytes(Paths.get(recordPath));
-            // OutputStream outputStream = response.getOutputStream();
-            // outputStream.write(imageBytes);
             return AjaxResult.success(imageBytes);
-            //if (GlobalVariable.previewMap.containsKey(cameraId)) {
-            //    lRealHandle = new LLong(GlobalVariable.previewMap.get(cameraId));
-            //    RealPlayModule.stopRealPlay(lRealHandle);
-            //    GlobalVariable.previewMap.remove(cameraId);
-            //    log.debug("鏈湴褰曞儚鍋滄");
-            //    String recordPath = FileUtils.createFile("D:/LocalRecordTemp/" + cameraId + ".mp4");
-            //    byte[] imageBytes = Files.readAllBytes(Paths.get(recordPath));
-            //   // OutputStream outputStream = response.getOutputStream();
-            //   // outputStream.write(imageBytes);
-            //    return AjaxResult.success(imageBytes);
-            //}
-            //else {
-            //    return AjaxResult.error("璁惧鏈紑濮嬪綍鍍�");
-            //}
         } catch (Exception ex) {
             log.error("鏈湴褰曞儚鍋滄寮傚父" + ex.getMessage());
             return AjaxResult.error("鏈湴褰曞儚鍋滄寮傚父" + ex.getMessage());
@@ -636,7 +628,9 @@
             String url = "";
             String cameraId = cmd.getCameraId();
             Integer chanNo = cmd.getChanNo();
-            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
+            // 鏈湴涓存椂褰曞儚鍦板潃
+            String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+            String path = FileUtils.createFile(tempPath + "/" + cameraId + ".mp4");
             boolean enable = cmd.isEnable();
             if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                 return "";
@@ -675,7 +669,9 @@
         try {
             String cameraId = cmd.getCameraId();
             Integer chanNo = cmd.getChanNo();
-            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
+            // 鏈湴涓存椂褰曞儚鍦板潃
+            String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+            String path = FileUtils.createFile(tempPath + "/" + cameraId + ".mp4");
             if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                 return false;
             }
@@ -711,7 +707,9 @@
         String url = "";
         try {
             String cameraId = cmd.getCameraId();
-            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
+            // 鏈湴涓存椂褰曞儚鍦板潃
+            String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+            String path = FileUtils.createFile(tempPath + "/" + cameraId + ".mp4");
             if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                 return "";
             }
@@ -780,15 +778,18 @@
             double[] cameraPositon = new double[]{cameras.getLongitude(), cameras.getLatitude(), cameras.getAltitude()};
             double[] targetPositions = cmd.getTargetPosition();
             double[] cameraPTZ = GisUtil.getCameraPTZ(cameraPositon, targetPositions, 20, 150);
+            //淇淇话
+            double correctPitch = cameraSdkService.correctPitch(cmd);
+            double newt = cameraPTZ[1] + correctPitch;
             int p = (int) (cameraPTZ[0] * 10);
-            int t = (int) (cameraPTZ[1] * 10);
+            int t = (int) (newt * 10);
             int z = (int) (cameraPTZ[2]);
             boolean bool = netsdk.CLIENT_DHPTZControlEx(loginId, chanNo - 1, NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_EXACTGOTO, p, t, z, 0);
             if (!bool) {
                 log.error("璁剧疆ptz澶辫触:" + getErrorCodePrint());
                 return AjaxResult.warn("璁剧疆ptz澶辫触:" + getErrorCodePrint());
             }
-            return AjaxResult.success("寮曞鐩爣浣嶇疆鎴愬姛");
+            return AjaxResult.success("寮曞鐩爣浣嶇疆鎴愬姛", correctPitch);
         } catch (Exception ex) {
             log.error("寮曞鐩爣浣嶇疆寮傚父:" + ex.getMessage());
             return AjaxResult.error("寮曞鐩爣浣嶇疆寮傚父:" + ex.getMessage());

--
Gitblit v1.9.3