From aea81128444acb8ca9a90bc7ef04758bf2cd284d Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期三, 23 八月 2023 14:44:22 +0800
Subject: [PATCH] 重构minio和mqtt配置信息获取 重构minio工具类 区分生产环境和开发环境配置信息

---
 ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java |   65 +++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 11 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
index 60c0b26..771c21f 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
@@ -2,22 +2,26 @@
 
 import com.ruoyi.common.annotation.SdkOperate;
 import com.ruoyi.common.utils.file.FileUtils;
+import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.device.camera.domain.CameraCmd;
 import com.ruoyi.device.camera.service.IArdCamerasService;
+import com.ruoyi.device.channel.domain.ArdChannel;
 import com.ruoyi.device.hiksdk.common.GlobalVariable;
 import com.ruoyi.device.camera.domain.ArdCameras;
-import com.ruoyi.device.hiksdk.config.MinioClientSingleton;
 import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil;
 import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK;
 import com.ruoyi.device.hiksdk.service.IHikClientService;
 import com.ruoyi.device.hiksdk.util.hikSdkUtil.LoginResultCallBack;
 import com.ruoyi.storage.minio.utils.MinioUtils;
 import com.sun.jna.Native;
+import com.sun.jna.NativeLong;
 import com.sun.jna.Platform;
 import com.sun.jna.Pointer;
 import com.sun.jna.ptr.IntByReference;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+
 import java.util.Base64;
 import javax.annotation.Resource;
 import java.io.*;
@@ -40,8 +44,12 @@
 @Service
 public class HikClientServiceImpl implements IHikClientService {
 
+    @Value("${minio.endpoint}")
+    private static String endpoint;
     @Resource
-    IArdCamerasService ardCamerasService;
+    private IArdCamerasService ardCamerasService;
+    @Resource
+    private MinioUtils minioUtil;
 
     private static HCNetSDK hCNetSDK;
 
@@ -125,7 +133,7 @@
         GlobalVariable.loginMap.remove(camera.getId());
         GlobalVariable.loginMap.put(camera.getId(), lUserID);
         camera.setLoginId(lUserID);
-        camera.setChannel((int) m_strDeviceInfo.byStartChan);
+        camera.setStartDChan((int) m_strDeviceInfo.byStartChan);
         return camera;
     }
 
@@ -1093,7 +1101,7 @@
         log.debug("-----------杩欓噷寮�濮嬪浘鐗囧瓨鍏ュ唴瀛�----------" + is);
 
         Base64.Encoder decoder = Base64.getEncoder();
-      //  BASE64Encoder encoder = new BASE64Encoder();
+        //  BASE64Encoder encoder = new BASE64Encoder();
         String png_base64 = decoder.encodeToString(jpegBuffer.array());//杞崲鎴恇ase64涓�
         png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//鍒犻櫎 \r\n
         log.debug("-----------澶勭悊瀹屾垚鎴浘鏁版嵁----------");
@@ -1142,16 +1150,14 @@
             byte[] array = jpegBuffer.array();
             //瀛樺偍鍒癿inio
             String BucketName = "pic";
-            String uuid = UUID.randomUUID().toString().replace("-", "");
-            String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
-            String ObjectName = time + "/" + uuid + ".jpeg";
+            String ObjectName = "capture/" + IdUtils.simpleUUID() + ".jpeg";
             String ContentType = "image/JPEG";
             InputStream input = new ByteArrayInputStream(array);
             String url = "";
             try {
-                boolean b = MinioUtils.uploadObject(BucketName, ObjectName, input, input.available(), ContentType);
+                boolean b = minioUtil.uploadObject(BucketName, ObjectName, input, input.available(), ContentType);
                 if (b) {
-                    url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName);
+                    url = minioUtil.getBucketObjectUrl(BucketName, ObjectName);
                     log.debug("涓婁紶鏂囦欢鎴愬姛!" + url);
                 }
             } catch (IOException ex) {
@@ -1335,9 +1341,9 @@
             FileInputStream stream = new FileInputStream(path);
             String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
             String recordName = cameraId + "/" + time + "/" + ObjectName + ".mp4";
-            boolean b = MinioUtils.uploadObject(BucketName, recordName, stream, stream.available(), ContentType);
+            boolean b = minioUtil.uploadObject(BucketName, recordName, stream, stream.available(), ContentType);
             if (b) {
-                url = MinioClientSingleton.domainUrl + "/" + BucketName + "/" + recordName;
+                url = endpoint + "/" + BucketName + "/" + recordName;
                 log.debug("涓婁紶鏂囦欢鎴愬姛!" + url);
             }
             return url;
@@ -1386,4 +1392,41 @@
             log.error("褰曞儚鍋滄寮傚父" + ex.getMessage());
         }
     }
+
+    //鑾峰彇IP閫氶亾
+    @Override
+    public List<ArdChannel> getCameraChannelList(ArdCameras camera) {
+        /*鑾峰彇閫氶亾*/
+        List<ArdChannel> channelList = new ArrayList<>();
+        try {
+            Integer chanNum = camera.getChanNum();
+            Integer startDChan = camera.getStartDChan();
+            if (chanNum > 0) {
+                // 鑾峰彇閫氶亾鍙�
+                for (int iChannum = 0; iChannum < chanNum; iChannum++) {
+                    ArdChannel ardChannel = new ArdChannel();
+                    int channum = iChannum + startDChan+1;
+                    HCNetSDK.NET_DVR_PICCFG_V40 strPicCfg = new HCNetSDK.NET_DVR_PICCFG_V40();
+                    strPicCfg.dwSize = strPicCfg.size();
+                    strPicCfg.write();
+                    Pointer pStrPicCfg = strPicCfg.getPointer();
+                    NativeLong lChannel = new NativeLong(channum);
+                    IntByReference pInt = new IntByReference(0);
+                    boolean b_GetPicCfg = hCNetSDK.NET_DVR_GetDVRConfig(camera.getLoginId(), HCNetSDK.NET_DVR_GET_PICCFG_V40, lChannel.intValue(),
+                            pStrPicCfg, strPicCfg.size(), pInt);
+                    if (b_GetPicCfg) {
+                        strPicCfg.read();
+                        String channelName = new String(strPicCfg.sChanName, "GBK").trim();
+                        ardChannel.setName(channelName);
+                    }
+                    ardChannel.setDeviceId(camera.getId());
+                    ardChannel.setChanNo(iChannum + 1);
+                    channelList.add(ardChannel);
+                }
+            }
+        } catch (Exception ex) {
+            log.error("鑾峰彇鐩告満閫氶亾寮傚父:" + ex.getMessage());
+        }
+        return channelList;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3