From 57c673aa3e83677bcf5d30b4b45d06bae6609db8 Mon Sep 17 00:00:00 2001 From: liusuyi <1951119284@qq.com> Date: 星期四, 08 八月 2024 16:14:40 +0800 Subject: [PATCH] 优化:获取会话 --- ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java | 1565 +++++++++++++++++++++++++++++++++------------------------ 1 files changed, 895 insertions(+), 670 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java index 88678a3..0209056 100644 --- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java +++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java @@ -1,670 +1,895 @@ -package com.ruoyi.device.camera.service.impl; - -import com.ruoyi.common.annotation.SdkOperate; -import com.ruoyi.common.constant.CacheConstants; -import com.ruoyi.common.core.redis.RedisCache; -import com.ruoyi.common.utils.file.FileUtils; -import com.ruoyi.device.camera.domain.ArdCameras; -import com.ruoyi.device.camera.domain.CameraCmd; -import com.ruoyi.device.camera.service.IArdCamerasService; -import com.ruoyi.device.camera.service.ICameraSdkService; -import com.ruoyi.device.channel.domain.ArdChannel; -import com.ruoyi.device.dhsdk.lib.NetSDKLib; -import com.ruoyi.device.dhsdk.module.RealPlayModule; -import com.ruoyi.device.dhsdk.service.IDhClientService; -import com.ruoyi.device.hiksdk.common.GlobalVariable; -import com.ruoyi.device.hiksdk.service.IHikClientService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.ruoyi.device.dhsdk.lib.ToolKits.getErrorCodePrint; -import static com.ruoyi.device.dhsdk.module.LoginModule.netsdk; -import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.NET_DVR_CHECK_USER_STATUS; - - -/** - * @Description: 鐩告満sdk涓氬姟 - * @ClassName: CameraSdkServiceImpl - * @Author: 鍒樿嫃涔� - * @Date: 2023骞�10鏈�16鏃�15:21:01 - **/ -@Service -@Slf4j(topic = "SDK") -public class CameraSdkServiceImpl implements ICameraSdkService { - @Resource - private IArdCamerasService ardCamerasService; - @Resource - IHikClientService hikClientService; - @Resource - IDhClientService dhClientService; - @Resource - RedisCache redisCache; - //鍒濆鍖朣DK - @Override - public void initSDK() { - //鍒濆鍖栧姞杞絪dk搴撴枃浠� - boolean initHIK = hikClientService.init(); - if (initHIK) { - hikClientService.loginAll();//鐧诲綍鍏ㄩ儴娴峰悍鐩告満 - } - Boolean initDH = dhClientService.init(); - if (initDH) { - dhClientService.loginAll();//鐧诲綍鍏ㄩ儴澶у崕鐩告満 - } - } - //鐧诲綍 - @Override - public Boolean login(ArdCameras ardCamera) { - boolean result = false; - try { - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - hikClientService.syncLogin(ardCamera); - result=true; - } else if (factory.equals("2")) { - result = dhClientService.login(ardCamera); - } - } - } catch (Exception ex) { - log.error("鐧诲綍寮傚父锛�" + ex.getMessage()); - return false; - } - return result; - } - //娉ㄩ攢 - @Override - public boolean logout(String cameraId) { - boolean result = false; - try { - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.logout(cameraId); - } else if (factory.equals("2")) { - result = dhClientService.logout(cameraId); - } - } - } catch (Exception ex) { - log.error("娉ㄩ攢寮傚父锛�" + ex.getMessage()); - return false; - } - return result; - } - - //鍦ㄧ嚎妫�娴� - @Override - public boolean isOnLine(CameraCmd cmd) { - try { - boolean onLine = false; - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - onLine = hikClientService.isOnLine(cmd); - } else if (factory.equals("2")) { - onLine = dhClientService.isOnLine(cmd); - } - } - return onLine; - } catch (Exception ex) { - log.error("妫�娴嬪湪绾垮紓甯革細" + ex.getMessage()); - return false; - } - } - //浜戝彴鎺у埗 - @SdkOperate - @Override - public boolean pTZControl(CameraCmd cmd) { - try { - boolean result = false; - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.pTZControlWithSpeed(cmd); - } else if (factory.equals("2")) { - result = dhClientService.pTZControl(cmd); - } - } - return result; - } catch (Exception ex) { - log.error("ptz鎺у埗寮傚父锛�" + ex.getMessage()); - return false; - } - } - //璁剧疆鑱氱劍鍊� - @Override - public boolean setFocusPos(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.setFocusPos(cmd); - } else if (factory.equals("2")) { - result = dhClientService.setFocusPos(cmd); - } - } - } catch (Exception ex) { - log.error("璁剧疆鑱氱劍鍊煎紓甯革細" + ex.getMessage()); - - } - return result; - } - //鑾峰彇鑱氱劍鍊� - @Override - public int getFocusPos(CameraCmd cmd) { - int result=0; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.getFocusPos(cmd); - } else if (factory.equals("2")) { - result = dhClientService.getFocusPos(cmd); - } - } - } catch (Exception ex) { - log.error("鑾峰彇鑱氱劍鍊煎紓甯革細" + ex.getMessage()); - } - return result; - } - //璁剧疆棰勭疆浣� - @Override - public boolean setPreset(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.setPreset(cmd); - } else if (factory.equals("2")) { - result = dhClientService.setPreset(cmd); - } - } - } catch (Exception ex) { - log.error("璁剧疆棰勭疆浣嶅紓甯革細" + ex.getMessage()); - } - return result; - } - //璋冪敤棰勭疆浣� - @Override - public boolean gotoPreset(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.gotoPreset(cmd); - } else if (factory.equals("2")) { - result = dhClientService.gotoPreset(cmd); - } - } - } catch (Exception ex) { - log.error("璋冪敤棰勭疆浣嶅紓甯革細" + ex.getMessage()); - } - return result; - } - //鑾峰彇鐮佹祦鍘嬬缉鍙傛暟 - @Override - public Map<String, Object> getVideoCompressionCfg(CameraCmd cmd) { - Map<String, Object> map = new HashMap<>(); - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - map = hikClientService.getVideoCompressionCfg(cmd); - } else if (factory.equals("2")) { - map = dhClientService.getVideoCompressionCfg(cmd); - } - } - } catch (Exception ex) { - log.error("鑾峰彇鐮佹祦鍘嬬缉鍙傛暟寮傚父锛�" + ex.getMessage()); - } - return map; - } - //閫忛浘寮�鍏� - @Override - public boolean controlDefogcfg(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.controlDefogcfg(cmd); - } else if (factory.equals("2")) { - //涓嶆敮鎸� - } - } - } catch (Exception ex) { - log.error("鎿嶆帶閫忛浘寮傚父锛�" + ex.getMessage()); - } - return result; - } - //绾㈠寮�鍏� - @Override - public boolean controlInfrarecfg(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.controlInfrarecfg(cmd); - } else if (factory.equals("2")) { - result = dhClientService.controlInfrarecfg(cmd); - } - } - } catch (Exception ex) { - log.error("鎿嶆帶绾㈠寮傚父锛�" + ex.getMessage()); - } - return result; - } - //鎵嬪姩/鑷姩鑱氱劍 - @Override - public boolean controlFocusMode(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.controlFocusMode(cmd); - } else if (factory.equals("2")) { - result = dhClientService.controlFocusMode(cmd); - } - } - } catch (Exception ex) { - log.error("鎿嶆帶鑱氱劍妯″紡寮傚父锛�" + ex.getMessage()); - } - return result; - } - //鑾峰彇鑱氱劍妯″紡 - @Override - public String getFocusMode(CameraCmd cmd) { - String result = ""; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.getFocusMode(cmd); - } else if (factory.equals("2")) { - result = dhClientService.getFocusMode(cmd); - } - } - } catch (Exception ex) { - log.error("鑾峰彇鑱氱劍妯″紡寮傚父锛�" + ex.getMessage()); - } - return result; - } - //浜戝彴鍔犵儹 - @Override - public boolean controlPTHeateRpwron(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.controlPTHeateRpwron(cmd); - } else if (factory.equals("2")) { - //涓嶆敮鎸� - } - } - } catch (Exception ex) { - log.error("鎿嶆帶浜戝彴鍔犵儹寮傚父锛�" + ex.getMessage()); - } - return result; - } - //闀滃ご鍔犵儹 - @Override - public boolean controlCameraDeicing(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.controlCameraDeicing(cmd); - } else if (factory.equals("2")) { - //涓嶆敮鎸� - } - } - } catch (Exception ex) { - log.error("鎿嶆帶浜戝彴鍔犵儹寮傚父锛�" + ex.getMessage()); - } - return result; - } - - //鑾峰彇浜戝彴閿佸畾淇℃伅 - @Override - public int getPTZLockInfo(CameraCmd cmd) { - int result = 99; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.getPTZLockInfo(cmd); - } else if (factory.equals("2")) { - - } - } - } catch (Exception ex) { - log.error("鑾峰彇浜戝彴閿佸畾淇℃伅寮傚父锛�" + ex.getMessage()); - } - return result; - } - - @Override - public String captureJPEGPicture(CameraCmd cmd) { - return null; - } - //鎶撳浘 - @SdkOperate - @Override - public String picCutCate(CameraCmd cmd) { - String url = ""; - try { - //鑾峰彇鎽勫儚澶碔D - String cameraId = cmd.getCameraId(); - //浠巖edis涓幏鍙栨憚鍍忓ご淇℃伅 - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - //鑾峰彇鎽勫儚澶村伐鍘� - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - //璋冪敤hikClientService鐨刾icCutCate鏂规硶 - url = hikClientService.picCutCate(cmd); - } else if (factory.equals("2")) { - //璋冪敤dhClientService鐨刾icCutCate鏂规硶 - url = dhClientService.picCutCate(cmd); - } - } - } catch (Exception ex) { - log.error("鎶撳浘寮傚父锛�" + ex.getMessage()); - } - return url; - } - //鑾峰彇ptz - @Override - public Map<String, Object> getPtz(CameraCmd cmd) { - Map<String, Object> map = new HashMap<>(); - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - map = hikClientService.getPtz(cmd); - } else if (factory.equals("2")) { - map = dhClientService.getPtz(cmd); - } - } - } catch (Exception ex) { - log.error("鑾峰彇ptz寮傚父锛�" + ex.getMessage()); - } - return map; - } - //鑾峰彇ptz鑼冨洿 - @Override - public Map<String, Object> getPtzScope(CameraCmd cmd) { - Map<String, Object> map = new HashMap<>(); - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - map = hikClientService.getPtzScope(cmd); - } else if (factory.equals("2")) { - - } - } - } catch (Exception ex) { - log.error("鑾峰彇ptz鑼冨洿寮傚父锛�" + ex.getMessage()); - } - return map; - } - //璁剧疆ptz - @SdkOperate - @Override - public boolean setPtz(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.setPtz(cmd); - } else if (factory.equals("2")) { - result = dhClientService.setPtz(cmd); - } - } - } catch (Exception ex) { - log.error("璁剧疆ptz寮傚父锛�" + ex.getMessage()); - } - return result; - } - //璁剧疆闆舵柟浣嶈 - @SdkOperate - @Override - public boolean setZeroPtz(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.setZeroPtz(cmd); - } else if (factory.equals("2")) { - result = dhClientService.setZeroPtz(cmd); - } - } - } catch (Exception ex) { - log.error("璁剧疆闆舵柟浣嶈寮傚父锛�" + ex.getMessage()); - } - return result; - } - //寮曞鎸囧悜鐩爣 - @SdkOperate - @Override - public boolean guideTargetPosition(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.guideTargetPosition(cmd); - } else if (factory.equals("2")) { - result = dhClientService.guideTargetPosition(cmd); - } - } - } catch (Exception ex) { - log.error("寮曞鎸囧悜鐩爣寮傚父锛�" + ex.getMessage()); - } - return result; - } - - /** - * @鎻忚堪 鎿嶆帶閿佸畾 - * @鍙傛暟 [userId, channelNum] - * @杩斿洖鍊� boolean - * @鍒涘缓浜� 鍒樿嫃涔� - * @鍒涘缓鏃堕棿 2023/1/17 16:36 - * @淇敼浜哄拰鍏跺畠淇℃伅 0-瑙i攣 1-閿佸畾 - */ - @Override - @SdkOperate - public boolean controlLock(CameraCmd cmd) { - String cameraId = cmd.getCameraId();//鐢宠閿佺殑鐩告満 - ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId); - Date now = new Date(); - now.setTime(now.getTime() + cmd.getExpired() * 1000); - ardCameras.setOperatorExpired(now);//璁剧疆褰撳墠杩囨湡鏃堕棿 - ardCamerasService.updateArdCameras(ardCameras); - return true; - } - - /** - * @鎻忚堪 鎿嶆帶瑙i攣 - * @鍙傛暟 [userId, channelNum] - * @杩斿洖鍊� boolean - * @鍒涘缓浜� 鍒樿嫃涔� - * @鍒涘缓鏃堕棿 2023/6/30 15:36 - * @淇敼浜哄拰鍏跺畠淇℃伅 - */ - @Override - public boolean controlUnLock(CameraCmd cmd) { - String cameraId = cmd.getCameraId();//鐢宠瑙i攣鐨勭浉鏈� - String operator = cmd.getOperator();//鐢宠鑰� - ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId); - if (ardCameras.getOperatorId().equals(operator)) { - //濡傛灉瑙i攣鐩告満鐨勫綋鍓嶇敤鎴锋槸鐢宠鑰咃紝鍒欐竻绌鸿鐩告満鐨勮繃鏈熸椂闂� - ardCameras.setOperatorExpired(null); - int i = ardCamerasService.updateArdCameras(ardCameras); - if (i > 0) { - log.debug(cameraId + "--瑙i攣鎴愬姛"); - } - } - return true; - } - - - //褰曞儚 - @SdkOperate - @Override - public String record(CameraCmd cmd) { - String url = ""; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - url = hikClientService.record(cmd); - } else if (factory.equals("2")) { - url = dhClientService.record(cmd); - } - } - } catch (Exception ex) { - log.error("褰曞儚寮傚父锛�" + ex.getMessage()); - } - return url; - } - - //寮�濮嬪綍鍍� - @Override - public boolean recordStart(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.recordStart(cmd); - } else if (factory.equals("2")) { - result = dhClientService.recordStart(cmd); - } - } - } catch (Exception ex) { - log.error("寮�濮嬪綍鍍忓紓甯革細" + ex.getMessage()); - } - return result; - } - //鍋滄褰曞儚骞跺瓨鍏inio - @Override - public String recordStopToMinio(CameraCmd cmd) { - String url = ""; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - url = hikClientService.recordStopToMinio(cmd); - } else if (factory.equals("2")) { - url = dhClientService.recordStopToMinio(cmd); - } - } - } catch (Exception ex) { - log.error("鍋滄褰曞儚寮傚父锛�" + ex.getMessage()); - } - return url; - } - //鍋滄褰曞儚骞朵笉瀛樺叆minio - @Override - public boolean recordStopNotToMinio(CameraCmd cmd) { - boolean result = false; - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - result = hikClientService.recordStopNotToMinio(cmd); - } else if (factory.equals("2")) { - result = dhClientService.recordStopNotToMinio(cmd); - } - } - } catch (Exception ex) { - log.error("鍋滄褰曞儚寮傚父锛�" + ex.getMessage()); - } - return result; - } - - //鑾峰彇鐩告満鏋惰鍙傛暟 - @Override - public Map<String, Object> getGisInfo(CameraCmd cmd) { - Map<String, Object> map = new HashMap<>(); - try { - String cameraId = cmd.getCameraId(); - ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); - if (ardCamera != null) { - String factory = ardCamera.getFactory(); - if (factory.equals("1")) { - map = hikClientService.getGisInfo(cmd); - } else if (factory.equals("2")) { - map = dhClientService.getGisInfo(cmd); - } - } - } catch (Exception ex) { - log.error("鑾峰彇鐩告満鏋惰鍙傛暟寮傚父锛�" + ex.getMessage()); - } - return map; - } -} +package com.ruoyi.device.camera.service.impl; + +import com.ruoyi.alarm.global.domain.GuidePoint; +import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; +import com.ruoyi.alarmpoints.well.domain.ArdWellGuideCamera; +import com.ruoyi.alarmpoints.well.service.IArdAlarmpointsWellService; +import com.ruoyi.common.annotation.SdkOperate; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.device.camera.domain.ArdCameras; +import com.ruoyi.device.camera.domain.CameraCmd; +import com.ruoyi.device.camera.service.IArdCamerasService; +import com.ruoyi.device.camera.service.ICameraSdkService; +import com.ruoyi.device.camera.factory.CameraSDK; +import com.ruoyi.device.camera.factory.CameraSDKFactory; +import com.ruoyi.device.noguidezone.domain.ArdCameraNoGuideZone; +import com.ruoyi.device.noguidezone.service.IArdCameraNoGuideZoneService; +import com.ruoyi.device.terrain.domain.ArdTerrainMark; +import com.ruoyi.device.terrain.service.IArdTerrainMarkService; +import com.ruoyi.utils.gis.GisUtil; +import com.ruoyi.utils.gis.Point; +import com.ruoyi.utils.sdk.common.GlobalVariable; +import com.ruoyi.utils.tools.ArdTool; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + + +/** + * @Description: 鐩告満sdk涓氬姟 + * @ClassName: CameraSdkServiceImpl + * @Author: 鍒樿嫃涔� + * @Date: 2023骞�10鏈�16鏃�15:21:01 + **/ +@Service +@Slf4j(topic = "sdk") +public class CameraSdkServiceImpl implements ICameraSdkService, ApplicationRunner { + @Resource + private IArdCamerasService ardCamerasService; + @Resource + private RedisCache redisCache; + @Resource + private CameraSDKFactory cameraSDKFactory; + @Resource + private IArdAlarmpointsWellService ardAlarmpointsWellService; + @Resource + private IArdCameraNoGuideZoneService ardCameraNoGuideZoneService; + @Resource + private IArdTerrainMarkService ardTerrainMarkService; + + /** + * 鍚姩绾跨▼鏂规硶锛岀敤浜庢墽琛屽垵濮嬪寲鐧诲綍鐩告満鐨勯�昏緫 + * + * @param args 鍛戒护琛屽弬鏁� + */ + @Override + public void run(ApplicationArguments args) { + try { + log.info("鍒濆鍖栫櫥褰曠浉鏈哄紑濮�"); + ardCamerasService.resetCameraLoginId(); + List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(new ArdCameras()); + ardCameras.stream().forEach(ardCamera -> asyncLogin(ardCamera)); + } catch (Exception ex) { + log.error("鍒濆鍖栫櫥褰曠浉鏈哄紓甯革細" + ex.getMessage()); + } + } + + //鍚屾鐧诲綍 + @Override + public AjaxResult login(ArdCameras ardCamera) { + try { + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.login(ardCamera);//鍚屾鐧诲綍 + } catch (Exception ex) { + log.error("鐧诲綍寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鐧诲綍寮傚父锛�" + ex.getMessage()); + } + } + + @Override + public AjaxResult asyncLogin(ArdCameras ardCamera) { + try { + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.asyncLogin(ardCamera);//寮傛鐧诲綍 + } catch (Exception ex) { + log.error("鐧诲綍寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鐧诲綍寮傚父锛�" + ex.getMessage()); + } + } + + //娉ㄩ攢 + @Override + public boolean logout(String cameraId) { + boolean result = false; + try { + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + result = cameraSDK.logout(cameraId); + } + } catch (Exception ex) { + log.error("娉ㄩ攢寮傚父锛�" + ex.getMessage()); + return false; + } + return result; + } + + //鍦ㄧ嚎妫�娴� + @Override + public boolean isOnLine(CameraCmd cmd) { + try { + boolean onLine = false; + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + onLine = cameraSDK.isOnLine(cmd); + } + return onLine; + } catch (Exception ex) { + log.error("妫�娴嬪湪绾垮紓甯革細" + ex.getMessage()); + return false; + } + } + + //浜戝彴鎺у埗 + @Override + public AjaxResult pTZControl(CameraCmd cmd) { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.pTZControl(cmd); + } + + //璁剧疆鑱氱劍鍊� + @Override + public AjaxResult setFocusPos(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.setFocusPos(cmd); + } catch (Exception ex) { + log.error("璁剧疆鑱氱劍鍊煎紓甯革細" + ex.getMessage()); + return AjaxResult.error("璁剧疆鑱氱劍鍊煎紓甯革細" + ex.getMessage()); + } + } + + //鑾峰彇鑱氱劍鍊� + @Override + public AjaxResult getFocusPos(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.getFocusPos(cmd); + } catch (Exception ex) { + log.error("鑾峰彇鑱氱劍鍊煎紓甯革細" + ex.getMessage()); + return AjaxResult.error("鑾峰彇鑱氱劍鍊煎紓甯�:" + ex.getMessage()); + } + } + + //璁剧疆棰勭疆浣� + @Override + public AjaxResult setPreset(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.setPreset(cmd); + } catch (Exception ex) { + log.error("璁剧疆棰勭疆浣嶅紓甯革細" + ex.getMessage()); + return AjaxResult.error("璁剧疆棰勭疆浣嶅紓甯�" + ex.getMessage()); + } + } + + //璋冪敤棰勭疆浣� + @Override + public AjaxResult gotoPreset(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.gotoPreset(cmd); + } catch (Exception ex) { + log.error("璋冪敤棰勭疆浣嶅紓甯革細" + ex.getMessage()); + return AjaxResult.error("璋冪敤棰勭疆浣嶅紓甯�" + ex.getMessage()); + } + } + + //鑾峰彇鐮佹祦鍘嬬缉鍙傛暟 + @Override + public Map<String, Object> getVideoCompressionCfg(CameraCmd cmd) { + Map<String, Object> map = new HashMap<>(); + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return new HashMap<>(); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + map = cameraSDK.getVideoCompressionCfg(cmd); + } catch (Exception ex) { + log.error("鑾峰彇鐮佹祦鍘嬬缉鍙傛暟寮傚父锛�" + ex.getMessage()); + } + return map; + } + + //閫忛浘寮�鍏� + @Override + public AjaxResult controlDefogcfg(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.controlDefogcfg(cmd); + } catch (Exception ex) { + log.error("鎿嶆帶閫忛浘寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鎿嶆帶閫忛浘寮傚父" + ex.getMessage()); + } + } + + //绾㈠寮�鍏� + @Override + public AjaxResult controlInfrarecfg(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.controlInfrarecfg(cmd); + } catch (Exception ex) { + log.error("鎿嶆帶绾㈠寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鎿嶆帶绾㈠寮傚父:" + ex.getMessage()); + } + } + + //鎵嬪姩/鑷姩鑱氱劍 + @Override + public AjaxResult controlFocusMode(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.controlFocusMode(cmd); + } catch (Exception ex) { + log.error("鎿嶆帶鑱氱劍妯″紡寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鎿嶆帶鑱氱劍妯″紡寮傚父:" + ex.getMessage()); + } + } + + //鑾峰彇鑱氱劍妯″紡 + @Override + public AjaxResult getFocusMode(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.getFocusMode(cmd); + } catch (Exception ex) { + log.error("鑾峰彇鑱氱劍妯″紡寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鑾峰彇鑱氱劍妯″紡寮傚父锛�" + ex.getMessage()); + } + } + + //浜戝彴鍔犵儹 + @Override + public AjaxResult controlPTHeateRpwron(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.controlPTHeateRpwron(cmd); + } catch (Exception ex) { + log.error("鎿嶆帶浜戝彴鍔犵儹寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鎿嶆帶浜戝彴鍔犵儹寮傚父:" + ex.getMessage()); + } + } + + //闀滃ご鍔犵儹 + @Override + public AjaxResult controlCameraDeicing(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.controlCameraDeicing(cmd); + } catch (Exception ex) { + log.error("鎿嶆帶浜戝彴鍔犵儹寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鎿嶆帶浜戝彴鍔犵儹寮傚父锛�" + ex.getMessage()); + } + } + + //鑾峰彇浜戝彴閿佸畾淇℃伅 + @Override + public AjaxResult getPTZLockInfo(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.getPTZLockInfo(cmd); + } catch (Exception ex) { + log.error("鑾峰彇浜戝彴閿佸畾淇℃伅寮傚父:" + ex.getMessage()); + return AjaxResult.error("鑾峰彇浜戝彴閿佸畾淇℃伅寮傚父:" + ex.getMessage()); + } + } + + //鏈湴鎶撳浘 + @Override + public AjaxResult localCapture(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.localCapture(cmd); + } catch (Exception ex) { + log.error("鎵嬪姩鎶撳浘寮傚父:" + ex.getMessage()); + return AjaxResult.error("鎵嬪姩鎶撳浘寮傚父:" + ex.getMessage()); + } + } + + //鎶撳浘 + @Override + public String picCutCate(CameraCmd cmd) { + String url = ""; + try { + //鑾峰彇鎽勫儚澶碔D + String cameraId = cmd.getCameraId(); + //浠巖edis涓幏鍙栨憚鍍忓ご淇℃伅 + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + //鑾峰彇鎽勫儚澶村伐鍘� + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + url = cameraSDK.picCutCate(cmd); + } + } catch (Exception ex) { + log.error("鎶撳浘寮傚父锛�" + ex.getMessage()); + } + return url; + } + + //鑾峰彇ptz + @Override + public AjaxResult getPtz(CameraCmd cmd) { + Map<String, Object> map = new HashMap<>(); + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + String gdtype = ardCamera.getGdtype(); + if (gdtype.equals("1")) { + return cameraSDK.getPtzHigh(cmd); + } else { + return cameraSDK.getPtz(cmd); + } + } catch (Exception ex) { + log.error("鑾峰彇ptz寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鑾峰彇ptz寮傚父锛�" + ex.getMessage()); + } + } + + //鑾峰彇ptz鑼冨洿 + @Override + public AjaxResult getPtzScope(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.getPtzScope(cmd); + } catch (Exception ex) { + log.error("鑾峰彇ptz鑼冨洿寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鑾峰彇ptz鑼冨洿寮傚父锛�" + ex.getMessage()); + } + } + + //璁剧疆ptz + @Override + public AjaxResult setPtz(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(ardCamera.getFactory()); + String gdtype = ardCamera.getGdtype(); + if (gdtype.equals("1")) { + //澶у厜鐢典娇鐢ㄩ珮绮惧害ptz璁剧疆 + return cameraSDK.setPtzHigh(cmd); + } else { + return cameraSDK.setPtz(cmd); + } + } catch (Exception ex) { + log.error("璁剧疆ptz寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("璁剧疆ptz寮傚父:" + ex.getMessage()); + } + } + + //璁剧疆闆舵柟浣嶈 + @Override + public AjaxResult setZeroPtz(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.setZeroPtz(cmd); + } catch (Exception ex) { + log.error("璁剧疆闆舵柟浣嶈寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("璁剧疆闆舵柟浣嶈寮傚父锛�" + ex.getMessage()); + } + } + + //寮曞鎸囧悜鐩爣 + @Override + public AjaxResult guideTargetPosition(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.guideTargetPosition(cmd); + } catch (Exception ex) { + log.error("寮曞鎸囧悜鐩爣寮傚父:" + ex.getMessage()); + return AjaxResult.error("寮曞鎸囧悜鐩爣寮傚父:" + ex.getMessage()); + } + } + + /** + * @return + * @Author 鍒樿嫃涔� + * @Description 淇淇话鍊硷紙鏍规嵁鐩告満ID鑾峰彇500绫宠寖鍥村唴鐨勫湴褰㈠弬鏁伴泦鍚堬紝璁$畻骞冲潎鍊煎姞涓奣鍊硷級 + * @Date 2024/6/22 11:16 + * @Param + */ + @Override + public Double correctPitch(CameraCmd cmd) { + Double pitchAngle = 0.0; + try { + double[] targetPositions = cmd.getTargetPosition(); + ArdTerrainMark ardTerrainMark = new ArdTerrainMark(); + ardTerrainMark.setCameraId(cmd.getCameraId()); + List<ArdTerrainMark> ardTerrainMarks = ardTerrainMarkService.selectArdTerrainMarkList(ardTerrainMark); + //杩囨护500绫宠寖鍥村唴鐨勯泦鍚� + ardTerrainMarks = ardTerrainMarks.stream().filter(n -> GisUtil.getDistance(targetPositions, new double[]{n.getLongitude(), n.getLatitude(), n.getAltitude()}) <= 500).collect(Collectors.toList()); + //璁$畻T骞冲潎鍊� + OptionalDouble averageT = ardTerrainMarks.stream().mapToDouble(ArdTerrainMark::getT).average(); + // 杈撳嚭 + if (averageT.isPresent()) { + pitchAngle = averageT.getAsDouble(); + log.debug("淇淇话鍊硷細" + pitchAngle); + } + } catch (Exception ex) { + log.error("淇淇话鍊煎紓甯革細" + ex.getMessage()); + + } + return pitchAngle; + } + + //寮曞鎸囧悜浜� + @Override + public AjaxResult guideTargetWell(CameraCmd cmd) { + + //鎸夋棩澶滃垏鎹㈤厤缃幏鍙栫浉鏈洪�氶亾 + Integer chanNo = ArdTool.getChannelBydayNightTime(redisCache.getCacheObject("sys_config:dayNightTime")); + cmd.setChanNo(chanNo); + + //鑾峰彇浜� + ArdAlarmpointsWell well = ardAlarmpointsWellService.selectArdAlarmpointsWellById(cmd.getWellId()); + if (well == null) { + return AjaxResult.warn("浜曚笉瀛樺湪"); + } + GuidePoint guidePoint = new GuidePoint().setLongitude(well.getLongitude()).setLatitude(well.getLatitude()); + cmd.setTargetPosition(new double[]{guidePoint.getLongitude(), guidePoint.getLatitude()}); + + //鑾峰彇浜曢厤缃殑寮曞鐩告満鍒楄〃 + List<ArdWellGuideCamera> ardWellGuideCameraList = well.getArdWellGuideCameraList(); + if (ardWellGuideCameraList != null && ardWellGuideCameraList.size() > 0) { + //鑾峰彇鐩告満鍜屼簳鐨勮窛绂昏繘琛屾帓搴忥紝鍙栧嚭鏈�杩戠殑涓�涓浉鏈� + Map<String, Double> distanceMap = new HashMap<>(); + for (ArdWellGuideCamera ardWellGuideCamera : ardWellGuideCameraList) { + ArdCameras cameras = ardCamerasService.selectArdCamerasById(ardWellGuideCamera.getCameraId()); + if (cameras == null) { + continue; + } + double[] targetPosition = new double[]{well.getLongitude(), well.getLatitude()}; + double[] camPosition = new double[]{cameras.getLongitude(), cameras.getLatitude()}; + double distance = GisUtil.getDistance(targetPosition, camPosition); + distanceMap.put(ardWellGuideCamera.getCameraId(), distance);//瀛樺叆缂撳瓨map + } + //浠庣紦瀛橀噷鍙栧嚭璺濈鏈�杩戠浉鏈篒D + String cameraId = ArdTool.getKeyByMinValue(distanceMap); + cmd.setCameraId(cameraId); + //鑾峰彇鏈�杩戠浉鏈虹殑瀵硅薄 + Optional<ArdWellGuideCamera> first = ardWellGuideCameraList.stream().filter(s -> s.getCameraId().equals(cameraId)).findFirst(); + if (first.isPresent()) { + ArdWellGuideCamera ardWellGuideCamera = first.get(); + Map<String, Double> ptzMap = null; + //閫氳繃閫氶亾鑾峰彇棰勭疆浣� + switch (chanNo) { + case 1: + if (ardWellGuideCamera.getP1() != null) { + ptzMap = new HashMap<>(); + ptzMap.put("p", ardWellGuideCamera.getP1()); + ptzMap.put("t", ardWellGuideCamera.getT1()); + ptzMap.put("z", ardWellGuideCamera.getZ1()); + } + break; + case 2: + if (ardWellGuideCamera.getP2() != null) { + ptzMap = new HashMap<>(); + ptzMap.put("p", ardWellGuideCamera.getP2()); + ptzMap.put("t", ardWellGuideCamera.getT2()); + ptzMap.put("z", ardWellGuideCamera.getZ2()); + } + break; + + } + //寮曞 + if (ptzMap != null) { + //浣跨敤ptz寮曞 + cmd.setPtzMap(ptzMap); + return setPtz(cmd); + } + } + + } + log.debug("鏈壘鍒皃tz寮曞鐩告満,鏌ユ壘鏈�杩戠浉鏈�"); + + //浠庨檮杩戠浉鏈烘壘鏈�杩戠殑涓�涓浉鏈� + String cameraId = getCameraByNear(new double[]{well.getLongitude(), well.getLatitude()}); + cmd.setCameraId(cameraId); + if ("".equals(cameraId)) { + return AjaxResult.warn("鏈壘鍒板紩瀵肩浉鏈�"); + } + //鍒ゆ柇绂佸紩鍖� + if (isInPolygon(cameraId, new Double[]{well.getLongitude(), well.getLatitude()})) { + return AjaxResult.warn("浜曚綅缃睘浜庣浉鏈虹姝㈠紩瀵煎尯鍩�"); + } + //鎸変簳鍧愭爣寮�濮嬪紩瀵� + if (!guideTargetPosition(cmd).get("code").equals(200)) { + return AjaxResult.warn("浜曞潗鏍囧紩瀵煎け璐�", "cameraId:" + cameraId); + } + return AjaxResult.success("浜曞潗鏍囧紩瀵兼垚鍔�", "cameraId:" + cameraId); + + } + + /** + * 鑾峰彇鏈�杩戣窛绂荤殑鍏夌數 + * 1-鐩告満鍦ㄧ嚎 + * 2-寮�鍚姤璀﹀紩瀵煎姛鑳� + * 3-閰嶇疆浜嗘渶澶у彲瑙嗚窛绂� + */ + private String getCameraByNear(double[] targetPosition) { + String minDistanceCameraId = ""; + try { + //鑾峰彇鎵�鏈夊ぇ鍏夌數 + List<Object> Objects = redisCache.getListKey(CacheConstants.CAMERA_LIST_KEY); + //缁熻鎵�鏈夊ぇ鍏夌數鍙鑼冨洿鍐呬笌鎶ヨ鐐圭殑璺濈 + Map<String, Double> distanceMap = new HashMap<>(); + for (Object obj : Objects) { + ArdCameras camera = (ArdCameras) obj; + + if (!GlobalVariable.loginMap.containsKey(camera.getId())) { + log.debug("璇ュ厜鐢垫湭鐧诲綍"); + continue; + } + if (camera.getCamMaxVisibleDistance() == null) { + log.debug("璇ュ厜鐢垫湭閰嶇疆鏈�澶у彲瑙嗚窛绂�"); + continue; + } + if (camera.getCamAlarmGuideEnable().equals(0)) { + log.debug("璇ュ厜鐢垫湭寮�鍚姤璀﹀紩瀵�"); + continue; + } + + double[] camPosition = new double[]{camera.getLongitude(), camera.getLatitude()}; + double distance = GisUtil.getDistance(targetPosition, camPosition); + if (distance != 0.0 && distance <= camera.getCamMaxVisibleDistance()) { + distanceMap.put(camera.getId(), distance); + if (StringUtils.isNull(camera.getCamAlarmGuideEnable())) { + camera.setCamAlarmGuideEnable(0); + } + } + } + if (distanceMap.size() > 0) { + log.debug("灏濊瘯鏌ユ壘鏈�杩戝厜鐢�"); + //鑾峰彇璺濈瀛楀吀涓渶杩戠殑涓�涓浉鏈篒D + minDistanceCameraId = ArdTool.getKeyByMinValue(distanceMap); + log.debug("鏌ユ壘鍒版渶杩戝厜鐢�:" + minDistanceCameraId); + } + } catch (Exception ex) { + log.error("鑾峰彇闄勮繎寮�鍚姤璀﹀紩瀵煎姛鑳藉厜鐢靛紓甯�:" + ex.getMessage()); + } + return minDistanceCameraId; + } + + //鍒ゆ柇鐩告満鍜屽紩瀵间綅缃槸鍚﹀湪绂佹寮曞鍖哄煙 + public boolean isInPolygon(String cameraId, Double[] targetPosition) { + boolean result = false; + //鎷︽埅鎵嬪姩寮曞 + ArdCameraNoGuideZone ardCameraNoGuideZone = new ArdCameraNoGuideZone(); + ardCameraNoGuideZone.setCameraId(cameraId); + ardCameraNoGuideZone.setEnabled("1"); + //鑾峰彇褰撳墠鐩告満鐨勭寮曞彲瑙嗗煙鍒楄〃 + List<ArdCameraNoGuideZone> ardCameraNoGuideZones = ardCameraNoGuideZoneService.selectArdCameraNoGuideZoneList(ardCameraNoGuideZone); + if (ardCameraNoGuideZones.size() > 0) { + //鑾峰彇鍒板綋鍓嶇浉鏈虹殑鍧愭爣闆嗗悎 + for (ArdCameraNoGuideZone zone : ardCameraNoGuideZones) { + String[] parts = zone.getPoi().split(","); + List<Point> pointList = new ArrayList<>(); + for (int i = 0; i < parts.length; i += 3) { + Point point = new Point(); + point.setLongitude(Double.valueOf(parts[i])); + point.setLatitude(Double.valueOf(parts[i + 1])); + pointList.add(point); + } + double lon = targetPosition[0]; + double lat = targetPosition[1]; + Point targetPoint = new Point(lon, lat); + //鍒ゆ柇寮曞鐩爣鏄惁鍦ㄥ潗鏍囬泦鍚堢粍鎴愮殑澶氳竟褰㈠唴 + boolean inPolygon = GisUtil.isInPolygon(targetPoint, pointList); + if (inPolygon) { + result = inPolygon; + } + } + } + return result; + } + + /** + * @鎻忚堪 鎿嶆帶閿佸畾 + * @鍙傛暟 [userId, channelNum] + * @杩斿洖鍊� boolean + * @鍒涘缓浜� 鍒樿嫃涔� + * @鍒涘缓鏃堕棿 2023/1/17 16:36 + * @淇敼浜哄拰鍏跺畠淇℃伅 0-瑙i攣 1-閿佸畾 + */ + @Override + @SdkOperate + public AjaxResult controlLock(CameraCmd cmd) { + String cameraId = cmd.getCameraId();//鐢宠閿佺殑鐩告満 + ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId); + if (ardCameras == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + Date now = new Date(); + now.setTime(now.getTime() + cmd.getExpired() * 1000); + ardCameras.setOperatorExpired(now);//璁剧疆褰撳墠杩囨湡鏃堕棿 + ardCamerasService.updateArdCameras(ardCameras); + return AjaxResult.success("鎿嶆帶閿佸畾鎴愬姛"); + } + + /** + * @鎻忚堪 鎿嶆帶瑙i攣 + * @鍙傛暟 [userId, channelNum] + * @杩斿洖鍊� boolean + * @鍒涘缓浜� 鍒樿嫃涔� + * @鍒涘缓鏃堕棿 2023/6/30 15:36 + * @淇敼浜哄拰鍏跺畠淇℃伅 + */ + @Override + public AjaxResult controlUnLock(CameraCmd cmd) { + String cameraId = cmd.getCameraId();//鐢宠瑙i攣鐨勭浉鏈� + String operator = cmd.getOperator();//鐢宠鑰� + ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId); + if (ardCameras == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + if (ardCameras.getOperatorId().equals(operator)) { + //濡傛灉瑙i攣鐩告満鐨勫綋鍓嶇敤鎴锋槸鐢宠鑰咃紝鍒欐竻绌鸿鐩告満鐨勮繃鏈熸椂闂� + ardCameras.setOperatorExpired(null); + int i = ardCamerasService.updateArdCameras(ardCameras); + if (i > 0) { + log.debug(cameraId + "--瑙i攣鎴愬姛"); + } + } + + return AjaxResult.success("鎿嶆帶瑙i攣鎴愬姛"); + } + + //褰曞儚 + @SdkOperate + @Override + public String record(CameraCmd cmd) { + String url = ""; + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + url = cameraSDK.record(cmd); + } + } catch (Exception ex) { + log.error("褰曞儚寮傚父锛�" + ex.getMessage()); + } + return url; + } + + //寮�濮嬪綍鍍� + @Override + public boolean recordStart(CameraCmd cmd) { + boolean result = false; + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + result = cameraSDK.recordStart(cmd); + } + } catch (Exception ex) { + log.error("寮�濮嬪綍鍍忓紓甯革細" + ex.getMessage()); + } + return result; + } + + //鍋滄褰曞儚骞跺瓨鍏inio + @Override + public String recordStopToMinio(CameraCmd cmd) { + String url = ""; + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + url = cameraSDK.recordStopToMinio(cmd); + } + } catch (Exception ex) { + log.error("鍋滄褰曞儚寮傚父锛�" + ex.getMessage()); + } + return url; + } + + //鍋滄褰曞儚骞朵笉瀛樺叆minio + @Override + public boolean recordStopNotToMinio(CameraCmd cmd) { + boolean result = false; + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera != null) { + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + result = cameraSDK.recordStopNotToMinio(cmd); + } + } catch (Exception ex) { + log.error("鍋滄褰曞儚寮傚父锛�" + ex.getMessage()); + } + return result; + } + + //鑾峰彇鐩告満鏋惰鍙傛暟 + @Override + public AjaxResult getGisInfo(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.getGisInfo(cmd); + } catch (Exception ex) { + log.error("鑾峰彇鐩告満鏋惰鍙傛暟寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鑾峰彇鐩告満鏋惰鍙傛暟寮傚父锛�" + ex.getMessage()); + } + } + + //鏈湴褰曞儚寮�濮� + @Override + public AjaxResult localRecordStart(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.localRecordStart(cmd); + } catch (Exception ex) { + log.error("鏈湴褰曞儚寮�濮嬪紓甯革細" + ex.getMessage()); + return AjaxResult.error("鏈湴褰曞儚寮�濮嬪紓甯革細" + ex.getMessage()); + } + } + + //鏈湴褰曞儚鍋滄 + @Override + public AjaxResult localRecordStop(CameraCmd cmd) { + try { + String cameraId = cmd.getCameraId(); + ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); + if (ardCamera == null) { + return AjaxResult.warn("璁惧涓嶅瓨鍦�"); + } + String factory = ardCamera.getFactory(); + CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); + return cameraSDK.localRecordStop(cmd); + } catch (Exception ex) { + log.error("鏈湴褰曞儚鍋滄寮傚父锛�" + ex.getMessage()); + return AjaxResult.error("鏈湴褰曞儚鍋滄寮傚父锛�" + ex.getMessage()); + } + } +} -- Gitblit v1.9.3