Ver código fonte

Merge branch 'master' of http://124.70.58.209:3000/ytrd-project-management/GeoHazardMonitor

gao.qiang 9 meses atrás
pai
commit
f657a95c2a

+ 10 - 10
business-service/src/main/java/com/ozs/service/service/impl/CameraCaptureService.java

@@ -50,7 +50,7 @@ public class CameraCaptureService {
             connection.setRequestProperty("Charsert", "UTF-8");
             //设置读取时间为30秒
             connection.setConnectTimeout(30 * 1000);
-            connection.setReadTimeout(30 * 1000);
+            connection.setReadTimeout(180 * 1000);
             connection.connect();
 
             // 返回流
@@ -66,15 +66,15 @@ public class CameraCaptureService {
                     byteArrayOutputStream.write(bytes,0,index);
                 }
                 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-                String uploadUrl = "/data/test_picture/"+ IdUtils.fastSimpleUUID()+".jpeg";
-                if (log.isDebugEnabled()) {
-                    log.debug("生成至服务器本地开始,路径为======" + uploadUrl);
-                }
-                IOUtils.copy(byteArrayInputStream, new FileOutputStream(uploadUrl));
-                if (log.isDebugEnabled()) {
-                    log.debug("生成至服务器本地结束,路径为======");
-                }
-                byteArrayInputStream.reset();
+//                String uploadUrl = "/data/test_picture/"+ IdUtils.fastSimpleUUID()+".jpeg";
+//                if (log.isDebugEnabled()) {
+//                    log.debug("生成至服务器本地开始,路径为======" + uploadUrl);
+//                }
+//                IOUtils.copy(byteArrayInputStream, new FileOutputStream(uploadUrl));
+//                if (log.isDebugEnabled()) {
+//                    log.debug("生成至服务器本地结束,路径为======");
+//                }
+//                byteArrayInputStream.reset();
                 if (log.isDebugEnabled()) {
                     log.debug("getCapture======" + fileName);
                 }

+ 36 - 4
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureExecutors.java

@@ -1,5 +1,8 @@
 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;
 import lombok.extern.slf4j.Slf4j;
@@ -11,8 +14,10 @@ import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * @author wyy
@@ -34,17 +39,31 @@ public class ShotPictureExecutors {
     private String storeAddress;
     @Resource
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+    @Autowired
+    RedisCache redisCache;
 
     /**
      * 处理非预警摄像头截图
      */
     @Async
     @Scheduled(fixedRate = 60000)
-    public synchronized void handleNormalPicture() {
+    public void handleNormalPicture() {
 
         try {
-
-            this.threadPoolTaskExecutor.execute(taskService::getNormalPicture);
+            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(status == 1){
+                this.threadPoolTaskExecutor.execute(taskService::getNormalPicture);
+            }
         } catch (Exception e) {
             e.getMessage();
             log.error("正常摄像机截图定时任务失败",e);
@@ -57,7 +76,20 @@ public class ShotPictureExecutors {
     @Scheduled(fixedRate = 500)
     public void handleAlarmPicture() {
         try {
-            this.threadPoolTaskExecutor.execute(taskService::getAlarmPicture);
+            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(status == 1){
+                this.threadPoolTaskExecutor.execute(taskService::getAlarmPicture);
+            }
         } catch (Exception e) {
             e.getMessage();
             log.error("报警摄像机截图定时任务失败",e);

+ 10 - 23
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskService.java

@@ -48,22 +48,13 @@ public class TaskService {
 
     public void getNormalPicture() {
         String address = storeAddress;
-        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);
-        }
         List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
         if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
             addressDataList = iSysDictTypeService.selectDictDataByType("shot_address");
             DictUtils.setDictCache("shot_address",addressDataList);
         }
-        if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
-            if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
-                    address = addressDataList.get(0).getDictLabel();
-                }
-            }
+        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
+            address = addressDataList.get(0).getDictLabel();
         }
         boolean isHasKeyNormal = redisService.hasKey(Constants.NORMAL_SET);
         if(!isHasKeyNormal){
@@ -71,6 +62,9 @@ public class TaskService {
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Set<BaseCameraVO> normalSet = redisService.getSetMembers(Constants.NORMAL_SET);
+        if (log.isDebugEnabled()) {
+            log.debug("正常摄像机数量:"+normalSet.size());
+        }
         if (!CollectionUtils.isEmpty(normalSet)) {
             String finalAddress = address;
             normalSet.forEach(item -> {
@@ -101,22 +95,13 @@ public class TaskService {
 
     public void getAlarmPicture() {
         String address = storeAddress;
-        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);
-        }
         List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
         if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
             addressDataList = iSysDictTypeService.selectDictDataByType("shot_address");
             DictUtils.setDictCache("shot_address",addressDataList);
         }
-        if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
-            if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
-                    address = addressDataList.get(0).getDictLabel();
-                }
-            }
+        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
+            address = addressDataList.get(0).getDictLabel();
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         boolean isHasKeyAlarm = redisService.hasKey(Constants.ALARM_SET);
@@ -124,6 +109,9 @@ public class TaskService {
             msgAlarmService.initializationCameraCache();
         }
         Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
+        if (log.isDebugEnabled()) {
+            log.debug("报警摄像机数量:"+alarmSet.size());
+        }
         if(!CollectionUtils.isEmpty(alarmSet)){
             String finalAddress = address;
             alarmSet.forEach(item -> {
@@ -152,5 +140,4 @@ public class TaskService {
             });
         }
     }
-
 }

+ 4 - 1
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,7 +152,7 @@ public class SysDictDataController extends BaseController {
     {
         dict.setUpdateBy(getUsername());
         if(StringUtils.equals(dict.getDictType(),"shot_switch")){
-            DictUtils.removeDictCache("shot_switch");
+            redisCache.setCacheObject("shot_switch",dict.getStatus());
         }
         return toAjax(dictDataService.updateDictData(dict));
     }