From 75499090564614ed79f31a61c2434699882ee29d Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 周五, 02 6月 2023 17:31:14 +0800
Subject: [PATCH] 优化

---
 ard-work/src/main/java/com/ruoyi/inspect/service/IArdVideoInspectTaskService.java         |    5 
 ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/PatrolInspectionTask.java                |  264 -----------------------------
 ruoyi-admin/pom.xml                                                                       |   20 ++
 ard-work/src/main/java/com/ruoyi/inspect/controller/TaskController.java                   |   19 +
 ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java |  209 +++++++++++++++-------
 ruoyi-admin/Dockerfile                                                                    |    7 
 6 files changed, 185 insertions(+), 339 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/inspect/controller/TaskController.java b/ard-work/src/main/java/com/ruoyi/inspect/controller/TaskController.java
index 5fb815a..c3ab320 100644
--- a/ard-work/src/main/java/com/ruoyi/inspect/controller/TaskController.java
+++ b/ard-work/src/main/java/com/ruoyi/inspect/controller/TaskController.java
@@ -2,6 +2,7 @@
 
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.inspect.service.IArdVideoInspectTaskService;
 import com.ruoyi.inspect.service.impl.InspectionTaskManager;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -26,14 +27,24 @@
 public class TaskController {
     @Autowired
     private InspectionTaskManager inspectionTaskManager;
-
+    @Autowired
+    IArdVideoInspectTaskService ardVideoInspectTaskService;
     @PreAuthorize("@ss.hasPermi('inspect:control:manual')")
     @GetMapping("/startTask/{taskId}")
     @ApiOperation("手动开启巡检")
     AjaxResult startTask(@PathVariable String taskId) {
-        // 开启巡检任务
-        inspectionTaskManager.startInspectionTask(taskId);
-        return AjaxResult.success();
+        boolean enablemanualTask = ardVideoInspectTaskService.isEnablemanualTask(taskId);
+        if (enablemanualTask)
+        {
+            // 开启巡检任务
+            inspectionTaskManager.startInspectionTask(taskId);
+            return AjaxResult.success();
+        }
+        else
+        {
+            return AjaxResult.error();
+        }
+
     }
 
     @PreAuthorize("@ss.hasPermi('inspect:control:manual')")
diff --git a/ard-work/src/main/java/com/ruoyi/inspect/service/IArdVideoInspectTaskService.java b/ard-work/src/main/java/com/ruoyi/inspect/service/IArdVideoInspectTaskService.java
index 6cf5539..ba1fe73 100644
--- a/ard-work/src/main/java/com/ruoyi/inspect/service/IArdVideoInspectTaskService.java
+++ b/ard-work/src/main/java/com/ruoyi/inspect/service/IArdVideoInspectTaskService.java
@@ -77,7 +77,10 @@
      * 手动巡检任务
      */
     public void manualTaskRun(String TaskId);
-
+    /**
+     * 判断当前相机能否开启手动
+     */
+    public boolean isEnablemanualTask(String TaskId);
     /**
      * 巡检任务
      */
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 3f1c570..b9329bb 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,6 +2,7 @@
 
 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;
@@ -46,19 +47,17 @@
     private IHikClientService hikClientService;
 
     @PostConstruct
-    public void initTask()
-    {
+    public void initTask() {
         List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskMapper.selectArdVideoInspectTaskList(new ArdVideoInspectTask());
         /*启动后将所有手动任务置为关闭*/
-        for(ArdVideoInspectTask ardVideoInspectTask:ardVideoInspectTasks)
-        {
-            if(ardVideoInspectTask.getInspectMode().equals("手动"))
-            {
+        for (ArdVideoInspectTask ardVideoInspectTask : ardVideoInspectTasks) {
+            if (ardVideoInspectTask.getInspectMode().equals("手动")) {
                 ardVideoInspectTask.setMenualSwitch("关");
                 ardVideoInspectTaskMapper.updateArdVideoInspectTask(ardVideoInspectTask);
             }
         }
     }
+
     /**
      * 查询视频巡检任务
      *
@@ -184,35 +183,75 @@
      */
     @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("手动");
+        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;
     }
 
     /**
@@ -220,48 +259,80 @@
      */
     @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();
-                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);
-                        }
+        try {
+            /*扫描当前手动开的任务,获取手动控制的相机idList*/
+            List<String> menualCameraId = new ArrayList<>();
+            ArdVideoInspectTask menualTask = new ArdVideoInspectTask();
+            menualTask.setInspectMode("手动");
+            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());
         }
     }
+
     /**
      * 自动手动合并,扫库方式,目前不使用
      */
@@ -288,12 +359,12 @@
             videoInspectTask.setArdVideoInspectTaskStepList(ardVideoInspectTaskStepList);
             String currentStepId = videoInspectTask.getCurrentStepId();//当前步骤id
             String currentStepStartTime = videoInspectTask.getCurrentStepStartTime();//当前步骤启动时间
-            if (StringUtils.isNull(currentStepId)||StringUtils.isEmpty(currentStepId)) {
+            if (StringUtils.isNull(currentStepId) || StringUtils.isEmpty(currentStepId)) {
                 //开始第一个步骤
                 videoInspectTask.setCurrentStepId(ardVideoInspectTaskStepList.get(0).getId());
                 startRunStep(videoInspectTask);
             } else {
-                if (StringUtils.isNull(currentStepStartTime)||StringUtils.isEmpty(currentStepStartTime)) {
+                if (StringUtils.isNull(currentStepStartTime) || StringUtils.isEmpty(currentStepStartTime)) {
                     //当前任务启动时间为空,则说明当前步骤被中断,直接启动当前步骤
                     startRunStep(videoInspectTask);
                 } else {
diff --git a/ruoyi-admin/Dockerfile b/ruoyi-admin/Dockerfile
new file mode 100644
index 0000000..cf735a9
--- /dev/null
+++ b/ruoyi-admin/Dockerfile
@@ -0,0 +1,7 @@
+FROM openjdk:8-jdk-alpine
+ARG JAR_FILE=target/*.jar
+COPY ${JAR_FILE} ruoyi-admin.jar
+ENV TimeZone=Asia/Shanghai
+# 使用软连接,并且将时区配置覆盖/etc/timezone
+RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone
+ENTRYPOINT ["java","-jar","/ruoyi-admin.jar"]
\ No newline at end of file
diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml
index ee560f9..3c953da 100644
--- a/ruoyi-admin/pom.xml
+++ b/ruoyi-admin/pom.xml
@@ -14,6 +14,9 @@
     <description>
         web服务入口
     </description>
+    <properties>
+        <docker.image.prefix>ruoyi</docker.image.prefix>
+    </properties>
 
     <dependencies>
 
@@ -99,7 +102,22 @@
                     <failOnMissingWebXml>false</failOnMissingWebXml>
                     <warName>${project.artifactId}</warName>
                 </configuration>   
-           </plugin>   
+           </plugin>
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>dockerfile-maven-plugin</artifactId>
+                <version>1.3.6</version>
+                <configuration>
+                    <repository>${docker.image.prefix}/${project.artifactId}</repository>
+                    <buildArgs>
+                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
+                    </buildArgs>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+            </plugin>
         </plugins>
         <finalName>${project.artifactId}</finalName>
     </build>
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/PatrolInspectionTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/PatrolInspectionTask.java
index da32f82..6837327 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/PatrolInspectionTask.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/PatrolInspectionTask.java
@@ -40,268 +40,4 @@
     public void scanRun() {
         ardVideoInspectTaskService.autoTaskRun();
     }
-
-    //自动巡检任务
-//    public void scanRun() {
-//        /*扫描所有可执行任务1-时间满足2-自动*/
-//        ArdVideoInspectTask ardVideoInspectTask = new ArdVideoInspectTask();
-//        ardVideoInspectTask.setInspectMode("自动");
-//        List<ArdVideoInspectTask> ardVideoInspectTasks = ardVideoInspectTaskService.selectArdVideoInspectTaskList(ardVideoInspectTask);
-//        for (ArdVideoInspectTask videoInspectTask : ardVideoInspectTasks) {
-//            /*遍历所有时间满足的自动任务*/
-//            boolean timeCompare = DateUtils.TimeCompare(videoInspectTask.getStartTime(), videoInspectTask.getEndTime());
-//            if (timeCompare) {
-//                /*获取当前任务的所有巡检步骤*/
-//                List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTaskService.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);
-//                        }
-//                    }
-//                }
-//            }
-//        }
-//    }
-
-//    //手动巡检任务
-//    public void ManualTaskRun(String taskId) {
-//        Timer timer = new Timer();
-//        // 5s后执行
-//        // timer.schedule(new MyTask(), 5000);
-//        // 马上执行任务,每隔2000执行一次
-//        timerTask = new TimerTask() {
-//            @Override
-//            public void run() {
-//                ArdVideoInspectTask videoInspectTask = ardVideoInspectTaskService.selectArdVideoInspectTaskById(taskId);
-//                /*获取当前任务的所有巡检步骤*/
-//                List<ArdVideoInspectTaskStep> ardVideoInspectTaskStepList = ardVideoInspectTaskService.selectArdVideoInspectTaskById(videoInspectTask.getId()).getArdVideoInspectTaskStepList();
-//                if (ardVideoInspectTaskStepList.size() == 0) {
-//                    log.error("当前任务没有发现执行步骤");
-//                    return;
-//                }
-//                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);
-//                        }
-//                    }
-//                }
-//            }
-//        };
-//        timer.scheduleAtFixedRate(timerTask, new Date(), 2000);
-//    }
-//
-//    //步骤开始
-//    private void startRunStep(ArdVideoInspectTask ardVideoInspectTask) {
-//        try {
-//            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);
-//                    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();
-//                    /*控制相机巡检*/
-//                    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) {
-//                        /*控制相机巡检成功,开始录像*/
-//                        cmd.setEnable(true);//启动录像
-//                        hikClientService.recordToMinio(cmd);
-//                        /*更新任务当前步骤id和步骤启动时间*/
-//                        ArdVideoInspectTask avit = new ArdVideoInspectTask();
-//                        avit.setId(ardVideoInspectTask.getId());
-//                        avit.setCurrentStepId(step.getId());
-//                        avit.setCurrentStepStartTime(DateUtils.getTime());
-//                        ardVideoInspectTaskService.updateArdVideoInspectTaskNoUpdater(avit);
-//                    } else {
-//                        cmd.setEnable(false);//停止录像
-//                        hikClientService.recordToMinio(cmd);
-//                        /*控制失败,当前步骤启动时间置null*/
-//                        ArdVideoInspectTask avit = new ArdVideoInspectTask();
-//                        avit.setId(ardVideoInspectTask.getId());
-//                        avit.setCurrentStepId(step.getId());
-//                        avit.setCurrentStepStartTime(null);
-//                        ardVideoInspectTaskService.updateArdVideoInspectTaskNoUpdater(avit);
-//                    }
-//                }
-//            }
-//        } catch (Exception ex) {
-//            log.error("巡检开始异常:" + ex.getMessage());
-//        }
-//    }
-//
-//    //步骤停止
-//    private void stopRunStep(ArdVideoInspectTask ardVideoInspectTask) {
-//        try {
-//            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);
-//                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);
-//                hikClientService.recordToMinio(cmd);
-//                /*插入巡检记录*/
-//                ArdVideoInspectRecord ardVideoInspectRecord = new ArdVideoInspectRecord();
-//                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);
-//            }
-//        } catch (Exception ex) {
-//            log.error("巡检停止异常:" + ex.getMessage());
-//        }
-//    }
-//
-//    //步骤判断是否过期
-//    private boolean isExpirdStep(ArdVideoInspectTask ardVideoInspectTask) {
-//        try {
-//            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;
-//            }
-//        } catch (Exception ex) {
-//            log.error("判断巡检步骤过期异常:" + ex.getMessage());
-//            return false;
-//        }
-//    }
-//
-//    //步骤切换
-//    private String changeNextStep(ArdVideoInspectTask ardVideoInspectTask) {
-//        try {
-//            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 (currentStepOrderNumber < ardVideoInspectTask.getArdVideoInspectTaskStepList().size()) {
-//                    /*小于则执行下一步骤*/
-//                    currentStepOrderNumber++;
-//                } else {
-//                    /*否则从1开始执行*/
-//                    currentStepOrderNumber = 1;
-//                }
-//                Integer nextStepOrderNumber = currentStepOrderNumber;
-//                /*更新当前任务切换新步骤*/
-//                ArdVideoInspectTask avit = new ArdVideoInspectTask();
-//                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;
-//            }
-//        } catch (Exception ex) {
-//            log.error("巡检步骤切换异常:" + ex.getMessage());
-//        }
-//        return "";
-//    }
 }

--
Gitblit v1.9.3