| | |
| | | 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 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; |
| | | |
| | | |
| | |
| | | @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库文件 |
| | |
| | | dhClientService.loginAll();//登录全部大华相机 |
| | | } |
| | | } |
| | | |
| | | //登录 |
| | | @Override |
| | | public void syncLogin(ArdCameras cameras) { |
| | | |
| | | 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 void asyncLogin(ArdCameras cameras) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void loginAll() { |
| | | |
| | | } |
| | | |
| | | //注销 |
| | | @Override |
| | | public boolean logout(String cameraId) { |
| | | return false; |
| | | 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 { |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //云台控制 |
| | | @SdkOperate |
| | | @Override |
| | | public boolean pTZControl(CameraCmd cmd) { |
| | | try { |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //设置聚焦值 |
| | | @Override |
| | | public boolean setFocusPos(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.setFocusPos(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | result = dhClientService.setFocusPos(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | //获取聚焦值 |
| | | @Override |
| | | public Map<String, Object> getFocusPos(CameraCmd cmd) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | 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")) { |
| | | map = hikClientService.getFocusPos(cmd); |
| | | result = hikClientService.getFocusPos(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | result = dhClientService.getFocusPos(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("获取聚焦值异常:" + ex.getMessage()); |
| | | } |
| | | return map; |
| | | return result; |
| | | } |
| | | |
| | | //设置预置位 |
| | | @Override |
| | | public boolean setPreset(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.setPreset(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | result = dhClientService.setPreset(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //调用预置位 |
| | | @Override |
| | | public boolean gotoPreset(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.gotoPreset(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | result = dhClientService.gotoPreset(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //获取码流压缩参数 |
| | | @Override |
| | | public Map<String, String> getVideoCompressionCfg(CameraCmd cmd) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | 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 (factory.equals("1")) { |
| | | map = hikClientService.getVideoCompressionCfg(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | map = dhClientService.getVideoCompressionCfg(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | //透雾开关 |
| | | @Override |
| | | public boolean controlDefogcfg(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.controlDefogcfg(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | //不支持 |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //红外开关 |
| | | @Override |
| | | public boolean controlInfrarecfg(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.controlInfrarecfg(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | result = dhClientService.controlInfrarecfg(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | //手动/自动聚焦 |
| | | @Override |
| | | public boolean controlFocusMode(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.controlFocusMode(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | result = dhClientService.controlFocusMode(cmd); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //获取聚焦模式 |
| | | @Override |
| | | public String getFocusMode(CameraCmd cmd) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //云台加热 |
| | | @Override |
| | | public boolean controlPTHeateRpwron(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.controlPTHeateRpwron(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | //不支持 |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //镜头加热 |
| | | @Override |
| | | public boolean controlCameraDeicing(CameraCmd cmd) { |
| | |
| | | if (factory.equals("1")) { |
| | | result = hikClientService.controlCameraDeicing(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | //不支持 |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("操控云台加热异常:" + ex.getMessage()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //操控锁定 |
| | | @Override |
| | | public boolean controlLock(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.controlLock(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("操控锁定异常:" + ex.getMessage()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | //设置解锁 |
| | | @Override |
| | | public boolean controlUnLock(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.controlUnLock(cmd); |
| | | } else if (factory.equals("2")) { |
| | | |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("设置解锁异常:" + ex.getMessage()); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | public String captureJPEGPicture(CameraCmd cmd) { |
| | | return null; |
| | | } |
| | | |
| | | //抓图 |
| | | @SdkOperate |
| | | @Override |
| | | public String picCutCate(CameraCmd cmd) { |
| | | String url = ""; |
| | | 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); |
| | | } |
| | | } |
| | |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | //获取ptz范围 |
| | | @Override |
| | | public Map<String, Object> getPtzScope(CameraCmd cmd) { |
| | |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | //设置ptz |
| | | @SdkOperate |
| | | @Override |
| | | public boolean setPtz(CameraCmd cmd) { |
| | | boolean result = false; |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //设置零方位角 |
| | | @SdkOperate |
| | | @Override |
| | | public boolean setZeroPtz(CameraCmd cmd) { |
| | | boolean result = false; |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | //引导指向目标 |
| | | @SdkOperate |
| | | @Override |
| | | public boolean guideTargetPosition(CameraCmd cmd) { |
| | | boolean result = false; |
| | |
| | | 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; |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //停止录像并存入minio |
| | | @Override |
| | | public String recordStopToMinio(CameraCmd cmd) { |
| | | String url = ""; |
| | |
| | | } |
| | | return url; |
| | | } |
| | | |
| | | //停止录像并不存入minio |
| | | @Override |
| | | public void recordStopNotToMinio(CameraCmd cmd) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ArdChannel> getCameraChannelList(ArdCameras camera) { |
| | | return null; |
| | | 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; |
| | | } |
| | | |
| | | //获取相机架设参数 |