| | |
| | | |
| | | import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; |
| | | import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper; |
| | | import com.ruoyi.alarmpoints.well.service.IArdAlarmpointsWellService; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | |
| | | import com.ruoyi.device.camera.domain.ArdCameras; |
| | | import com.ruoyi.device.camera.domain.CameraCmd; |
| | | import com.ruoyi.device.camera.mapper.ArdCamerasMapper; |
| | | import com.ruoyi.device.camera.service.IArdCamerasService; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import com.ruoyi.device.hiksdk.service.IHikClientService; |
| | | import com.ruoyi.inspect.domain.ArdVideoInspectRecord; |
| | | import com.ruoyi.inspect.mapper.ArdVideoInspectRecordMapper; |
| | | import com.ruoyi.inspect.service.IArdVideoInspectRecordService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import com.ruoyi.inspect.domain.ArdVideoInspectTask; |
| | | import com.ruoyi.inspect.service.IArdVideoInspectTaskService; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | |
| | | private ArdCamerasMapper ardCamerasMapper; |
| | | @Resource |
| | | private IHikClientService hikClientService; |
| | | |
| | | @PostConstruct |
| | | public void initTask() { |
| | | List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(new ArdVideoInspectTask()); |
| | | /*启动后将所有手动任务置为关闭*/ |
| | | for (ArdVideoInspectTask ardVideoInspectTask : ardVideoInspectTasks) { |
| | | if (ardVideoInspectTask.getInspectMode().equals("手动")) { |
| | | ardVideoInspectTask.setMenualSwitch("关"); |
| | | ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询视频巡检任务 |
| | |
| | | public int updateArdVideoInspectTask(ArdVideoInspectTask ardVideoInspectTask) { |
| | | ardVideoInspectTask.setUpdateBy(SecurityUtils.getUsername()); |
| | | ardVideoInspectTask.setUpdateTime(DateUtils.getNowDate()); |
| | | ardVideoInspectTaskMapper.deleteArdVideoInspectTaskStepByTaskId(ardVideoInspectTask.getId()) |
| | | ; |
| | | ardVideoInspectTaskMapper.deleteArdVideoInspectTaskStepByTaskId(ardVideoInspectTask.getId()); |
| | | insertArdVideoInspectTaskStep(ardVideoInspectTask); |
| | | return ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask); |
| | | } |
| | | |
| | | /** |
| | | * 修改视频巡检任务,bu更新步骤 |
| | | * |
| | | * @param ardVideoInspectTask 视频巡检任务 |
| | | * @return 结果 |
| | | */ |
| | | @Transactional |
| | | @Override |
| | | public int updateArdVideoInspectTaskSingle(ArdVideoInspectTask ardVideoInspectTask) { |
| | | ardVideoInspectTask.setUpdateBy(SecurityUtils.getUsername()); |
| | | ardVideoInspectTask.setUpdateTime(DateUtils.getNowDate()); |
| | | return ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 手动巡检任务 |
| | | */ |
| | | @Override |
| | | public void manualTaskRun(String TaskId) { |
| | | ArdVideoInspectTask videoInspectTask = ardVideoInspectTaskMapper.selectArdVideoInspectTaskById(TaskId); |
| | | if (videoInspectTask.getArdVideoInspectTaskStepList().size() == 0) { |
| | | return; |
| | | } |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | String currentStepStartTime = videoInspectTask.getCurrentStepStartTime(); |
| | | if (StringUtils.isNull(currentStepId)||StringUtils.isEmpty(currentStepId)) { |
| | | //从1号步骤开始 |
| | | videoInspectTask.setCurrentStepId(videoInspectTask.getArdVideoInspectTaskStepList().get(0).getId()); |
| | | if(InspectionTaskManager.taskMap.containsKey(TaskId)) { |
| | | startRunStep(videoInspectTask); |
| | | try { |
| | | ArdVideoInspectTask videoInspectTask = ardVideoInspectTaskMapper.selectArdVideoInspectTaskById(TaskId); |
| | | if (videoInspectTask.getArdVideoInspectTaskStepList().size() == 0) { |
| | | return; |
| | | } |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | if (StringUtils.isNull(currentStepStartTime)||StringUtils.isEmpty(currentStepStartTime)) { |
| | | //当前任务启动时间为null,则说明当前步骤被中断,直接启动当前步骤 |
| | | startRunStep(videoInspectTask); |
| | | } else { |
| | | boolean expird = isExpirdStep(videoInspectTask); /*判断当前步骤时间是否过期*/ |
| | | if (expird) { |
| | | //停止录像 |
| | | stopRunStep(videoInspectTask); |
| | | //切换步骤 |
| | | String nextStepId = changeNextStep(videoInspectTask); |
| | | //开始下一步骤 |
| | | videoInspectTask.setCurrentStepId(nextStepId); |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | String currentStepStartTime = videoInspectTask.getCurrentStepStartTime(); |
| | | if (StringUtils.isNull(currentStepId) || StringUtils.isEmpty(currentStepId)) { |
| | | //从1号步骤开始 |
| | | videoInspectTask.setCurrentStepId(videoInspectTask.getArdVideoInspectTaskStepList().get(0).getId()); |
| | | if (InspectionTaskManager.taskMap.containsKey(TaskId)) { |
| | | startRunStep(videoInspectTask); |
| | | } |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | if (StringUtils.isNull(currentStepStartTime) || StringUtils.isEmpty(currentStepStartTime)) { |
| | | //当前任务启动时间为null,则说明当前步骤被中断,直接启动当前步骤 |
| | | startRunStep(videoInspectTask); |
| | | } else { |
| | | boolean expird = isExpirdStep(videoInspectTask); /*判断当前步骤时间是否过期*/ |
| | | if (expird) { |
| | | //停止录像 |
| | | stopRunStep(videoInspectTask); |
| | | //切换步骤 |
| | | String nextStepId = changeNextStep(videoInspectTask); |
| | | //开始下一步骤 |
| | | videoInspectTask.setCurrentStepId(nextStepId); |
| | | startRunStep(videoInspectTask); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("手动巡检异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断当前手动任务能否开启 |
| | | */ |
| | | @Override |
| | | public boolean isEnablemanualTask(String TaskId) { |
| | | /*扫描当前手动开的任务,获取手动控制的相机idList*/ |
| | | List<String> menualCameraId = new ArrayList<>(); |
| | | ArdVideoInspectTask menualTask = new ArdVideoInspectTask(); |
| | | menualTask.setInspectMode("手动"); |
| | | menualTask.setMenualSwitch("开"); |
| | | List<ArdVideoInspectTask> menualTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(menualTask); |
| | | if (menualTasks.size() > 0) { |
| | | for (ArdVideoInspectTask task : menualTasks) { |
| | | if (StringUtils.isNull(task.getCameraId()) || StringUtils.isEmpty(task.getCameraId())) { |
| | | continue; |
| | | } |
| | | if (!menualCameraId.contains(task.getCameraId())) { |
| | | menualCameraId.add(task.getCameraId()); |
| | | } |
| | | } |
| | | } |
| | | /*判断相机是否已经被人手动控制*/ |
| | | ArdVideoInspectTask videoInspectTask = ardVideoInspectTaskMapper.selectArdVideoInspectTaskById(TaskId); |
| | | if (StringUtils.isNull(videoInspectTask)) { |
| | | return false; |
| | | } |
| | | String cameraId = videoInspectTask.getCameraId(); |
| | | if (StringUtils.isEmpty(cameraId)) { |
| | | return false; |
| | | } |
| | | if (menualCameraId.contains(cameraId)) { |
| | | /*如果当前任务关联的相机已经有人手动控制,则不允许控制*/ |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void autoTaskRun() { |
| | | /*扫描所有可执行任务1-时间满足2-自动*/ |
| | | ArdVideoInspectTask ardVideoInspectTask = new ArdVideoInspectTask(); |
| | | ardVideoInspectTask.setInspectMode("自动"); |
| | | List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(ardVideoInspectTask); |
| | | for (ArdVideoInspectTask videoInspectTask : ardVideoInspectTasks) { |
| | | /*遍历所有时间满足的自动任务*/ |
| | | boolean timeCompare = DateUtils.TimeCompare(videoInspectTask.getStartTime(), videoInspectTask.getEndTime()); |
| | | if (timeCompare) { |
| | | log.info("自动任务启动:" + videoInspectTask.getId()); |
| | | /*获取当前任务的所有巡检步骤*/ |
| | | List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTaskMapper.selectArdVideoInspectTaskById(videoInspectTask.getId()).getArdVideoInspectTaskStepList(); |
| | | if (ardVideoInspectTaskStepList.size() == 0) { |
| | | continue; |
| | | } |
| | | videoInspectTask.setArdVideoInspectTaskStepList(ardVideoInspectTaskStepList); |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | if (StringUtils.isNull(currentStepId)) { |
| | | videoInspectTask.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId()); |
| | | startRunStep(videoInspectTask);//开始当前任务的第一个步骤 |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | if (StringUtils.isNull(videoInspectTask.getCurrentStepStartTime())) { |
| | | //当前任务启动时间为null,则说明当前步骤被中断,直接启动当前步骤 |
| | | startRunStep(videoInspectTask); |
| | | } else { |
| | | boolean expird = isExpirdStep(videoInspectTask); /*判断当前步骤时间是否过期*/ |
| | | if (expird) { |
| | | //停止录像 |
| | | stopRunStep(videoInspectTask); |
| | | //切换步骤 |
| | | String nextStepId = changeNextStep(videoInspectTask); |
| | | //开始下一步骤 |
| | | videoInspectTask.setCurrentStepId(nextStepId); |
| | | startRunStep(videoInspectTask); |
| | | } |
| | | try { |
| | | /*扫描当前手动开的任务,获取手动控制的相机idList*/ |
| | | List<String> menualCameraId = new ArrayList<>(); |
| | | ArdVideoInspectTask menualTask = new ArdVideoInspectTask(); |
| | | menualTask.setInspectMode("手动"); |
| | | menualTask.setMenualSwitch("开"); |
| | | List<ArdVideoInspectTask> menualTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(menualTask); |
| | | if (menualTasks.size() > 0) { |
| | | for (ArdVideoInspectTask task : menualTasks) { |
| | | if (StringUtils.isNull(task.getCameraId()) || StringUtils.isEmpty(task.getCameraId())) { |
| | | continue; |
| | | } |
| | | if (!menualCameraId.contains(task.getCameraId())) { |
| | | menualCameraId.add(task.getCameraId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /*扫描所有自动任务*/ |
| | | ArdVideoInspectTask autoTask = new ArdVideoInspectTask(); |
| | | autoTask.setInspectMode("自动"); |
| | | List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(autoTask); |
| | | for (ArdVideoInspectTask videoInspectTask : ardVideoInspectTasks) { |
| | | /*遍历所有时间满足的自动任务*/ |
| | | boolean timeCompare = DateUtils.TimeCompare(videoInspectTask.getStartTime(), videoInspectTask.getEndTime()); |
| | | if (timeCompare) { |
| | | if (menualCameraId.contains(videoInspectTask.getCameraId())) { |
| | | /*若当前相机正在有任务手动执行,则不执行*/ |
| | | continue; |
| | | } |
| | | /*获取当前任务的所有巡检步骤*/ |
| | | List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTaskMapper.selectArdVideoInspectTaskById(videoInspectTask.getId()).getArdVideoInspectTaskStepList(); |
| | | if (ardVideoInspectTaskStepList.size() == 0) { |
| | | continue; |
| | | } |
| | | videoInspectTask.setArdVideoInspectTaskStepList(ardVideoInspectTaskStepList); |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | String currentStepStartTime = videoInspectTask.getCurrentStepStartTime(); |
| | | if (StringUtils.isNull(currentStepId) || StringUtils.isEmpty(currentStepId)) { |
| | | //开始当前任务的第一个步骤 |
| | | videoInspectTask.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId()); |
| | | startRunStep(videoInspectTask); |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | if (StringUtils.isNull(currentStepStartTime) || StringUtils.isEmpty(currentStepStartTime)) { |
| | | //当前任务启动时间为空,则说明当前步骤被中断,直接启动当前步骤 |
| | | startRunStep(videoInspectTask); |
| | | } else { |
| | | //判断当前步骤时间是否过期 |
| | | boolean expird = isExpirdStep(videoInspectTask); |
| | | if (expird) { |
| | | //停止录像 |
| | | stopRunStep(videoInspectTask); |
| | | //切换步骤 |
| | | String nextStepId = changeNextStep(videoInspectTask); |
| | | //开始下一步骤 |
| | | videoInspectTask.setCurrentStepId(nextStepId); |
| | | startRunStep(videoInspectTask); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | if (StringUtils.isEmpty(videoInspectTask.getCurrentStepId()) || StringUtils.isEmpty(videoInspectTask.getCurrentStepStartTime())) { |
| | | continue; |
| | | } |
| | | /*过期的任务清空当前步骤信息*/ |
| | | videoInspectTask.setCurrentStepId(""); |
| | | videoInspectTask.setCurrentStepStartTime(""); |
| | | ardVideoInspectTaskMapper.updateArdVideoInspectTask(videoInspectTask); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("自动巡检任务异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 自动手动合并,扫库方式,目前不使用 |
| | | */ |
| | | @Override |
| | | public void taskRun() { |
| | | /*扫描所有可执行任务1-时间满足2-自动*/ |
| | | ArdVideoInspectTask ardVideoInspectTask = new ArdVideoInspectTask(); |
| | | List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(ardVideoInspectTask); |
| | | for (ArdVideoInspectTask videoInspectTask : ardVideoInspectTasks) { |
| | |
| | | continue; |
| | | } |
| | | videoInspectTask.setArdVideoInspectTaskStepList(ardVideoInspectTaskStepList); |
| | | String currentStepId = videoInspectTask.getCurrentStepId(); |
| | | if (StringUtils.isNull(currentStepId)) { |
| | | String currentStepId = videoInspectTask.getCurrentStepId();//当前步骤id |
| | | String currentStepStartTime = videoInspectTask.getCurrentStepStartTime();//当前步骤启动时间 |
| | | if (StringUtils.isNull(currentStepId) || StringUtils.isEmpty(currentStepId)) { |
| | | //开始第一个步骤 |
| | | videoInspectTask.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId()); |
| | | startRunStep(videoInspectTask);//开始当前任务的第一个步骤 |
| | | } else /*当前任务已经执行,判断是否到期*/ { |
| | | if (StringUtils.isNull(videoInspectTask.getCurrentStepStartTime())) { |
| | | //当前任务启动时间为null,则说明当前步骤被中断,直接启动当前步骤 |
| | | startRunStep(videoInspectTask); |
| | | } else { |
| | | if (StringUtils.isNull(currentStepStartTime) || StringUtils.isEmpty(currentStepStartTime)) { |
| | | //当前任务启动时间为空,则说明当前步骤被中断,直接启动当前步骤 |
| | | startRunStep(videoInspectTask); |
| | | } else { |
| | | boolean expird = isExpirdStep(videoInspectTask); /*判断当前步骤时间是否过期*/ |
| | |
| | | ardVideoInspectTaskMapper.updateArdVideoInspectTask(avit); |
| | | } else { |
| | | cmd.setEnable(false);//停止录像 |
| | | cmd.setUploadMinio(true); |
| | | hikClientService.recordToMinio(cmd); |
| | | /*控制失败,当前步骤启动时间置null*/ |
| | | ArdVideoInspectTask avit = new ArdVideoInspectTask(); |
| | |
| | | String recordName = cameraId + "/" + time + "/" + uuid + ".mp4"; |
| | | cmd.setRecordBucketName("record"); |
| | | cmd.setRecordObjectName(recordName); |
| | | cmd.setUploadMinio(true); |
| | | hikClientService.recordToMinio(cmd); |
| | | /*插入巡检记录*/ |
| | | ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord(); |