From cfa36565f54f4274e415af9899db2aedadbd7b76 Mon Sep 17 00:00:00 2001 From: aijinhui <aijinhui> Date: 星期三, 06 九月 2023 16:10:43 +0800 Subject: [PATCH] 设备健康详情 --- ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java | 135 +++++++++++++++++++++++++++++++++++++------- 1 files changed, 113 insertions(+), 22 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..d03fb83 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,32 +2,36 @@ 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.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.beans.factory.annotation.Value; import org.springframework.stereotype.Service; + import java.util.Base64; import javax.annotation.Resource; import java.io.*; import java.math.BigDecimal; import java.nio.ByteBuffer; import java.text.DecimalFormat; -import java.text.SimpleDateFormat; import java.util.*; -import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*; +import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.*; /** * @ClassName: hikClientServiceImpl @@ -40,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; @@ -125,7 +131,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; } @@ -379,6 +385,9 @@ NET_DVR_FOCUSMODE_CFG focusmodeCfg = new NET_DVR_FOCUSMODE_CFG(); Pointer point = focusmodeCfg.getPointer(); IntByReference ibrBytesReturned = new IntByReference(0); + focusmodeCfg.byFocusMode = 1; + focusmodeCfg.byAutoFocusMode = 0; + focusmodeCfg.write(); boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, focusmodeCfg.size(), ibrBytesReturned); if (bool) { focusmodeCfg.read(); @@ -967,6 +976,14 @@ return bool; } + /** + * @鎻忚堪 鑾峰彇鑱氱劍妯″紡 + * @鍙傛暟 [userId, channelNum] + * @杩斿洖鍊� boolean + * @鍒涘缓浜� 鍒樿嫃涔� + * @鍒涘缓鏃堕棿 2023/1/18 13:07 + * @淇敼浜哄拰鍏跺畠淇℃伅 + */ public String getFocusMode(CameraCmd cmd) { String cameraId = cmd.getCameraId(); Integer channelNum = cmd.getChannelNum(); @@ -1093,7 +1110,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 +1159,13 @@ 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 ContentType = "image/JPEG"; + String ObjectName = "capture/" + IdUtils.simpleUUID() + ".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) { @@ -1330,14 +1344,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; @@ -1386,4 +1397,84 @@ 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; + } + + /** + * @鎻忚堪 鑾峰彇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.getChannelNum(); + 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