| | |
| | | package com.ruoyi.inspect.service.impl;
|
| | |
|
| | | import java.util.*;
|
| | |
|
| | | import com.ruoyi.alarm.global.domain.GuidePoint;
|
| | | import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
|
| | | import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | |
| | | import com.ruoyi.inspect.domain.ArdVideoInspectRecord;
|
| | | import com.ruoyi.inspect.mapper.ArdVideoInspectRecordMapper;
|
| | | import com.ruoyi.inspect.mapper.ArdVideoInspectTaskStepMapper;
|
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
| | | import com.ruoyi.inspect.mapper.ArdVideoInspectTaskMapper;
|
| | | import com.ruoyi.inspect.domain.ArdVideoInspectTask;
|
| | | import com.ruoyi.inspect.service.IArdVideoInspectTaskService;
|
| | |
|
| | | import javax.annotation.PostConstruct;
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | 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);
|
| | | }
|
| | |
| | | }
|
| | | if (StringUtils.isNotNull(ardVideoInspectTaskStepList)) {
|
| | | for (ArdVideoInspectTaskStep ardVideoInspectTaskStep : ardVideoInspectTaskStepList) {
|
| | | if (ardVideoInspectTaskStep.getId() == null) {
|
| | | //新的步骤,添加
|
| | | ardVideoInspectTaskStep.setId(IdUtils.simpleUUID());
|
| | | ardVideoInspectTaskStepMapper.insertArdVideoInspectTaskStep(ardVideoInspectTaskStep);
|
| | | } else {
|
| | | //已有步骤,更新
|
| | | ardVideoInspectTaskStepMapper.updateArdVideoInspectTaskStep(ardVideoInspectTaskStep);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | 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);
|
| | | if(StringUtils.isNull(cameras))
|
| | | {
|
| | | log.debug("找不到相机:"+cameraId);
|
| | | ArdAlarmpointsWell well = ardAlarmpointsWellMapper.selectArdAlarmpointsWellById(wellId);
|
| | | if (StringUtils.isNull(well)) {
|
| | | log.debug("找不到井:" + well.getWellId());
|
| | | return;
|
| | | }
|
| | | double[] cameraPositon = new double[3];
|
| | | cameraPositon[0] = cameras.getLongitude();
|
| | | cameraPositon[1] = cameras.getLatitude();
|
| | | cameraPositon[2] = cameras.getAltitude();
|
| | | log.debug("找到井:" + well.getWellId());
|
| | | GuidePoint guidePoint = new GuidePoint().setLongitude(well.getLongitude()).setLatitude(well.getLatitude());
|
| | | log.debug("找到井坐标:" + well.getLongitude() + "-" + well.getLatitude() + "-" + well.getAltitude());
|
| | | /*获取相机坐标*/
|
| | | ArdCameras cameras = ardCamerasMapper.selectArdCamerasById(cameraId);
|
| | | if (StringUtils.isNull(cameras)) {
|
| | | log.debug("找不到相机:" + cameraId);
|
| | | return;
|
| | | }
|
| | | log.debug("找到相机:" + cameraId);
|
| | | /*控制相机巡检*/
|
| | | CameraCmd cmd = new CameraCmd();
|
| | | cmd.setCameraId(cameraId);
|
| | | cmd.setChanNo(channel);
|
| | | cmd.setTargetPosition(targetPositon);
|
| | | cmd.setTargetPosition(new double[]{guidePoint.getLongitude(), guidePoint.getLatitude()});
|
| | | cmd.setOperator("sys_patrol_inspect");
|
| | | cmd.setExpired(step.getRecordingTime() * 60);
|
| | | boolean setTargetPosition = cameraSdkService.guideTargetPosition(cmd);
|
| | | cmd.setExpired(step.getRecordingTime());//秒为单位
|
| | | boolean setTargetPosition = cameraSdkService.guideTargetPosition(cmd).get("code").equals(200);
|
| | | if (setTargetPosition) {
|
| | | /*控制相机巡检成功,开始录像*/
|
| | | cameraSdkService.recordStart(cmd);
|
| | | //region 通知前端
|
| | | Map<String, Object> message = new HashMap<>();
|
| | | Map<String, String> data = new HashMap<>();
|
| | | data.put("cameraId", cmd.getCameraId());
|
| | | data.put("wellId", well.getWellId());
|
| | | message.put("70000", data);
|
| | | WebSocketUtils.sendMessageAll(message);
|
| | | //endregion
|
| | | } else {
|
| | | /*控制失败,当前步骤启动时间置null*/
|
| | | ardVideoInspectTask.setCurrentStepStartTime("");
|
| | |
| | | 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);
|
| | | if(StringUtils.isNull(cameras))
|
| | | ArdAlarmpointsWell well = ardAlarmpointsWellMapper.selectArdAlarmpointsWellById(wellId);
|
| | | if(StringUtils.isNull(well))
|
| | | {
|
| | | log.debug("找不到相机:"+cameraId);
|
| | | log.debug("找不到井:" + well.getWellId());
|
| | | return;
|
| | | }
|
| | | double[] cameraPositon = new double[3];
|
| | | cameraPositon[0] = cameras.getLongitude();
|
| | | cameraPositon[1] = cameras.getLatitude();
|
| | | cameraPositon[2] = cameras.getAltitude();
|
| | | log.debug("找到井:" + well.getWellId());
|
| | | GuidePoint guidePoint = new GuidePoint().setLongitude(well.getLongitude()).setLatitude(well.getLatitude());
|
| | | /*获取相机坐标*/
|
| | | ArdCameras cameras = ardCamerasMapper.selectArdCamerasById(cameraId);
|
| | | if (StringUtils.isNull(cameras)) {
|
| | | log.debug("找不到相机:" + cameraId);
|
| | | return;
|
| | | }
|
| | | log.debug("找到相机:" + cameraId);
|
| | | /*控制相机巡检*/
|
| | | CameraCmd cmd = new CameraCmd();
|
| | | cmd.setCameraId(cameraId);
|
| | | cmd.setChanNo(channel);
|
| | | cmd.setTargetPosition(targetPositon);
|
| | | cmd.setTargetPosition(new double[]{guidePoint.getLongitude(), guidePoint.getLatitude()});
|
| | | cmd.setOperator("sys_patrol_inspect");
|
| | | cmd.setExpired(step.getRecordingTime() * 60);
|
| | | boolean setTargetPosition = cameraSdkService.guideTargetPosition(cmd);
|
| | | cmd.setExpired(step.getRecordingTime());//秒为单位
|
| | | boolean setTargetPosition = cameraSdkService.guideTargetPosition(cmd).get("code").equals(200);
|
| | | if (!setTargetPosition) {
|
| | | /*控制失败,当前步骤启动时间置null*/
|
| | | ardVideoInspectTask.setCurrentStepStartTime("");
|
| | | ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask);
|
| | | } else {
|
| | | log.debug("引导成功!");
|
| | | //region 通知前端
|
| | | Map<String, Object> message = new HashMap<>();
|
| | | Map<String, String> data = new HashMap<>();
|
| | | data.put("cameraId", cmd.getCameraId());
|
| | | data.put("wellId", well.getWellId());
|
| | | message.put("70000", data);
|
| | | WebSocketUtils.sendMessageAll(message);
|
| | | //endregion
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | cmd.setChanNo(channel);
|
| | | cmd.setOperator("sys_patrol_inspect");
|
| | | cmd.setRecordBucketName("record");
|
| | | cmd.setRecordObjectName("inspect_" + IdUtils.fastSimpleUUID());
|
| | | cmd.setRecordObjectName("inspectGuide/" + DateUtils.getDateYYYYMMDD() + "/" + IdUtils.fastSimpleUUID());
|
| | | String url = cameraSdkService.recordStopToMinio(cmd);
|
| | | /*插入巡检记录*/
|
| | | ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord();
|
| | |
| | | ardVideoInspectRecord.setWellName(ardAlarmpointsWell.getWellId());
|
| | | }
|
| | | Date currentStepStartDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartTime);
|
| | | Date currentStepStopDate = DateUtils.addMinutes(currentStepStartDate, step.getRecordingTime());
|
| | | Date currentStepStopDate = DateUtils.addSeconds(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));
|
| | | ardVideoInspectRecord.setRecordFilePath(url);
|
| | |
| | | ArdVideoInspectTaskStep currentStep = objectOptional.get();
|
| | | /*获取到当前步骤的开始和结束时间*/
|
| | | Date currentStepStartDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, currentStepStartTime);
|
| | | Date currentStepStopDate = DateUtils.addMinutes(currentStepStartDate, currentStep.getRecordingTime());
|
| | | Date currentStepStopDate = DateUtils.addSeconds(currentStepStartDate, currentStep.getRecordingTime());
|
| | | /*判断当前步骤时间是否过期*/
|
| | | if (!DateUtils.TimeCompare(currentStepStartDate, currentStepStopDate)) {
|
| | | return true;
|
| | |
| | |
|
| | | /**
|
| | | * 获取相机的空闲时段
|
| | | *
|
| | | * @param cameraId
|
| | | * @return
|
| | | */
|
| | | public List getCameraIdleTimeList(String cameraId) {
|
| | | LinkedList<String> timeList = new LinkedList();
|
| | | List<Map> usedPeriods = this.getTaskUsedCameraPeriods(cameraId);
|
| | | for (Map p :
|
| | | usedPeriods) {
|
| | | timeList.add((String) p.get("start_time"));
|
| | | timeList.add((String) p.get("end_time"));
|
| | | }
|
| | | //判断第一个起始点
|
| | | if (timeList.size() > 0) {
|
| | | if ("00:00:00".equals(timeList.getFirst())) {
|
| | | timeList.removeFirst();
|
| | | } else {
|
| | | timeList.addFirst("00:00:00");
|
| | | //事件段为空,则全天作为一个时间段
|
| | | if (usedPeriods.size() == 0) {
|
| | | timeList.add("00:00:00");
|
| | | timeList.add("23:59:59");
|
| | | }else{
|
| | | for (Map p :
|
| | | usedPeriods) {
|
| | | timeList.add((String) p.get("start_time"));
|
| | | timeList.add((String) p.get("end_time"));
|
| | | }
|
| | | //判断最后一个结束时间
|
| | | if ("23:59:59".equals(timeList.getLast())) {
|
| | | timeList.removeLast();
|
| | | } else {
|
| | | timeList.addLast("23:59:59");
|
| | | }
|
| | | //事件段为空,则全天作为一个时间段
|
| | | if (timeList.size() == 0) {
|
| | | timeList.add("00:00:00");
|
| | | timeList.add("23:59:59");
|
| | | }
|
| | | //判断第一个起始点
|
| | | if (timeList.size() > 0) {
|
| | | if ("00:00:00".equals(timeList.getFirst())) {
|
| | | timeList.removeFirst();
|
| | | } else {
|
| | | timeList.addFirst("00:00:00");
|
| | | }
|
| | | //判断最后一个结束时间
|
| | | if ("23:59:59".equals(timeList.getLast())) {
|
| | | timeList.removeLast();
|
| | | } else {
|
| | | timeList.addLast("23:59:59");
|
| | | }
|
| | |
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | return timeList;
|
| | | }
|
| | | }
|