ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java
@@ -6,6 +6,7 @@
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
@@ -34,7 +35,7 @@
 * @date 2023-05-30
 */
@Service
@Slf4j
@Slf4j(topic = "PatrolInspectionTask")
public class ArdVideoInspectTaskServiceImpl implements IArdVideoInspectTaskService {
    @Resource
    private ArdVideoInspectTaskMapper ardVideoInspectTaskMapper;
@@ -229,6 +230,9 @@
                        //开始下一步骤
                        videoInspectTask.setCurrentStepId(nextStepId);
                        startRunStep(videoInspectTask);
                    }else{
                        //未过期尝试引导,引导失败清空当前步骤开始时间,标记中断
                        tryGuide(videoInspectTask);
                    }
                }
            }
@@ -337,7 +341,7 @@
                                //开始下一步骤
                                videoInspectTask.setCurrentStepId(nextStepId);
                                startRunStep(videoInspectTask);
                            }
                            }else{tryGuide(videoInspectTask);}
                        }
                    }
                } else {
@@ -414,7 +418,7 @@
                log.info("当前开始巡检步骤id为空");
                return;
            }
            log.info("步骤:" + currentStepId + "开始");
            log.debug("巡检步骤:" + currentStepId + "尝试开始");
            String cameraId = ardVideoInspectTask.getCameraId();
            Integer channel = ardVideoInspectTask.getChannel();
            Optional<ArdVideoInspectTaskStep> objectOptional = ardVideoInspectTask.getArdVideoInspectTaskStepList().stream()
@@ -446,16 +450,12 @@
                    cmd.setChannelNum(channel);
                    cmd.setTargetPosition(targetPositon);
                    cmd.setOperator("sys_patrol_inspect");
                    cmd.setExpired(step.getRecordingTime());
                    boolean setTargetPosition = hikClientService.setTargetPosition(cmd);
                    cmd.setExpired(step.getRecordingTime()*60);
                    boolean setTargetPosition = hikClientService.guideTargetPosition(cmd);
                    if (setTargetPosition) {
                        /*控制相机巡检成功,开始录像*/
                        cmd.setEnable(true);//启动录像
                        hikClientService.recordToMinio(cmd);
                        hikClientService.recordStart(cmd);
                    } else {
                        cmd.setEnable(false);//停止录像
                        cmd.setUploadMinio(true);
                        hikClientService.recordToMinio(cmd);
                        /*控制失败,当前步骤启动时间置null*/
                        ardVideoInspectTask.setCurrentStepStartTime("");
                        ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask);
@@ -466,12 +466,64 @@
            log.error("巡检开始异常:" + ex.getMessage());
        }
    }
    //尝试控制引导
    private void tryGuide(ArdVideoInspectTask ardVideoInspectTask) {
        try {
            String currentStepId = ardVideoInspectTask.getCurrentStepId();
            if (StringUtils.isNull(currentStepId)) {
                log.info("当前开始巡检步骤id为空");
                return;
            }
            log.debug("巡检正常,尝试引导:" + currentStepId);
            String cameraId = ardVideoInspectTask.getCameraId();
            Integer channel = ardVideoInspectTask.getChannel();
            Optional<ArdVideoInspectTaskStep> objectOptional = ardVideoInspectTask.getArdVideoInspectTaskStepList().stream()
                    .filter(obj -> obj.getId().equals(currentStepId))
                    .findFirst();
            if (objectOptional.isPresent()) {
                ArdVideoInspectTaskStep step = objectOptional.get();
                String wellId = step.getWellId();
                if (!StringUtils.isNull(wellId)) {
                    /*获取井坐标*/
                    ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellById(wellId);
                    double[] targetPositon = new double[3];
                    targetPositon[0] = ardAlarmpointsWell.getLongitude();
                    targetPositon[1] = ardAlarmpointsWell.getLatitude();
                    targetPositon[2] = ardAlarmpointsWell.getAltitude();
                    /*获取相机坐标*/
                    ArdCameras cameras = ardCamerasMapper.selectArdCamerasById(cameraId);
                    double[] cameraPositon = new double[3];
                    cameraPositon[0] = cameras.getLongitude();
                    cameraPositon[1] = cameras.getLatitude();
                    cameraPositon[2] = cameras.getAltitude();
                    /*控制相机巡检*/
                    CameraCmd cmd = new CameraCmd();
                    cmd.setCameraId(cameraId);
                    cmd.setChannelNum(channel);
                    cmd.setTargetPosition(targetPositon);
                    cmd.setOperator("sys_patrol_inspect");
                    cmd.setExpired(step.getRecordingTime()*60);
                    boolean setTargetPosition = hikClientService.guideTargetPosition(cmd);
                    if (!setTargetPosition) {
                        /*控制失败,当前步骤启动时间置null*/
                        ardVideoInspectTask.setCurrentStepStartTime("");
                        ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask);
                    }
                    else
                    {
                        log.debug("引导成功!");
                    }
                }
            }
        } catch (Exception ex) {
            log.error("巡检尝试引导异常:" + ex.getMessage());
        }
    }
    //步骤停止
    private void stopRunStep(ArdVideoInspectTask ardVideoInspectTask) {
        try {
            String currentStepId = ardVideoInspectTask.getCurrentStepId();
            log.info("步骤:" + currentStepId + "停止");
            log.debug("巡检步骤:" + currentStepId + "停止");
            if (StringUtils.isNull(currentStepId)) {
                log.info("当前停止巡检步骤id为空");
                return;
@@ -489,14 +541,9 @@
                cmd.setCameraId(cameraId);
                cmd.setChannelNum(channel);
                cmd.setOperator("sys_patrol_inspect");
                cmd.setEnable(false);//停止录像
                String uuid = UUID.randomUUID().toString().replace("-", "");
                String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
                String recordName = cameraId + "/" + time + "/" + uuid + ".mp4";
                cmd.setRecordBucketName("record");
                cmd.setRecordObjectName(recordName);
                cmd.setUploadMinio(true);
                hikClientService.recordToMinio(cmd);
                cmd.setRecordObjectName("inspect_"+ IdUtils.fastSimpleUUID());
                String url=  hikClientService.recordStopToMinio(cmd);
                /*插入巡检记录*/
                ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord();
                ardVideoInspectRecord.setStepId(step.getId());
@@ -508,7 +555,6 @@
                Date currentStepStopDate = DateUtils.addMinutes(currentStepStartDate, step.getRecordingTime());
                ardVideoInspectRecord.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartDate));
                ardVideoInspectRecord.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStopDate));
                String url = MinioClientSingleton.domainUrl + "/" + cmd.getRecordBucketName() + "/" + recordName;
                ardVideoInspectRecord.setRecordFilePath(url);
                ardVideoInspectRecordMapper.insertArdVideoInspectRecord(ardVideoInspectRecord);
            }