浏览代码

截图定时任务修改定时时间

wyyay 1 年之前
父节点
当前提交
27fb5a27db
共有 1 个文件被更改,包括 30 次插入8 次删除
  1. 30 8
      hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotExecutors.java

+ 30 - 8
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotExecutors.java

@@ -1,6 +1,9 @@
 package com.ozs.web.controller.shotschedule;
 
+import com.ozs.common.core.domain.entity.SysDictData;
+import com.ozs.common.utils.DictUtils;
 import com.ozs.system.service.ISysDictDataService;
+import com.ozs.system.service.ISysDictTypeService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
@@ -9,8 +12,11 @@ import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.Objects;
 import java.util.UUID;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -31,6 +37,8 @@ public class ShotExecutors {
     @Autowired
     private ISysDictDataService dictDataService;
     @Autowired
+    private ISysDictTypeService iSysDictTypeService;
+    @Autowired
     private TaskNormalService taskNormalService; //定时任务-没有报警摄像头
     @Autowired
     private TaskAlarmService taskAlarmService;//定时任务-报警摄像头
@@ -39,12 +47,19 @@ public class ShotExecutors {
      * 处理非预警摄像头截图
      */
     @Async
-    @Scheduled(fixedRate = 500)
+    @Scheduled(fixedRate = 60000)
     public void handleNormalPicture() {
-        boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
+        List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
+        if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
+            dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
+            DictUtils.setDictCache("shot_switch",dataList);
+        }
+        //boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
         try {
-            if (shotSwitch) {
-                taskNormalService.getNormalPicture();
+            if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
+                if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
+                    taskNormalService.getNormalPicture();
+                }
             }
         } catch (Exception e) {
             e.getMessage();
@@ -56,12 +71,19 @@ public class ShotExecutors {
      * 处理预警摄像头截图
      */
     @Async
-    @Scheduled(fixedRate = 200)
+    @Scheduled(fixedRate = 500)
     public void handleAlarmPicture() {
-        boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
+        List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
+        if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
+            dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
+            DictUtils.setDictCache("shot_switch",dataList);
+        }
+        //boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
         try {
-            if (shotSwitch) {
-                taskAlarmService.getAlarmPicture();
+            if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
+                if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
+                    taskAlarmService.getAlarmPicture();
+                }
             }
         } catch (Exception e) {
             e.getMessage();