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 | 283 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 141 insertions(+), 142 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 e2e2290..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; @@ -184,7 +183,7 @@ System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length()); m_strLoginInfo.wPort = m_sPort; m_strLoginInfo.byVerifyMode = 0; - m_strLoginInfo.byLoginMode=0; + m_strLoginInfo.byLoginMode = 0; //鏄惁寮傛鐧诲綍锛�0- 鍚︼紝1- 鏄� windowsSDK閲屾槸true鍜宖alse m_strLoginInfo.bUseAsynLogin = true; //寮傛鐧诲綍鍥炶皟 @@ -211,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) { @@ -267,7 +267,7 @@ */ @Override @SdkOperate - public boolean PTZControlWithSpeed(CameraCmd cmd) { + public boolean pTZControlWithSpeed(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); Integer channelNum = cmd.getChannelNum(); @@ -596,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); @@ -605,7 +605,7 @@ } else { int code = hCNetSDK.NET_DVR_GetLastError(); log.info("鎺у埗澶辫触,璇风◢鍚庨噸璇�" + code); - return null; + return new HashMap<>(); } } @@ -653,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)) { @@ -663,7 +663,8 @@ NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS(); m_ptzPosCurrent.wAction = 1; try { - double[] cameraPositon = cmd.getCamPosition(); + ArdCameras cameras = ardCamerasMapper.selectArdCamerasById(cameraId); + double[] cameraPositon = new double[]{cameras.getLongitude(), cameras.getLatitude(), cameras.getAltitude()}; double[] targetPositions = cmd.getTargetPosition(); double[] cameraPTZ = GisUtil.getCameraPTZ(cameraPositon, targetPositions, 20, 150); String p = String.valueOf((int) (cameraPTZ[0] * 10)); @@ -681,7 +682,7 @@ } return bool; } catch (Exception ex) { - log.error(ex.getMessage()); + log.error("寮曞寮傚父:" + ex.getMessage()); return false; } } @@ -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] @@ -1232,109 +1252,14 @@ * @淇敼浜哄拰鍏跺畠淇℃伅 */ @Override - @SdkOperate public String record(CameraCmd cmd) { - String cameraId = cmd.getCameraId(); - Integer channelNum = cmd.getChannelNum(); - boolean enable = cmd.isEnable(); - if (!GlobalVariable.loginMap.containsKey(cameraId)) { - return ""; - } - Integer userId = GlobalVariable.loginMap.get(cameraId); - String path = ""; - //棰勮鍙傛暟 - NET_DVR_PREVIEWINFO previewinfo = new NET_DVR_PREVIEWINFO(); - previewinfo.read(); - previewinfo.lChannel = channelNum; - previewinfo.dwStreamType = 0;//鐮佹祦绫诲瀷锛�0-涓荤爜娴侊紝1-瀛愮爜娴侊紝2-涓夌爜娴侊紝3-铏氭嫙鐮佹祦锛屼互姝ょ被鎺� - previewinfo.dwLinkMode = 0;//杩炴帴鏂瑰紡锛�0-TCP鏂瑰紡锛�1-UDP鏂瑰紡锛�2-澶氭挱鏂瑰紡锛�3-RTP鏂瑰紡锛�4-RTP/RTSP锛�5-RTP/HTTP锛�6-HRUDP锛堝彲闈犱紶杈擄級锛�7-RTSP/HTTPS锛�8-NPQ - previewinfo.hPlayWnd = null;//鎾斁绐楀彛鐨勫彞鏌勶紝涓篘ULL琛ㄧず涓嶈В鐮佹樉绀恒�� - previewinfo.bBlocked = 0;//0- 闈為樆濉炲彇娴侊紝1-闃诲鍙栨祦 - previewinfo.byNPQMode = 0;//NPQ妯″紡锛�0-鐩磋繛妯″紡锛�1-杩囨祦濯掍綋妯″紡 - previewinfo.write(); - int lRealHandle; - if (enable) { - if (!GlobalVariable.user_real_Map.containsKey(userId)) { - lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); - if (lRealHandle == -1) { - int iErr = hCNetSDK.NET_DVR_GetLastError(); - log.error("鍙栨祦澶辫触" + iErr); - return ""; - } - log.info("鍙栨祦鎴愬姛"); - - File file = new File("D:/record/temp.mp4"); - if (!file.exists()) { - try { - File fileParent = file.getParentFile(); - if (!fileParent.exists()) { - fileParent.mkdirs(); - } - file.createNewFile(); - } catch (Exception e) { - e.printStackTrace(); - } - } - try { - path = file.getCanonicalPath(); - } catch (IOException e) { - e.printStackTrace(); - } - recordInfo info = new recordInfo(); - info.setLRealHandle(lRealHandle); - info.setRecordPath(path); - GlobalVariable.user_real_Map.put(userId, info); - } - recordInfo info = GlobalVariable.user_real_Map.get(userId); - if (!hCNetSDK.NET_DVR_SaveRealData_V30(info.getLRealHandle(), 1, info.getRecordPath())) { - log.error("淇濆瓨瑙嗛鏂囦欢鍒颁复鏃舵枃浠跺す澶辫触 閿欒鐮佷负: " + hCNetSDK.NET_DVR_GetLastError()); - return "淇濆瓨瑙嗛鏂囦欢鍒颁复鏃舵枃浠跺す澶辫触 閿欒鐮佷负:" + hCNetSDK.NET_DVR_GetLastError(); - } - log.info("褰曞儚寮�濮�"); - //return info.getRecordPath(); - return ""; - } else { - recordInfo info = GlobalVariable.user_real_Map.get(userId); - if (StringUtils.isNull(info)) { - return ""; - } - hCNetSDK.NET_DVR_StopRealPlay(info.getLRealHandle()); - log.info("褰曞儚鍋滄"); - //瀛樺叆minio - String BucketName = "record"; - String uuid = UUID.randomUUID().toString().replace("-", ""); - String time = new SimpleDateFormat("yyyyMMdd").format(new Date()); - String ObjectName = cameraId + "/" + time + "/" + uuid + ".mp4"; - String ContentType = "video/MP4"; - FileInputStream stream = null; - try { - stream = new FileInputStream(info.getRecordPath()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - String url = ""; - try { - boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); - if (b) { - url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName); - log.info("涓婁紶鏂囦欢鎴愬姛!" + url); - } - } catch (IOException ex) { - log.error("涓婁紶鏂囦欢寮傚父锛�" + ex.getMessage()); - } - GlobalVariable.user_real_Map.remove(userId); - return url; - } - } - - @Override - public void 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甯х粨鏋勪綋瀵硅薄 @@ -1357,50 +1282,124 @@ previewinfo.bBlocked = 0;//0- 闈為樆濉炲彇娴侊紝1-闃诲鍙栨祦 previewinfo.byNPQMode = 0;//NPQ妯″紡锛�0-鐩磋繛妯″紡锛�1-杩囨祦濯掍綋妯″紡 previewinfo.write(); - int lRealHandle; + String url = ""; if (enable) { - if (!GlobalVariable.user_real_Map.containsKey(userId)) { - lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); + 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; + return ""; } log.info("鍙栨祦鎴愬姛"); - - String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4"); - recordInfo info = new recordInfo(); - info.setLRealHandle(lRealHandle); - info.setRecordPath(path); - GlobalVariable.user_real_Map.put(userId, info); + GlobalVariable.previewMap.put(cameraId, lRealHandle); } - recordInfo info = GlobalVariable.user_real_Map.get(userId); - if (!hCNetSDK.NET_DVR_SaveRealData_V30(info.getLRealHandle(), 2, info.getRecordPath())) { + if (!hCNetSDK.NET_DVR_SaveRealData_V30(GlobalVariable.previewMap.get(cameraId), 2, path)) { log.error("淇濆瓨瑙嗛鏂囦欢鍒颁复鏃舵枃浠跺す澶辫触 閿欒鐮佷负: " + hCNetSDK.NET_DVR_GetLastError()); - return; + return ""; } log.info("褰曞儚寮�濮�"); } else { - recordInfo info = GlobalVariable.user_real_Map.get(userId); - if (StringUtils.isNull(info)) { - return; + if (GlobalVariable.previewMap.containsKey(cameraId)) { + Integer lRealHandle = GlobalVariable.previewMap.get(cameraId); + hCNetSDK.NET_DVR_StopRealPlay(lRealHandle); + GlobalVariable.previewMap.remove(cameraId); } - hCNetSDK.NET_DVR_StopRealPlay(info.getLRealHandle()); log.info("褰曞儚鍋滄"); - if (cmd.isUploadMinio()) { - //瀛樺叆minio - String BucketName = cmd.getRecordBucketName(); - String ObjectName = cmd.getRecordObjectName(); - String ContentType = "video/MP4"; - FileInputStream stream = new FileInputStream(info.getRecordPath()); - boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); - if (b) { - log.info("涓婁紶鏂囦欢鎴愬姛!" + MinioClientSingleton.domainUrl + "/" + BucketName + "/" + ObjectName); - GlobalVariable.user_real_Map.remove(userId); - } + //瀛樺叆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); + if (b) { + url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName); + log.info("涓婁紶鏂囦欢鎴愬姛!" + MinioClientSingleton.domainUrl + "/" + BucketName + "/" + ObjectName); } } + return url; } catch (Exception ex) { log.error("褰曞儚寮傚父" + ex.getMessage()); + return ""; + } + } + + @Override + 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 ""; + } + Integer userId = GlobalVariable.loginMap.get(cameraId); + //寮哄埗I甯х粨鏋勪綋瀵硅薄 + HCNetSDK.NET_DVR_I_FRAME netDvrIFrame = new HCNetSDK.NET_DVR_I_FRAME(); //鏂板缓缁撴瀯浣撳璞� + netDvrIFrame.read(); + netDvrIFrame.dwChannel = channelNum;//鍥犱负涓婃枃浠g爜涓缃簡閫氶亾鍙凤紝鎸夌収涓婃枃涓殑璁剧疆 + netDvrIFrame.byStreamType = 0; + netDvrIFrame.dwSize = netDvrIFrame.size(); + netDvrIFrame.write(); + if (!hCNetSDK.NET_DVR_RemoteControl(userId, 3402, netDvrIFrame.getPointer(), netDvrIFrame.dwSize)) { + log.error("寮哄埗I甯� 閿欒鐮佷负: " + hCNetSDK.NET_DVR_GetLastError()); + } + //棰勮鍙傛暟 + NET_DVR_PREVIEWINFO previewinfo = new NET_DVR_PREVIEWINFO(); + previewinfo.read(); + previewinfo.lChannel = channelNum; + previewinfo.dwStreamType = 0;//鐮佹祦绫诲瀷锛�0-涓荤爜娴侊紝1-瀛愮爜娴侊紝2-涓夌爜娴侊紝3-铏氭嫙鐮佹祦锛屼互姝ょ被鎺� + previewinfo.dwLinkMode = 0;//杩炴帴鏂瑰紡锛�0-TCP鏂瑰紡锛�1-UDP鏂瑰紡锛�2-澶氭挱鏂瑰紡锛�3-RTP鏂瑰紡锛�4-RTP/RTSP锛�5-RTP/HTTP锛�6-HRUDP锛堝彲闈犱紶杈擄級锛�7-RTSP/HTTPS锛�8-NPQ + previewinfo.hPlayWnd = null;//鎾斁绐楀彛鐨勫彞鏌勶紝涓篘ULL琛ㄧず涓嶈В鐮佹樉绀恒�� + previewinfo.bBlocked = 0;//0- 闈為樆濉炲彇娴侊紝1-闃诲鍙栨祦 + previewinfo.byNPQMode = 0;//NPQ妯″紡锛�0-鐩磋繛妯″紡锛�1-杩囨祦濯掍綋妯″紡 + previewinfo.write(); + if (enable) { + 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 ""; + } + log.debug("褰曞儚寮�濮�"); + } else { + if (GlobalVariable.previewMap.containsKey(cameraId)) { + Integer lRealHandle = GlobalVariable.previewMap.get(cameraId); + hCNetSDK.NET_DVR_StopRealPlay(lRealHandle); + GlobalVariable.previewMap.remove(cameraId); + } + log.debug("褰曞儚鍋滄"); + //瀛樺叆minio + String BucketName = cmd.getRecordBucketName(); + String ObjectName = cmd.getRecordObjectName(); + String ContentType = "video/MP4"; + FileInputStream stream = new FileInputStream(path); + 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) { + 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