| | |
| | | import com.ruoyi.inspect.service.IArdVideoInspectTaskService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Description: 巡检任务 |
| | |
| | | log.info("满足时间"); |
| | | /*当前任务的巡检步骤*/ |
| | | List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTaskService.selectArdVideoInspectTaskById(videoInspectTask.getId()).getArdVideoInspectTaskStepList(); |
| | | Integer setpNum=ardVideoInspectTaskStepList.size();//步骤数量 |
| | | Map<Integer, Object> sortMap = new HashMap<>();//排序map |
| | | Map<String, Object> stepMap = new HashMap<>();//IDmap |
| | | for (ArdVideoInspectTaskStep step : ardVideoInspectTaskStepList) { |
| | | sortMap.put(step.getOrderNumber(), step); |
| | | stepMap.put(step.getId(), step); |
| | | } |
| | | /*获取当前任务正在执行的步骤和当前步骤开始的时间*/ |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | String cameraId = videoInspectTask.getCameraId(); |
| | |
| | | String currentStepStartTime = videoInspectTask.getCurrentStepStartTime(); |
| | | /*如果当前步骤未找到,则从1开始*/ |
| | | if (StringUtils.isNull(currentStepId)) { |
| | | String wellId = ardVideoInspectTaskStepList.get(0).getWellId();//获取第一个步骤的井号 |
| | | ArdVideoInspectTaskStep step = (ArdVideoInspectTaskStep) sortMap.get(1); |
| | | String wellId = step.getWellId();//获取第一个步骤的井号 |
| | | if (!StringUtils.isNull(wellId)) { |
| | | /*获取井坐标*/ |
| | | ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellService.selectArdAlarmpointsWellById(wellId); |
| | | double[] targetPositon = new double[3]; |
| | | targetPositon[0]=ardAlarmpointsWell.getLongitude(); |
| | | targetPositon[1]=ardAlarmpointsWell.getLatitude(); |
| | | targetPositon[2]=ardAlarmpointsWell.getAltitude(); |
| | | targetPositon[0] = ardAlarmpointsWell.getLongitude(); |
| | | targetPositon[1] = ardAlarmpointsWell.getLatitude(); |
| | | targetPositon[2] = ardAlarmpointsWell.getAltitude(); |
| | | /*获取相机坐标*/ |
| | | ArdCameras cameras = ardCamerasService.selectArdCamerasById(cameraId); |
| | | double[] cameraPositon = new double[3]; |
| | | cameraPositon[0]=cameras.getLongitude(); |
| | | cameraPositon[1]=cameras.getLatitude(); |
| | | cameraPositon[2]=cameras.getAltitude(); |
| | | cameraPositon[0] = cameras.getLongitude(); |
| | | cameraPositon[1] = cameras.getLatitude(); |
| | | cameraPositon[2] = cameras.getAltitude(); |
| | | /*控制相机巡检*/ |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(cameraId); |
| | |
| | | cmd.setCamPosition(cameraPositon); |
| | | cmd.setTargetPosition(targetPositon); |
| | | cmd.setOperator("sys_patrol_inspect"); |
| | | cmd.setExpired(ardVideoInspectTaskStepList.get(0).getRecordingTime()); |
| | | cmd.setExpired(step.getRecordingTime()); |
| | | boolean setTargetPosition = hikClientService.setTargetPosition(cmd); |
| | | if(setTargetPosition) |
| | | { |
| | | if (setTargetPosition) { |
| | | /*控制相机巡检成功,开始录像*/ |
| | | cmd.setEnable(true);//启动录像 |
| | | hikClientService.recordToMinio(cmd); |
| | | /*更新任务当前步骤id和步骤启动时间*/ |
| | | ArdVideoInspectTask avit=new ArdVideoInspectTask(); |
| | | ArdVideoInspectTask avit = new ArdVideoInspectTask(); |
| | | avit.setId(videoInspectTask.getId()); |
| | | avit.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId()); |
| | | avit.setCurrentStepStartTime(DateUtils.getTime()); |
| | | //TODO with int i = ardVideoInspectTaskService.updateArdVideoInspectTaskWithCurrentStepInfo(avit); |
| | | // log.info("更新结果"+i); |
| | | ardVideoInspectTaskService.updateArdVideoInspectTaskNoUpdater(avit); |
| | | } |
| | | } |
| | | } |
| | | else /*当前任务已经执行,判断是否到期*/ |
| | | { |
| | | Optional<Integer> recordingTime = ardVideoInspectTaskStepList.stream() |
| | | .filter(ardVideoInspectTaskStep -> ardVideoInspectTaskStep.getId().equals(currentStepId)) |
| | | .map(ArdVideoInspectTaskStep::getRecordingTime) |
| | | .findFirst(); |
| | | if (recordingTime.isPresent()) { |
| | | System.out.println("找到了匹配的recordingTime: " + recordingTime.get()); |
| | | /*获取到当前步骤的持续时间*/ |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | if (stepMap.containsKey(currentStepId)) { |
| | | /*获取当前步骤信息*/ |
| | | ArdVideoInspectTaskStep currentStep = (ArdVideoInspectTaskStep) stepMap.get(currentStepId); |
| | | /*获取到当前步骤的开始和结束时间*/ |
| | | Date currentStepStartDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartTime); |
| | | Date currentStepStopDate = DateUtils.addMinutes(currentStepStartDate,recordingTime.get()); |
| | | /*判断时间是否过期*/ |
| | | if(!DateUtils.TimeCompare(currentStepStartDate,currentStepStopDate)) |
| | | { |
| | | /*已过期,停止录像,执行下一步骤*/ |
| | | Date currentStepStopDate = DateUtils.addMinutes(currentStepStartDate, currentStep.getRecordingTime()); |
| | | /*判断当前步骤时间是否过期*/ |
| | | if (!DateUtils.TimeCompare(currentStepStartDate, currentStepStopDate)) { |
| | | /*已过期,停止录像*/ |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(cameraId); |
| | | cmd.setChannelNum(channel); |
| | |
| | | String url= MinioClientSingleton.domainUrl+ "/" +cmd.getRecordBucketName()+ "/"+recordName; |
| | | hikClientService.recordToMinio(cmd); |
| | | /*更新巡检记录*/ |
| | | ArdVideoInspectRecord ardVideoInspectRecord=new ArdVideoInspectRecord(); |
| | | ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord(); |
| | | ardVideoInspectRecord.setStepId(currentStepId); |
| | | ardVideoInspectRecord.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,currentStepStartDate)); |
| | | ardVideoInspectRecord.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,currentStepStopDate)); |
| | | ardVideoInspectRecord.setRecordFilePath(record); |
| | | ardVideoInspectRecord.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartDate)); |
| | | ardVideoInspectRecord.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStopDate)); |
| | | ardVideoInspectRecord.setRecordFilePath(url); |
| | | ardVideoInspectRecordService.insertArdVideoInspectRecord(ardVideoInspectRecord); |
| | | log.info(record); |
| | | } |
| | | } else { |
| | | System.out.println("未找到匹配的recordingTime"); |
| | | } |
| | | |
| | | /*切换下一步骤*/ |
| | | Integer orderNumber = currentStep.getOrderNumber(); |
| | | /*判断当前步骤序号是否小于步骤总数*/ |
| | | if (orderNumber < stepMap.size()) { |
| | | /*小于则执行下一步骤*/ |
| | | orderNumber++; |
| | | } else { |
| | | /*否则从1开始执行*/ |
| | | orderNumber = 1; |
| | | } |
| | | ArdVideoInspectTaskStep step = (ArdVideoInspectTaskStep) sortMap.get(orderNumber); |
| | | String wellId = step.getWellId();//获取第一个步骤的井号 |
| | | if (!StringUtils.isNull(wellId)) { |
| | | /*获取井坐标*/ |
| | | ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellService.selectArdAlarmpointsWellById(wellId); |
| | | double[] targetPositon = new double[3]; |
| | | targetPositon[0] = ardAlarmpointsWell.getLongitude(); |
| | | targetPositon[1] = ardAlarmpointsWell.getLatitude(); |
| | | targetPositon[2] = ardAlarmpointsWell.getAltitude(); |
| | | /*获取相机坐标*/ |
| | | ArdCameras cameras = ardCamerasService.selectArdCamerasById(cameraId); |
| | | double[] cameraPositon = new double[3]; |
| | | cameraPositon[0] = cameras.getLongitude(); |
| | | cameraPositon[1] = cameras.getLatitude(); |
| | | cameraPositon[2] = cameras.getAltitude(); |
| | | /*控制相机巡检*/ |
| | | log.info("指向" + ardAlarmpointsWell.getWellId() + "坐标:" + targetPositon); |
| | | cmd = new CameraCmd(); |
| | | cmd.setCameraId(cameraId); |
| | | cmd.setChannelNum(channel); |
| | | cmd.setCamPosition(cameraPositon); |
| | | cmd.setTargetPosition(targetPositon); |
| | | cmd.setOperator("sys_patrol_inspect"); |
| | | cmd.setExpired(step.getRecordingTime()); |
| | | boolean setTargetPosition = hikClientService.setTargetPosition(cmd); |
| | | if (setTargetPosition) { |
| | | /*控制相机巡检成功,开始录像*/ |
| | | cmd.setEnable(true);//启动录像 |
| | | hikClientService.recordToMinio(cmd); |
| | | /*更新任务当前步骤id和步骤启动时间*/ |
| | | ArdVideoInspectTask avit = new ArdVideoInspectTask(); |
| | | avit.setId(videoInspectTask.getId()); |
| | | avit.setCurrentStepId(step.getId()); |
| | | avit.setCurrentStepStartTime(DateUtils.getTime()); |
| | | ardVideoInspectTaskService.updateArdVideoInspectTaskNoUpdater(avit); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /*否则判断当前步骤开始时间,判断是否到期*/ |
| | | /*未到期*/ |
| | | /*忽略*/ |
| | | /*已到期*/ |
| | | /*结束录像,转到下一个步骤, |
| | | 控制云台指向关联井坐标,并开始录像,更新当前步骤和当前步骤开始时间/ |
| | | */ |
| | | } |
| | | } |
| | | } |