From 5bf75f909fc56a82be653431f18c134bd32e4430 Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期六, 22 七月 2023 14:04:19 +0800 Subject: [PATCH] 增加app任务下发 --- ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java | 166 ++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 104 insertions(+), 62 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java b/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java index 4116465..4c32163 100644 --- a/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java +++ b/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java @@ -2,10 +2,11 @@ import java.text.SimpleDateFormat; import java.util.*; + import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.constant.Global; +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; @@ -14,7 +15,6 @@ import com.ruoyi.inspect.domain.ArdVideoInspectRecord; import com.ruoyi.inspect.mapper.ArdVideoInspectRecordMapper; import com.ruoyi.inspect.mapper.ArdVideoInspectTaskStepMapper; -import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import com.ruoyi.common.utils.StringUtils; @@ -35,7 +35,7 @@ * @date 2023-05-30 */ @Service -@Slf4j +@Slf4j(topic = "PatrolInspectionTask") public class ArdVideoInspectTaskServiceImpl implements IArdVideoInspectTaskService { @Resource private ArdVideoInspectTaskMapper ardVideoInspectTaskMapper; @@ -49,6 +49,8 @@ private ArdCamerasMapper ardCamerasMapper; @Resource private IHikClientService hikClientService; + @Resource + private ArdCamerasMapper camerasMapper; @PostConstruct public void initTask() { @@ -60,7 +62,7 @@ } ardVideoInspectTask.setCurrentStepId(""); ardVideoInspectTask.setCurrentStepStartTime(""); - ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask); } } @@ -171,9 +173,16 @@ */ public void insertArdVideoInspectTaskStep(ArdVideoInspectTask ardVideoInspectTask) { List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTask.getArdVideoInspectTaskStepList(); - String id = ardVideoInspectTask.getId(); + //鑾峰彇鐩告満 + ArdCameras camera = camerasMapper.selectArdCamerasById(ardVideoInspectTask.getCameraId()); + Collections.sort(ardVideoInspectTaskStepList, new ArdVideoInspectTaskStepComparator(this.ardAlarmpointsWellMapper, camera.getLongitude(), camera.getLatitude())); + String taskId = ardVideoInspectTask.getId(); + for (int i = 0; i < ardVideoInspectTaskStepList.size(); i++) { + ArdVideoInspectTaskStep step = ardVideoInspectTaskStepList.get(i); + step.setTaskId(taskId); + step.setOrderNumber(new Integer(i + 1)); + } if (StringUtils.isNotNull(ardVideoInspectTaskStepList)) { - List<ArdVideoInspectTaskStep> list = new ArrayList<ArdVideoInspectTaskStep>(); for (ArdVideoInspectTaskStep ardVideoInspectTaskStep : ardVideoInspectTaskStepList) { if (ardVideoInspectTaskStep.getId() == null) { //鏂扮殑姝ラ,娣诲姞 @@ -193,6 +202,9 @@ public void manualTaskRun(String TaskId) { try { ArdVideoInspectTask videoInspectTask = ardVideoInspectTaskMapper.selectArdVideoInspectTaskById(TaskId); + if (!videoInspectTask.getMenualSwitch().equals("寮�")) { + return; + } if (videoInspectTask.getArdVideoInspectTaskStepList().size() == 0) { return; } @@ -218,6 +230,9 @@ //寮�濮嬩笅涓�姝ラ videoInspectTask.setCurrentStepId(nextStepId); startRunStep(videoInspectTask); + }else{ + //鏈繃鏈熷皾璇曞紩瀵硷紝寮曞澶辫触娓呯┖褰撳墠姝ラ寮�濮嬫椂闂达紝鏍囪涓柇 + tryGuide(videoInspectTask); } } } @@ -304,6 +319,7 @@ continue; } videoInspectTask.setArdVideoInspectTaskStepList(ardVideoInspectTaskStepList); + String currentStepId = videoInspectTask.getCurrentStepId(); String currentStepStartTime = videoInspectTask.getCurrentStepStartTime(); if (StringUtils.isNull(currentStepId) || StringUtils.isEmpty(currentStepId)) { @@ -325,33 +341,18 @@ //寮�濮嬩笅涓�姝ラ videoInspectTask.setCurrentStepId(nextStepId); startRunStep(videoInspectTask); - } + }else{tryGuide(videoInspectTask);} } } } else { - if(Global.task_record.contains(videoInspectTask.getId())) - { - /*鍋滄褰曞儚*/ - CameraCmd cmd = new CameraCmd(); - cmd.setCameraId(videoInspectTask.getCameraId()); - cmd.setChannelNum(videoInspectTask.getChannel()); - cmd.setOperator("sys_patrol_inspect"); - cmd.setEnable(false);//鍋滄褰曞儚 - String uuid = UUID.randomUUID().toString().replace("-", ""); - String time = new SimpleDateFormat("yyyyMMdd").format(new Date()); - String recordName = videoInspectTask.getCameraId() + "/" + time + "/" + uuid + ".mp4"; - cmd.setRecordBucketName("record"); - cmd.setRecordObjectName(recordName); - cmd.setUploadMinio(true); - hikClientService.recordToMinio(cmd); + if (StringUtils.isNotEmpty(videoInspectTask.getCurrentStepId())) { + videoInspectTask.setCurrentStepId(""); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(videoInspectTask); } - if (StringUtils.isEmpty(videoInspectTask.getCurrentStepId()) || StringUtils.isEmpty(videoInspectTask.getCurrentStepStartTime())) { - continue; + if (StringUtils.isNotEmpty(videoInspectTask.getCurrentStepStartTime())) { + videoInspectTask.setCurrentStepId(""); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(videoInspectTask); } - /*杩囨湡鐨勪换鍔℃竻绌哄綋鍓嶆楠や俊鎭�*/ - videoInspectTask.setCurrentStepId(""); - videoInspectTask.setCurrentStepStartTime(""); - ardVideoInspectTaskMapper.updateArdVideoInspectTask(videoInspectTask); } } } catch (Exception ex) { @@ -417,7 +418,63 @@ log.info("褰撳墠寮�濮嬪贰妫�姝ラid涓虹┖"); return; } - log.info("姝ラ锛�" + currentStepId + "寮�濮�"); + 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(); + /*鏇存柊浠诲姟褰撳墠姝ラid鍜屾楠ゅ惎鍔ㄦ椂闂�*/ + ardVideoInspectTask.setCurrentStepId(step.getId()); + ardVideoInspectTask.setCurrentStepStartTime(DateUtils.getTime()); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask); + 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) { + /*鎺у埗鐩告満宸℃鎴愬姛锛屽紑濮嬪綍鍍�*/ + hikClientService.recordStart(cmd); + } else { + /*鎺у埗澶辫触,褰撳墠姝ラ鍚姩鏃堕棿缃畁ull*/ + ardVideoInspectTask.setCurrentStepStartTime(""); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask); + } + } + } + } catch (Exception ex) { + log.error("宸℃寮�濮嬪紓甯革細" + ex.getMessage()); + } + } + //灏濊瘯鎺у埗寮曞 + private void tryGuide(ArdVideoInspectTask ardVideoInspectTask) { + try { + String currentStepId = ardVideoInspectTask.getCurrentStepId(); + if (StringUtils.isNull(currentStepId)) { + log.info("褰撳墠寮�濮嬪贰妫�姝ラid涓虹┖"); + return; + } + log.debug("宸℃姝e父锛屽皾璇曞紩瀵硷細" + currentStepId); String cameraId = ardVideoInspectTask.getCameraId(); Integer channel = ardVideoInspectTask.getChannel(); Optional<ArdVideoInspectTaskStep> objectOptional = ardVideoInspectTask.getArdVideoInspectTaskStepList().stream() @@ -443,42 +500,30 @@ CameraCmd 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) { - if(!Global.task_record.contains(ardVideoInspectTask.getId())) - { - /*鎺у埗鐩告満宸℃鎴愬姛锛屽紑濮嬪綍鍍�*/ - cmd.setEnable(true);//鍚姩褰曞儚 - hikClientService.recordToMinio(cmd); - Global.task_record.add(ardVideoInspectTask.getId()); - } - /*鏇存柊浠诲姟褰撳墠姝ラid鍜屾楠ゅ惎鍔ㄦ椂闂�*/ - ardVideoInspectTask.setCurrentStepId(step.getId()); - ardVideoInspectTask.setCurrentStepStartTime(DateUtils.getTime()); - ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask); - } else { - cmd.setEnable(false);//鍋滄褰曞儚 - cmd.setUploadMinio(true); - hikClientService.recordToMinio(cmd); + cmd.setExpired(step.getRecordingTime()*60); + boolean setTargetPosition = hikClientService.guideTargetPosition(cmd); + if (!setTargetPosition) { /*鎺у埗澶辫触,褰撳墠姝ラ鍚姩鏃堕棿缃畁ull*/ ardVideoInspectTask.setCurrentStepStartTime(""); - ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(ardVideoInspectTask); + } + else + { + log.debug("寮曞鎴愬姛!"); } } } } catch (Exception ex) { - log.error("宸℃寮�濮嬪紓甯革細" + ex.getMessage()); + 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; @@ -496,23 +541,20 @@ 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); - Global.task_record.remove(ardVideoInspectTask.getId()); + cmd.setRecordObjectName("inspect_"+ IdUtils.fastSimpleUUID()); + String url= hikClientService.recordStopToMinio(cmd); /*鎻掑叆宸℃璁板綍*/ ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord(); ardVideoInspectRecord.setStepId(step.getId()); + ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellById(step.getWellId()); + if (StringUtils.isNotNull(ardAlarmpointsWell)) { + ardVideoInspectRecord.setWellName(ardAlarmpointsWell.getWellId()); + } 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); ardVideoInspectRecordMapper.insertArdVideoInspectRecord(ardVideoInspectRecord); } @@ -580,7 +622,7 @@ .findFirst() .orElse(null); avit.setCurrentStepId(nextStepId); - ardVideoInspectTaskMapper.updateArdVideoInspectTask(avit); + ardVideoInspectTaskMapper.updateArdVideoInspectTaskWithCurrentSetpInfo(avit); log.info("姝ラ锛�" + currentStepId + "鍒囨崲涓�" + nextStepId); return nextStepId; } @@ -622,4 +664,4 @@ return timeList; } -} \ No newline at end of file +} -- Gitblit v1.9.3