| | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.constant.sdkPriority; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.constant.CamPriority; |
| | | import com.ruoyi.device.camera.domain.CameraCmd; |
| | | import com.ruoyi.device.camera.mapper.ArdCamerasMapper; |
| | | import com.ruoyi.device.hiksdk.common.GlobalVariable; |
| | | import com.ruoyi.device.camera.domain.ArdCameras; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import com.ruoyi.device.hiksdk.domain.recordInfo; |
| | | import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil; |
| | | import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK; |
| | | import com.ruoyi.device.hiksdk.service.IHikClientService; |
| | |
| | | import com.sun.jna.Pointer; |
| | | import com.sun.jna.ptr.IntByReference; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | import static com.ruoyi.device.hiksdk.common.GlobalVariable.threadMap; |
| | | import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | @SdkOperate |
| | | public boolean setTargetPosition(CameraCmd cmd) { |
| | | public boolean guideTargetPosition(CameraCmd cmd) { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer channelNum = cmd.getChannelNum(); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | |
| | | } else { |
| | | //如果非本人比较优先级 |
| | | Integer currentLevel = 0;//当前操作者的优先级 |
| | | if (sdkPriority.priorityMap.containsKey(currentOperator)) { |
| | | if (CamPriority.priorityMap.containsKey(currentOperator)) { |
| | | /*当前控制者为系统报警用户*/ |
| | | currentLevel = (Integer) sdkPriority.priorityMap.get(currentOperator); |
| | | currentLevel = (Integer) CamPriority.priorityMap.get(currentOperator); |
| | | } else { |
| | | /*当前控制者为普通用户*/ |
| | | SysUser sysUser = sysUserMapper.selectUserById(currentOperator); |
| | | currentLevel = sysUser.getCameraPriority(); |
| | | } |
| | | Integer operatorLevel = 0;//获取申请者的优先级 |
| | | if (sdkPriority.priorityMap.containsKey(operator)) { |
| | | if (CamPriority.priorityMap.containsKey(operator)) { |
| | | /*包含说明当前申请控制者为系统报警用户*/ |
| | | operatorLevel = (Integer) sdkPriority.priorityMap.get(operator); |
| | | operatorLevel = (Integer) CamPriority.priorityMap.get(operator); |
| | | } else { |
| | | /*否则申请控制者为当前登录用户*/ |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void recordToMinio(CameraCmd cmd) { |
| | | public String recordToMinio(CameraCmd cmd) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer channelNum = cmd.getChannelNum(); |
| | | String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4"); |
| | | boolean enable = cmd.isEnable(); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return; |
| | | return ""; |
| | | } |
| | | Integer userId = GlobalVariable.loginMap.get(cameraId); |
| | | //强制I帧结构体对象 |
| | |
| | | Integer lRealHandle = GlobalVariable.previewMap.get(cameraId); |
| | | hCNetSDK.NET_DVR_StopRealPlay(lRealHandle); |
| | | GlobalVariable.previewMap.remove(cameraId); |
| | | log.info("录像停止"); |
| | | log.debug("停止当前录像"); |
| | | } |
| | | int lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); |
| | | if (lRealHandle == -1) { |
| | | log.error("取流失败" + hCNetSDK.NET_DVR_GetLastError()); |
| | | return; |
| | | return ""; |
| | | } |
| | | log.info("取流成功"); |
| | | log.debug("取流成功"); |
| | | GlobalVariable.threadMap.put(cameraId,Thread.currentThread().getName()); |
| | | GlobalVariable.previewMap.put(cameraId, lRealHandle); |
| | | if (!hCNetSDK.NET_DVR_SaveRealData_V30(GlobalVariable.previewMap.get(cameraId), 2, path)) { |
| | | log.error("保存视频文件到临时文件夹失败 错误码为: " + hCNetSDK.NET_DVR_GetLastError()); |
| | | return; |
| | | return ""; |
| | | } |
| | | log.info("录像开始"); |
| | | log.debug("录像开始"); |
| | | } else { |
| | | if (GlobalVariable.previewMap.containsKey(cameraId)) { |
| | | Integer lRealHandle = GlobalVariable.previewMap.get(cameraId); |
| | | hCNetSDK.NET_DVR_StopRealPlay(lRealHandle); |
| | | GlobalVariable.previewMap.remove(cameraId); |
| | | } |
| | | log.info("录像停止"); |
| | | log.debug("录像停止"); |
| | | //存入minio |
| | | String BucketName = cmd.getRecordBucketName(); |
| | | String ObjectName = cmd.getRecordObjectName(); |
| | | String ContentType = "video/MP4"; |
| | | FileInputStream stream = new FileInputStream(path); |
| | | boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); |
| | | String simpleUUID = IdUtils.simpleUUID(); |
| | | String time = new SimpleDateFormat("yyyyMMdd").format(new Date()); |
| | | String recordName = cameraId + "/" + time + "/" + ObjectName +"_"+ simpleUUID + ".mp4"; |
| | | boolean b = MinioUtils.uploadObject(BucketName, recordName, stream, stream.available(), ContentType); |
| | | if (b) { |
| | | log.info("上传文件成功!" + MinioClientSingleton.domainUrl + "/" + BucketName + "/" + ObjectName); |
| | | String url = MinioClientSingleton.domainUrl + "/" + BucketName + "/" + recordName; |
| | | log.debug("上传文件成功!" + url); |
| | | return url; |
| | | } |
| | | } |
| | | return ""; |
| | | } catch (Exception ex) { |
| | | log.error("录像异常" + ex.getMessage()); |
| | | return ""; |
| | | } |
| | | } |
| | | } |