From 2fa66c208202f420a5f001cf0d67e5aa1bf94578 Mon Sep 17 00:00:00 2001 From: aijinhui <aijinhui> Date: 星期四, 07 九月 2023 16:53:39 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java | 194 +++++++++++++++++++++++++++++++----------------- 1 files changed, 125 insertions(+), 69 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 1471f3a..12c8cc8 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 @@ -1,28 +1,26 @@ package com.ruoyi.device.hiksdk.service.impl; -import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.annotation.SdkOperate; import com.ruoyi.common.utils.file.FileUtils; +import com.ruoyi.common.utils.file.MimeTypeUtils; 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.channel.service.IArdChannelService; 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.utils.gis.GisUtil; +import com.ruoyi.device.hiksdk.sdk.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.ruoyi.device.hiksdk.sdk.LoginResultCallBack; +import com.ruoyi.utils.minio.MinioUtil; 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.scheduling.annotation.Async; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.Base64; @@ -31,11 +29,9 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; import java.text.DecimalFormat; -import java.text.SimpleDateFormat; import java.util.*; -import java.util.stream.Collectors; -import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*; +import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.*; /** * @ClassName: hikClientServiceImpl @@ -48,8 +44,10 @@ @Service public class HikClientServiceImpl implements IHikClientService { + @Value("${minio.endpoint}") + private static String endpoint; @Resource - IArdCamerasService ardCamerasService; + private IArdCamerasService ardCamerasService; private static HCNetSDK hCNetSDK; @@ -264,7 +262,7 @@ public boolean pTZControlWithSpeed(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); Integer speed = cmd.getSpeed(); Integer code = cmd.getCode(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { @@ -350,23 +348,31 @@ @SdkOperate public boolean setFocusPos(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); Integer dwFocusPos = cmd.getDwFocusPos(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } + // 鑾峰彇鍙傛暟 Integer userId = GlobalVariable.loginMap.get(cameraId); - - NET_DVR_FOCUSMODE_CFG focusmodeCfg = new NET_DVR_FOCUSMODE_CFG(); - Pointer point = focusmodeCfg.getPointer(); - IntByReference ibrBytesReturned = new IntByReference(0); - focusmodeCfg.dwFocusPos = dwFocusPos; - boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, focusmodeCfg.size(), ibrBytesReturned); + HCNetSDK.NET_DVR_STD_CONFIG struStdCfg = new HCNetSDK.NET_DVR_STD_CONFIG(); + HCNetSDK.NET_DVR_GIS_INFO struGisInfo = new HCNetSDK.NET_DVR_GIS_INFO(); + struGisInfo.struPtzPosEx.dwFocus=dwFocusPos; + struStdCfg.read(); + IntByReference lchannel = new IntByReference(channelNum); + struStdCfg.lpInBuffer= struGisInfo.getPointer(); + struStdCfg.lpCondBuffer = lchannel.getPointer(); + struStdCfg.dwCondSize = 4; + struStdCfg.dwInSize = struGisInfo.size(); + struStdCfg.write();//璁剧疆鍓嶄箣鍓嶈write() + boolean bool = hCNetSDK.NET_DVR_SetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg); if (!bool) { int code = hCNetSDK.NET_DVR_GetLastError(); - log.error("璁剧疆鑱氱劍鍊煎け璐�,璇风◢鍚庨噸璇�" + code); + log.error("璁剧疆GIS淇℃伅鏁版嵁澶辫触,璇风◢鍚庨噸璇�" + code); + return false; + } else { + return true; } - return bool; } /** @@ -377,28 +383,31 @@ @Override public Map<String, Object> getFocusPos(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); - + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return new HashMap<>(); } + // 鑾峰彇鍙傛暟 Integer userId = GlobalVariable.loginMap.get(cameraId); - - NET_DVR_FOCUSMODE_CFG focusmodeCfg = new NET_DVR_FOCUSMODE_CFG(); - Pointer point = focusmodeCfg.getPointer(); - IntByReference ibrBytesReturned = new IntByReference(0); - boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, focusmodeCfg.size(), ibrBytesReturned); - if (bool) { - focusmodeCfg.read(); - Map<String, Object> map = new HashMap<>(); - map.put("dwFocusPos", focusmodeCfg.dwFocusPos); - map.put("byFocusDefinitionDisplay ", focusmodeCfg.byFocusDefinitionDisplay); - map.put("dwRelativeFocusPos", focusmodeCfg.dwRelativeFocusPos); - return map; - } else { + HCNetSDK.NET_DVR_STD_CONFIG struStdCfg = new HCNetSDK.NET_DVR_STD_CONFIG(); + HCNetSDK.NET_DVR_GIS_INFO struGisInfo = new HCNetSDK.NET_DVR_GIS_INFO(); + struStdCfg.read(); + IntByReference lchannel = new IntByReference(channelNum); + struStdCfg.lpCondBuffer = lchannel.getPointer(); + struStdCfg.dwCondSize = 4; + struStdCfg.lpOutBuffer = struGisInfo.getPointer(); + struStdCfg.dwOutSize = struGisInfo.size(); + struStdCfg.write();//璁剧疆鍓嶄箣鍓嶈write() + boolean bool = hCNetSDK.NET_DVR_GetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg); + if (!bool) { int code = hCNetSDK.NET_DVR_GetLastError(); - log.debug("鑾峰彇鑱氱劍鍊煎け璐�,璇风◢鍚庨噸璇�" + code); + log.error("鑾峰彇GIS淇℃伅鏁版嵁澶辫触,璇风◢鍚庨噸璇�" + code); return new HashMap<>(); + } else { + struGisInfo.read(); + Map<String, Object> map = new HashMap<>(); + map.put("dwFocus",struGisInfo.struPtzPosEx.dwFocus); + return map; } } @@ -411,7 +420,7 @@ @SdkOperate public boolean setPreset(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); Integer PresetIndex = cmd.getPresetIndex(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; @@ -434,7 +443,7 @@ @SdkOperate public boolean gotoPreset(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); Integer PresetIndex = cmd.getPresetIndex(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; @@ -459,7 +468,7 @@ @Override public String getVideoResolution(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return " "; } @@ -564,7 +573,7 @@ @Override public Map<String, Object> getPtz(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return null; } @@ -615,7 +624,7 @@ @SdkOperate public boolean setPtz(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); Map<String, Double> ptz = cmd.getPtzMap(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; @@ -648,7 +657,7 @@ @SdkOperate public boolean guideTargetPosition(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -735,7 +744,7 @@ @Override public int getPTZLockInfo(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return -1; } @@ -767,7 +776,7 @@ @SdkOperate public boolean setZeroPtz(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -799,7 +808,7 @@ @Override public Map<String, Object> getPtzScope(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return new HashMap<>(); } @@ -848,7 +857,7 @@ public boolean controlDefogcfg(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -894,7 +903,7 @@ public boolean controlInfrarecfg(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -942,7 +951,7 @@ public boolean controlFocusMode(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -975,9 +984,17 @@ return bool; } + /** + * @鎻忚堪 鑾峰彇鑱氱劍妯″紡 + * @鍙傛暟 [userId, channelNum] + * @杩斿洖鍊� boolean + * @鍒涘缓浜� 鍒樿嫃涔� + * @鍒涘缓鏃堕棿 2023/1/18 13:07 + * @淇敼浜哄拰鍏跺畠淇℃伅 + */ public String getFocusMode(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return ""; } @@ -1007,7 +1024,7 @@ public boolean controlPTHeateRpwron(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -1040,7 +1057,7 @@ public boolean controlCameraDeicing(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; } @@ -1077,7 +1094,7 @@ */ public String captureJPEGPicture(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return ""; } @@ -1120,7 +1137,7 @@ @SdkOperate public String picCutCate(CameraCmd cmd) { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return ""; } @@ -1151,13 +1168,12 @@ //瀛樺偍鍒癿inio String BucketName = "pic"; 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(), MimeTypeUtils.IMAGE_JPEG); if (b) { - url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName); + url = MinioUtil.getBucketObjectUrl(BucketName, ObjectName); log.debug("涓婁紶鏂囦欢鎴愬姛!" + url); } } catch (IOException ex) { @@ -1183,7 +1199,7 @@ public String record(CameraCmd cmd) { try { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4"); boolean enable = cmd.isEnable(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { @@ -1245,7 +1261,7 @@ public void recordStart(CameraCmd cmd) { try { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4"); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return; @@ -1300,7 +1316,7 @@ String url = ""; try { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4"); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return ""; @@ -1336,14 +1352,11 @@ log.debug("褰曞儚鍋滄"); //瀛樺叆minio String BucketName = cmd.getRecordBucketName(); - String ObjectName = cmd.getRecordObjectName(); - String ContentType = "video/MP4"; + String ObjectName = cmd.getRecordObjectName() + ".mp4"; 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, ObjectName, stream, stream.available(), "video/MP4"); if (b) { - url = MinioClientSingleton.domainUrl + "/" + BucketName + "/" + recordName; + url = MinioUtil.getBucketObjectUrl(BucketName, ObjectName); log.debug("涓婁紶鏂囦欢鎴愬姛!" + url); } return url; @@ -1357,7 +1370,7 @@ public void recordStopNotToMinio(CameraCmd cmd) { try { String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); + Integer channelNum = cmd.getChanNo(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return; } @@ -1405,7 +1418,7 @@ // 鑾峰彇閫氶亾鍙� for (int iChannum = 0; iChannum < chanNum; iChannum++) { ArdChannel ardChannel = new ArdChannel(); - int channum = iChannum + startDChan+1; + int channum = iChannum + startDChan + 1; HCNetSDK.NET_DVR_PICCFG_V40 strPicCfg = new HCNetSDK.NET_DVR_PICCFG_V40(); strPicCfg.dwSize = strPicCfg.size(); strPicCfg.write(); @@ -1429,4 +1442,47 @@ } return channelList; } + + /** + * @鎻忚堪 鑾峰彇GIS淇℃伅鏁版嵁 + * @鍙傛暟 [userId, channelNum] + * @杩斿洖鍊� boolean + * @鍒涘缓浜� 鍒樿嫃涔� + * @鍒涘缓鏃堕棿 2023/1/17 16:36 + * @淇敼浜哄拰鍏跺畠淇℃伅 0-瑙i攣 1-閿佸畾 + */ + @Override + public Map<String, Object> getGisInfo(CameraCmd cmd) { + String cameraId = cmd.getCameraId(); + Integer channelNum = cmd.getChanNo(); + if (!GlobalVariable.loginMap.containsKey(cameraId)) { + return new HashMap<>(); + } + // 鑾峰彇鍙傛暟 + Integer userId = GlobalVariable.loginMap.get(cameraId); + HCNetSDK.NET_DVR_STD_CONFIG struStdCfg = new HCNetSDK.NET_DVR_STD_CONFIG(); + HCNetSDK.NET_DVR_GIS_INFO struGisInfo = new HCNetSDK.NET_DVR_GIS_INFO(); + struStdCfg.read(); + IntByReference lchannel = new IntByReference(channelNum); + struStdCfg.lpCondBuffer = lchannel.getPointer(); + struStdCfg.dwCondSize = 4; + struStdCfg.lpOutBuffer = struGisInfo.getPointer(); + struStdCfg.dwOutSize = struGisInfo.size(); + struStdCfg.write();//璁剧疆鍓嶄箣鍓嶈write() + boolean bool = hCNetSDK.NET_DVR_GetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg); + if (!bool) { + int code = hCNetSDK.NET_DVR_GetLastError(); + log.error("鑾峰彇GIS淇℃伅鏁版嵁澶辫触,璇风◢鍚庨噸璇�" + code); + return new HashMap<>(); + } else { + struGisInfo.read(); + Map<String, Object> map = new HashMap<>(); + map.put("p", struGisInfo.struPtzPos.fPanPos); + map.put("t", struGisInfo.struPtzPos.fTiltPos<0?struGisInfo.struPtzPos.fTiltPos+360:struGisInfo.struPtzPos.fTiltPos); + map.put("z", struGisInfo.struPtzPos.fZoomPos); + map.put("fHorFieldAngle", struGisInfo.fHorizontalValue);// 姘村钩瑙嗗満瑙� + map.put("fVerFieldAngle", struGisInfo.fVerticalValue);// 鍨傜洿瑙嗗満瑙� + return map; + } + } } \ No newline at end of file -- Gitblit v1.9.3