Browse Source

截图定时优化

wyyay 9 months ago
parent
commit
c66a6073b6

+ 25 - 10
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureExecutors.java

@@ -1,6 +1,7 @@
 package com.ozs.web.controller.shotschedule;
 
 import com.ozs.common.core.domain.entity.SysDictData;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.utils.DictUtils;
 import com.ozs.system.service.ISysDictDataService;
 import com.ozs.system.service.ISysDictTypeService;
@@ -38,6 +39,8 @@ public class ShotPictureExecutors {
     private String storeAddress;
     @Resource
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+    @Autowired
+    RedisCache redisCache;
 
     /**
      * 处理非预警摄像头截图
@@ -47,12 +50,18 @@ public class ShotPictureExecutors {
     public void handleNormalPicture() {
 
         try {
-            List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
-            if(CollectionUtils.isEmpty(dataList)){
-                dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
-                DictUtils.setDictCache("shot_switch",dataList);
+            Integer status = redisCache.getCacheObject("shot_switch");
+            if(status == null){
+                List<SysDictData> dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
+                if(CollectionUtils.isEmpty(dataList)){
+                    redisCache.setCacheObject("shot_switch",2);
+                    status = redisCache.getCacheObject("shot_switch");
+                }else{
+                    redisCache.setCacheObject("shot_switch",dataList.get(0).getStatus());
+                    status = redisCache.getCacheObject("shot_switch");
+                }
             }
-            if(Boolean.parseBoolean(dataList.get(0).getDictLabel())){
+            if(status == 1){
                 this.threadPoolTaskExecutor.execute(taskService::getNormalPicture);
             }
         } catch (Exception e) {
@@ -67,12 +76,18 @@ public class ShotPictureExecutors {
     @Scheduled(fixedRate = 500)
     public void handleAlarmPicture() {
         try {
-            List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
-            if(CollectionUtils.isEmpty(dataList)){
-                dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
-                DictUtils.setDictCache("shot_switch",dataList);
+            Integer status = redisCache.getCacheObject("shot_switch");
+            if(status == null){
+                List<SysDictData> dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
+                if(CollectionUtils.isEmpty(dataList)){
+                    redisCache.setCacheObject("shot_switch",2);
+                    status = redisCache.getCacheObject("shot_switch");
+                }else{
+                    redisCache.setCacheObject("shot_switch",dataList.get(0).getStatus());
+                    status = redisCache.getCacheObject("shot_switch");
+                }
             }
-            if(Boolean.parseBoolean(dataList.get(0).getDictLabel())){
+            if(status == 1){
                 this.threadPoolTaskExecutor.execute(taskService::getAlarmPicture);
             }
         } catch (Exception e) {

+ 4 - 3
hazard-admin/src/main/java/com/ozs/web/controller/system/SysDictDataController.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ozs.common.core.domain.vo.SysDictDataVo;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.utils.DictUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -43,6 +44,8 @@ public class SysDictDataController extends BaseController {
 
     @Autowired
     private ISysDictTypeService dictTypeService;
+    @Autowired
+    RedisCache redisCache;
 
 //    @PreAuthorize("@ss.hasPermi('system:dict:list')")
 //    @GetMapping("/list")
@@ -149,9 +152,7 @@ public class SysDictDataController extends BaseController {
     {
         dict.setUpdateBy(getUsername());
         if(StringUtils.equals(dict.getDictType(),"shot_switch")){
-            List<SysDictData> dataList = new ArrayList<>();
-            dataList.add(dict);
-            DictUtils.setDictCache("shot_switch",dataList);
+            redisCache.setCacheObject("shot_switch",dict.getStatus());
         }
         return toAjax(dictDataService.updateDictData(dict));
     }