| | |
| | | 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; |
| | | //初始化SDK |
| | | @Override |
| | | public void initSDK() { |
| | | //初始化加载sdk库文件 |
| | | 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")) { |
| | | |
| | | } |
| | | } |
| | | } 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 { |
| | | //获取摄像头ID |
| | | String cameraId = cmd.getCameraId(); |
| | | //从redis中获取摄像头信息 |
| | | ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); |
| | | if (ardCamera != null) { |
| | | //获取摄像头工厂 |
| | | String factory = ardCamera.getFactory(); |
| | | if (factory.equals("1")) { |
| | | //调用hikClientService的picCutCate方法 |
| | | url = hikClientService.picCutCate(cmd); |
| | | } else if (factory.equals("2")) { |
| | | //调用dhClientService的picCutCate方法 |
| | | 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-解锁 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; |
| | | } |
| | | |
| | | /** |
| | | * @描述 操控解锁 |
| | | * @参数 [userId, channelNum] |
| | | * @返回值 boolean |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/30 15:36 |
| | | * @修改人和其它信息 |
| | | */ |
| | | @Override |
| | | public boolean controlUnLock(CameraCmd cmd) { |
| | | String cameraId = cmd.getCameraId();//申请解锁的相机 |
| | | String operator = cmd.getOperator();//申请者 |
| | | ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId); |
| | | if (ardCameras.getOperatorId().equals(operator)) { |
| | | //如果解锁相机的当前用户是申请者,则清空该相机的过期时间 |
| | | ardCameras.setOperatorExpired(null); |
| | | int i = ardCamerasService.updateArdCameras(ardCameras); |
| | | if (i > 0) { |
| | | log.debug(cameraId + "--解锁成功"); |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | //停止录像并存入minio |
| | | @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")) { |
| | | |
| | | } |
| | | } |
| | | } 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.utils.gis.GisUtil;
|
| | | import com.ruoyi.utils.gis.Point;
|
| | | import com.ruoyi.utils.sdk.common.GlobalVariable;
|
| | | import com.ruoyi.utils.tools.ArdTool;
|
| | | import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.springframework.boot.ApplicationArguments;
|
| | | import org.springframework.boot.ApplicationRunner;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import java.util.*;
|
| | |
|
| | |
|
| | | /**
|
| | | * @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;
|
| | |
|
| | | /**
|
| | | * 启动线程方法,用于执行初始化登录相机的逻辑
|
| | | *
|
| | | * @param args 命令行参数
|
| | | */
|
| | | @Override
|
| | | public void run(ApplicationArguments args) {
|
| | | try {
|
| | | // 从ardCamerasService中获取ArdCameras列表
|
| | | List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(new ArdCameras());
|
| | | for (ArdCameras camera : ardCameras) {
|
| | | asyncLogin(camera);
|
| | | }
|
| | | } catch (Exception ex) {
|
| | | // 初始化登录相机异常,记录错误日志
|
| | | log.error("初始化登录相机异常:" + ex.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | //同步登录
|
| | | @Override
|
| | | public AjaxResult login(ArdCameras ardCamera) {
|
| | | try {
|
| | | if (ardCamera == null) {
|
| | | return AjaxResult.error("登录相机失败,相机不存在");
|
| | | }
|
| | | 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.error("登录相机失败,相机不存在");
|
| | | }
|
| | | 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.pTZControl(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | }
|
| | |
|
| | | //设置聚焦值
|
| | | @Override
|
| | | public AjaxResult setFocusPos(CameraCmd cmd) {
|
| | | 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);
|
| | | return cameraSDK.setFocusPos(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.getFocusPos(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.setPreset(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.gotoPreset(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.controlDefogcfg(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.controlInfrarecfg(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.controlFocusMode(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.getFocusMode(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.controlPTHeateRpwron(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.controlCameraDeicing(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.getPTZLockInfo(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } catch (Exception ex) {
|
| | | log.error("获取云台锁定信息异常:" + ex.getMessage());
|
| | | return AjaxResult.error("获取云台锁定信息异常:" + ex.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String captureJPEGPicture(CameraCmd cmd) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | //抓图
|
| | | @Override
|
| | | public String picCutCate(CameraCmd cmd) {
|
| | | String url = "";
|
| | | try {
|
| | | //获取摄像头ID
|
| | | String cameraId = cmd.getCameraId();
|
| | | //从redis中获取摄像头信息
|
| | | 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) {
|
| | | 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);
|
| | | }
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.getPtzScope(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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.error("摄像头不存在");
|
| | | }
|
| | | 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.setZeroPtz(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } 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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.guideTargetPosition(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("摄像头不存在");
|
| | | }
|
| | | } catch (Exception ex) {
|
| | | log.error("引导指向目标异常:" + ex.getMessage());
|
| | | return AjaxResult.error("引导指向目标异常:" + ex.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | | //引导指向井
|
| | | @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.error("井不存在");
|
| | | }
|
| | | 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
|
| | | }
|
| | | //从缓存里取出距离最近相机ID
|
| | | 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("未找到ptz引导相机,查找最近相机");
|
| | |
|
| | | //从附近相机找最近的一个相机
|
| | | String cameraId = getCameraByNear(new double[]{well.getLongitude(), well.getLatitude()});
|
| | | cmd.setCameraId(cameraId);
|
| | | if ("".equals(cameraId)) {
|
| | | return AjaxResult.error("未找到引导相机");
|
| | | }
|
| | | //判断禁引区
|
| | | if (isInPolygon(cameraId, new Double[]{well.getLongitude(), well.getLatitude()})) {
|
| | | return AjaxResult.error("井位置属于相机禁止引导区域");
|
| | | }
|
| | | //按井坐标开始引导
|
| | | if (!guideTargetPosition(cmd).get("code").equals(200)) {
|
| | | return AjaxResult.error("井坐标引导失败", "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("尝试查找最近光电");
|
| | | //获取距离字典中最近的一个相机ID
|
| | | 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-解锁 1-锁定
|
| | | */
|
| | | @Override
|
| | | @SdkOperate
|
| | | public AjaxResult controlLock(CameraCmd cmd) {
|
| | | String cameraId = cmd.getCameraId();//申请锁的相机
|
| | | ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId);
|
| | | if (ardCameras == null) {
|
| | | return AjaxResult.error("设备未登录");
|
| | | }
|
| | | Date now = new Date();
|
| | | now.setTime(now.getTime() + cmd.getExpired() * 1000);
|
| | | ardCameras.setOperatorExpired(now);//设置当前过期时间
|
| | | ardCamerasService.updateArdCameras(ardCameras);
|
| | | return AjaxResult.success("操控锁定成功");
|
| | | }
|
| | |
|
| | | /**
|
| | | * @描述 操控解锁
|
| | | * @参数 [userId, channelNum]
|
| | | * @返回值 boolean
|
| | | * @创建人 刘苏义
|
| | | * @创建时间 2023/6/30 15:36
|
| | | * @修改人和其它信息
|
| | | */
|
| | | @Override
|
| | | public AjaxResult controlUnLock(CameraCmd cmd) {
|
| | | String cameraId = cmd.getCameraId();//申请解锁的相机
|
| | | String operator = cmd.getOperator();//申请者
|
| | | ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cameraId);
|
| | | if (ardCameras == null) {
|
| | | return AjaxResult.error("设备未登录");
|
| | | }
|
| | | if (ardCameras.getOperatorId().equals(operator)) {
|
| | | //如果解锁相机的当前用户是申请者,则清空该相机的过期时间
|
| | | ardCameras.setOperatorExpired(null);
|
| | | int i = ardCamerasService.updateArdCameras(ardCameras);
|
| | | if (i > 0) {
|
| | | log.debug(cameraId + "--解锁成功");
|
| | | }
|
| | | }
|
| | |
|
| | | return AjaxResult.success("操控解锁成功");
|
| | | }
|
| | |
|
| | | //录像
|
| | | @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;
|
| | | }
|
| | |
|
| | | //停止录像并存入minio
|
| | | @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) {
|
| | | String factory = ardCamera.getFactory();
|
| | | CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
| | | return cameraSDK.getGisInfo(cmd);
|
| | | } else {
|
| | | return AjaxResult.error("相机不存在");
|
| | | }
|
| | | } catch (Exception ex) {
|
| | | log.error("获取相机架设参数异常:" + ex.getMessage());
|
| | | return AjaxResult.error("获取相机架设参数异常:" + ex.getMessage());
|
| | | }
|
| | | }
|
| | | }
|