| | |
| | | |
| | | public void scanRun(){ |
| | | /*扫描所有可执行任务1-时间满足2-自动*/ |
| | | log.info("开始扫描所有可执行任务"); |
| | | ArdVideoInspectTask ardVideoInspectTask = new ArdVideoInspectTask(); |
| | | ardVideoInspectTask.setInspectMode("自动"); |
| | | List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskService.selectArdVideoInspectTaskList(ardVideoInspectTask); |
| | |
| | | /*遍历所有时间满足的自动任务*/ |
| | | boolean timeCompare = DateUtils.TimeCompare(videoInspectTask.getStartTime(), videoInspectTask.getEndTime()); |
| | | if (timeCompare) { |
| | | log.info("满足时间"); |
| | | /*当前任务的巡检步骤*/ |
| | | /*获取当前任务的所有巡检步骤*/ |
| | | List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTaskService.selectArdVideoInspectTaskById(videoInspectTask.getId()).getArdVideoInspectTaskStepList(); |
| | | 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); |
| | | if (ardVideoInspectTaskStepList.size() == 0) { |
| | | continue; |
| | | } |
| | | /*获取当前任务正在执行的步骤和当前步骤开始的时间*/ |
| | | videoInspectTask.setArdVideoInspectTaskStepList(ardVideoInspectTaskStepList); |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | String cameraId = videoInspectTask.getCameraId(); |
| | | Integer channel = videoInspectTask.getChannel(); |
| | | String currentStepStartTime = videoInspectTask.getCurrentStepStartTime(); |
| | | /*如果当前步骤未找到,则从1开始*/ |
| | | if (StringUtils.isNull(currentStepId)) { |
| | | ArdVideoInspectTaskStep step = (ArdVideoInspectTaskStep) sortMap.get(1); |
| | | String wellId = step.getWellId();//获取第一个步骤的井号 |
| | | videoInspectTask.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId()); |
| | | startRunStep(videoInspectTask);//开始当前任务的第一个步骤 |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | boolean expird = isExpirdStep(videoInspectTask); /*判断当前步骤时间是否过期*/ |
| | | if (expird) { |
| | | /*已过期,停止录像*/ |
| | | |
| | | stopRunStep(videoInspectTask); |
| | | /*切换下一步*/ |
| | | String nextStepId = changeNextStep(videoInspectTask); |
| | | /*开始*/ |
| | | videoInspectTask.setCurrentStepId(nextStepId); |
| | | startRunStep(videoInspectTask); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //步骤开始 |
| | | private void startRunStep(ArdVideoInspectTask ardVideoInspectTask) { |
| | | String currentStepId = ardVideoInspectTask.getCurrentStepId(); |
| | | if(StringUtils.isNull(currentStepId)) |
| | | { |
| | | log.info("当前开始巡检步骤id为空"); |
| | | return; |
| | | } |
| | | log.info("步骤:" + 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 = ardAlarmpointsWellService.selectArdAlarmpointsWellById(wellId); |
| | |
| | | hikClientService.recordToMinio(cmd); |
| | | /*更新任务当前步骤id和步骤启动时间*/ |
| | | ArdVideoInspectTask avit = new ArdVideoInspectTask(); |
| | | avit.setId(videoInspectTask.getId()); |
| | | avit.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId()); |
| | | avit.setId(ardVideoInspectTask.getId()); |
| | | avit.setCurrentStepId(step.getId()); |
| | | avit.setCurrentStepStartTime(DateUtils.getTime()); |
| | | ardVideoInspectTaskService.updateArdVideoInspectTaskNoUpdater(avit); |
| | | } |
| | | } |
| | | } 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, currentStep.getRecordingTime()); |
| | | /*判断当前步骤时间是否过期*/ |
| | | if (!DateUtils.TimeCompare(currentStepStartDate, currentStepStopDate)) { |
| | | /*已过期,停止录像*/ |
| | | } |
| | | } |
| | | |
| | | //步骤停止 |
| | | private void stopRunStep(ArdVideoInspectTask ardVideoInspectTask) { |
| | | String currentStepId = ardVideoInspectTask.getCurrentStepId(); |
| | | log.info("步骤:" + currentStepId + "停止"); |
| | | if(StringUtils.isNull(currentStepId)) |
| | | { |
| | | log.info("当前停止巡检步骤id为空"); |
| | | return; |
| | | } |
| | | String currentStepStartTime = ardVideoInspectTask.getCurrentStepStartTime(); |
| | | 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(); |
| | | /*停止录像*/ |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(cameraId); |
| | | cmd.setChannelNum(channel); |
| | |
| | | String recordName = cameraId + "/" + time + "/" + uuid + ".mp4"; |
| | | cmd.setRecordBucketName("record"); |
| | | cmd.setRecordObjectName(recordName); |
| | | String url= MinioClientSingleton.domainUrl+ "/" +cmd.getRecordBucketName()+ "/"+recordName; |
| | | hikClientService.recordToMinio(cmd); |
| | | /*更新巡检记录*/ |
| | | /*插入巡检记录*/ |
| | | ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord(); |
| | | ardVideoInspectRecord.setStepId(currentStepId); |
| | | ardVideoInspectRecord.setStepId(step.getId()); |
| | | Date currentStepStartDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartTime); |
| | | 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); |
| | | ardVideoInspectRecordService.insertArdVideoInspectRecord(ardVideoInspectRecord); |
| | | } |
| | | } |
| | | |
| | | /*切换下一步骤*/ |
| | | Integer orderNumber = currentStep.getOrderNumber(); |
| | | //步骤判断是否过期 |
| | | private boolean isExpirdStep(ArdVideoInspectTask ardVideoInspectTask) { |
| | | List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTask.getArdVideoInspectTaskStepList(); |
| | | /*获取当前任务正在执行的步骤和当前步骤开始的时间*/ |
| | | String currentStepId = ardVideoInspectTask.getCurrentStepId(); |
| | | String currentStepStartTime = ardVideoInspectTask.getCurrentStepStartTime(); |
| | | Optional<ArdVideoInspectTaskStep> objectOptional = ardVideoInspectTaskStepList.stream() |
| | | .filter(ardVideoInspectTaskStep -> ardVideoInspectTaskStep.getId().equals(currentStepId)) |
| | | .findFirst(); |
| | | if (objectOptional.isPresent()) { |
| | | /*获取当前步骤信息*/ |
| | | ArdVideoInspectTaskStep currentStep = objectOptional.get(); |
| | | /*获取到当前步骤的开始和结束时间*/ |
| | | Date currentStepStartDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartTime); |
| | | Date currentStepStopDate = DateUtils.addMinutes(currentStepStartDate, currentStep.getRecordingTime()); |
| | | /*判断当前步骤时间是否过期*/ |
| | | if (!DateUtils.TimeCompare(currentStepStartDate, currentStepStopDate)) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } else { |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | //步骤切换 |
| | | private String changeNextStep(ArdVideoInspectTask ardVideoInspectTask) { |
| | | String currentStepId = ardVideoInspectTask.getCurrentStepId(); |
| | | Optional<ArdVideoInspectTaskStep> objectOptional = ardVideoInspectTask.getArdVideoInspectTaskStepList().stream() |
| | | .filter(obj -> obj.getId().equals(currentStepId)) |
| | | .findFirst(); |
| | | if (objectOptional.isPresent()) { |
| | | ArdVideoInspectTaskStep step = objectOptional.get(); |
| | | Integer currentStepOrderNumber = step.getOrderNumber(); |
| | | /*判断当前步骤序号是否小于步骤总数*/ |
| | | if (orderNumber < stepMap.size()) { |
| | | if (currentStepOrderNumber < ardVideoInspectTask.getArdVideoInspectTaskStepList().size()) { |
| | | /*小于则执行下一步骤*/ |
| | | orderNumber++; |
| | | currentStepOrderNumber++; |
| | | } else { |
| | | /*否则从1开始执行*/ |
| | | orderNumber = 1; |
| | | currentStepOrderNumber = 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和步骤启动时间*/ |
| | | Integer nextStepOrderNumber = currentStepOrderNumber; |
| | | /*更新当前任务切换新步骤*/ |
| | | ArdVideoInspectTask avit = new ArdVideoInspectTask(); |
| | | avit.setId(videoInspectTask.getId()); |
| | | avit.setCurrentStepId(step.getId()); |
| | | avit.setCurrentStepStartTime(DateUtils.getTime()); |
| | | avit.setId(ardVideoInspectTask.getId()); |
| | | String nextStepId = ardVideoInspectTask.getArdVideoInspectTaskStepList().stream() |
| | | .filter(obj -> obj.getOrderNumber() == nextStepOrderNumber) |
| | | .map(ArdVideoInspectTaskStep::getId) |
| | | .findFirst() |
| | | .orElse(null); |
| | | avit.setCurrentStepId(nextStepId); |
| | | ardVideoInspectTaskService.updateArdVideoInspectTaskNoUpdater(avit); |
| | | log.info("步骤:" + currentStepId + "切换为"+nextStepId); |
| | | return nextStepId; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | } |