From 0362c0c8502a81fc974afb8d2aff85d9efd7bbb1 Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期四, 29 六月 2023 17:28:22 +0800 Subject: [PATCH] 修改报警逻辑 增加优先级队列 --- ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java | 90 ++++++++++++++++++++++++++++++--------------- 1 files changed, 60 insertions(+), 30 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 1d5a6cd..9a5e8ed 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 @@ -6,13 +6,13 @@ import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUtils; -import com.ruoyi.constant.sdkPriority; +import com.ruoyi.common.utils.uuid.IdUtils; +import com.ruoyi.constant.CamPriority; import com.ruoyi.device.camera.domain.CameraCmd; import com.ruoyi.device.camera.mapper.ArdCamerasMapper; 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.domain.recordInfo; import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil; import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK; import com.ruoyi.device.hiksdk.service.IHikClientService; @@ -24,7 +24,6 @@ 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.stereotype.Service; import sun.misc.BASE64Encoder; @@ -35,6 +34,7 @@ import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; + import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*; /** @@ -210,6 +210,7 @@ log.debug("鍔犺浇lib瀹屾垚锛�"); List<ArdCameras> ardCameras = ardCamerasMapper.selectArdCamerasListNoDataScope(new ArdCameras()); for (ArdCameras camera : ardCameras) { + Thread.sleep(500); login(camera); } } catch (Exception ex) { @@ -595,7 +596,7 @@ double p = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); double t = c.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); double z = d.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - log.debug("T鍨傜洿鍙傛暟涓�: " + p + "P姘村钩鍙傛暟涓�: " + t + "Z鍙樺�嶅弬鏁颁负: " + z); +// log.debug("T鍨傜洿鍙傛暟涓�: " + p + "P姘村钩鍙傛暟涓�: " + t + "Z鍙樺�嶅弬鏁颁负: " + z); Map<String, Object> ptzMap = new HashMap<>(); ptzMap.put("p", p); ptzMap.put("t", t); @@ -604,7 +605,7 @@ } else { int code = hCNetSDK.NET_DVR_GetLastError(); log.info("鎺у埗澶辫触,璇风◢鍚庨噸璇�" + code); - return null; + return new HashMap<>(); } } @@ -652,7 +653,7 @@ @Override @SdkOperate - public boolean setTargetPosition(CameraCmd cmd) { + public boolean guideTargetPosition(CameraCmd cmd) { String cameraId = cmd.getCameraId(); Integer channelNum = cmd.getChannelNum(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { @@ -710,7 +711,7 @@ ardCameras.setOperatorId(operator); //璁剧疆褰撳墠杩囨湡鏃堕棿 Date now = new Date(); - now.setTime(now.getTime() + expired * 1000 * 60); + now.setTime(now.getTime() + expired * 1000); ardCameras.setOperatorExpired(now); ardCamerasMapper.updateArdCameras(ardCameras); } else { @@ -719,24 +720,24 @@ if (currentOperator.equals(operator)) { //璁剧疆褰撳墠杩囨湡鏃堕棿 Date now = new Date(); - now.setTime(now.getTime() + expired * 1000 * 60); + now.setTime(now.getTime() + expired * 1000); ardCameras.setOperatorExpired(now); ardCamerasMapper.updateArdCameras(ardCameras); } else { //濡傛灉闈炴湰浜烘瘮杈冧紭鍏堢骇 Integer currentLevel = 0;//褰撳墠鎿嶄綔鑰呯殑浼樺厛绾� - if (sdkPriority.priorityMap.containsKey(currentOperator)) { + if (CamPriority.priorityMap.containsKey(currentOperator)) { /*褰撳墠鎺у埗鑰呬负绯荤粺鎶ヨ鐢ㄦ埛*/ - currentLevel = (Integer) sdkPriority.priorityMap.get(currentOperator); + currentLevel = (Integer) CamPriority.priorityMap.get(currentOperator); } else { /*褰撳墠鎺у埗鑰呬负鏅�氱敤鎴�*/ SysUser sysUser = sysUserMapper.selectUserById(currentOperator); currentLevel = sysUser.getCameraPriority(); } Integer operatorLevel = 0;//鑾峰彇鐢宠鑰呯殑浼樺厛绾� - if (sdkPriority.priorityMap.containsKey(operator)) { + if (CamPriority.priorityMap.containsKey(operator)) { /*鍖呭惈璇存槑褰撳墠鐢宠鎺у埗鑰呬负绯荤粺鎶ヨ鐢ㄦ埛*/ - operatorLevel = (Integer) sdkPriority.priorityMap.get(operator); + operatorLevel = (Integer) CamPriority.priorityMap.get(operator); } else { /*鍚﹀垯鐢宠鎺у埗鑰呬负褰撳墠鐧诲綍鐢ㄦ埛*/ LoginUser loginUser = SecurityUtils.getLoginUser(); @@ -746,7 +747,7 @@ //鍒ゆ柇浼樺厛绾� if (operatorLevel > currentLevel) { Date now = new Date(); - now.setTime(now.getTime() + expired * 60 * 1000); + now.setTime(now.getTime() + expired * 60); ardCameras.setOperatorExpired(now);//璁剧疆褰撳墠杩囨湡鏃堕棿 ardCameras.setOperatorId(operator);//璁剧疆褰撳墠鐢ㄦ埛 ardCamerasMapper.updateArdCameras(ardCameras); @@ -1013,6 +1014,25 @@ return bool; } + public String getFocusMode(CameraCmd cmd) + { + String cameraId = cmd.getCameraId(); + Integer channelNum = cmd.getChannelNum(); + if (!GlobalVariable.loginMap.containsKey(cameraId)) { + return ""; + } + Integer userId = GlobalVariable.loginMap.get(cameraId); + NET_DVR_FOCUSMODE_CFG struFocusMode = new NET_DVR_FOCUSMODE_CFG(); + Pointer point = struFocusMode.getPointer(); + IntByReference ibrBytesReturned = new IntByReference(0); + boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, struFocusMode.size(), ibrBytesReturned); + if (!b_GetCameraParam) { + System.out.println("鑾峰彇鍓嶇鍙傛暟澶辫触锛岄敊璇爜锛�" + hCNetSDK.NET_DVR_GetLastError()); + } + struFocusMode.read(); + log.info("褰撳墠鑱氱劍妯″紡锛�" + struFocusMode.byFocusMode); + return String.valueOf(struFocusMode.byFocusMode); + } /** * @鎻忚堪 浜戝彴鍔犵儹寮�鍏� * @鍙傛暟 [userId, channelNum, enable] @@ -1304,14 +1324,14 @@ } @Override - public void recordToMinio(CameraCmd cmd) { + public String recordToMinio(CameraCmd cmd) { try { String cameraId = cmd.getCameraId(); Integer channelNum = cmd.getChannelNum(); String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4"); boolean enable = cmd.isEnable(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { - return; + return ""; } Integer userId = GlobalVariable.loginMap.get(cameraId); //寮哄埗I甯х粨鏋勪綋瀵硅薄 @@ -1335,41 +1355,51 @@ previewinfo.byNPQMode = 0;//NPQ妯″紡锛�0-鐩磋繛妯″紡锛�1-杩囨祦濯掍綋妯″紡 previewinfo.write(); if (enable) { - if (!GlobalVariable.previewMap.containsKey(cameraId)) { - int lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); - if (lRealHandle == -1) { - log.error("鍙栨祦澶辫触" + hCNetSDK.NET_DVR_GetLastError()); - return; - } - log.info("鍙栨祦鎴愬姛"); - GlobalVariable.previewMap.put(cameraId, lRealHandle); + if (GlobalVariable.previewMap.containsKey(cameraId)) { + Integer lRealHandle = GlobalVariable.previewMap.get(cameraId); + hCNetSDK.NET_DVR_StopRealPlay(lRealHandle); + GlobalVariable.previewMap.remove(cameraId); + log.debug("鍋滄褰撳墠褰曞儚"); } - + int lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); + if (lRealHandle == -1) { + log.error("鍙栨祦澶辫触" + hCNetSDK.NET_DVR_GetLastError()); + return ""; + } + log.debug("鍙栨祦鎴愬姛"); + GlobalVariable.threadMap.put(cameraId, Thread.currentThread().getName()); + GlobalVariable.previewMap.put(cameraId, lRealHandle); if (!hCNetSDK.NET_DVR_SaveRealData_V30(GlobalVariable.previewMap.get(cameraId), 2, path)) { log.error("淇濆瓨瑙嗛鏂囦欢鍒颁复鏃舵枃浠跺す澶辫触 閿欒鐮佷负: " + hCNetSDK.NET_DVR_GetLastError()); - return; + return ""; } - log.info("褰曞儚寮�濮�"); + log.debug("褰曞儚寮�濮�"); } else { if (GlobalVariable.previewMap.containsKey(cameraId)) { Integer lRealHandle = GlobalVariable.previewMap.get(cameraId); hCNetSDK.NET_DVR_StopRealPlay(lRealHandle); GlobalVariable.previewMap.remove(cameraId); } - log.info("褰曞儚鍋滄"); - + log.debug("褰曞儚鍋滄"); //瀛樺叆minio String BucketName = cmd.getRecordBucketName(); String ObjectName = cmd.getRecordObjectName(); String ContentType = "video/MP4"; FileInputStream stream = new FileInputStream(path); - boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); + String simpleUUID = IdUtils.simpleUUID(); + String time = new SimpleDateFormat("yyyyMMdd").format(new Date()); + String recordName = cameraId + "/" + time + "/" + ObjectName +"_"+ simpleUUID + ".mp4"; + boolean b = MinioUtils.uploadObject(BucketName, recordName, stream, stream.available(), ContentType); if (b) { - log.info("涓婁紶鏂囦欢鎴愬姛!" + MinioClientSingleton.domainUrl + "/" + BucketName + "/" + ObjectName); + String url = MinioClientSingleton.domainUrl + "/" + BucketName + "/" + recordName; + log.debug("涓婁紶鏂囦欢鎴愬姛!" + url); + return url; } } + return ""; } catch (Exception ex) { log.error("褰曞儚寮傚父" + ex.getMessage()); + return ""; } } } \ No newline at end of file -- Gitblit v1.9.3