Pārlūkot izejas kodu

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

 Conflicts:
	business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java
gao.qiang 10 mēneši atpakaļ
vecāks
revīzija
0fa10124cf

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

@@ -1,6 +1,8 @@
 package com.ozs.service.service.impl;
 
 import com.ozs.common.utils.MinioUtils;
+import com.ozs.common.utils.uuid.IdUtils;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -47,7 +49,7 @@ public class CameraCaptureService {
             connection.setRequestProperty("Charsert", "UTF-8");
             //设置读取时间为30秒
             connection.setConnectTimeout(30 * 1000);
-            connection.setReadTimeout(30 * 1000);
+            connection.setReadTimeout(180 * 1000);
             connection.connect();
 
             // 返回流
@@ -63,10 +65,23 @@ public class CameraCaptureService {
                     byteArrayOutputStream.write(bytes,0,index);
                 }
                 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-                log.info("getCapture======" + fileName);
-                log.info("fileName"+fileName+"图片开始截图时间"+new Date()+"--数组大小"+bytes.length);
+//                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);
+                    log.debug("minIoClientUpload fileName:"+fileName+"图片开始截图时间"+new Date()+"--数组大小"+bytes.length);
+                }
                 minioUtils.minIoClientUpload(byteArrayInputStream, fileName);
-                log.info("fileName"+fileName+"图片结束截图时间"+new Date());
+                if (log.isDebugEnabled()) {
+                    log.debug("minIoClientUpload fileName:"+fileName+"图片结束截图时间:"+new Date());
+                }
             }
         } catch (Exception e) {
             //先关闭外层的缓冲流,再关闭内层的流,但是在关闭外层流的同时,

+ 17 - 0
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -16,6 +16,7 @@ import com.ozs.service.service.RedisService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -159,6 +160,22 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
     public void getNormalBaseCameraManagementsCache(String setType) {
         log.info("---------setType-----------"+setType);
         Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
+        if(!CollectionUtils.isEmpty(alarmSet)) {
+            Set<String> cameraCodeSet = alarmSet.stream()
+                    .map(BaseCameraVO::getCameraCode)
+                    .collect(Collectors.toSet());
+            QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
+            if (Constants.ALARM_SET.equals(setType)) {
+                // 使用QueryWrapper和notin方法根据cameraCode列表查询BaseCameraManagement数据
+                queryWrapper.notIn("camera_code", cameraCodeSet);
+                Set<BaseCameraManagement> set = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toSet());
+                set.forEach(item -> {
+                    BaseCameraVO baseCameraVO = new BaseCameraVO();
+                    baseCameraVO.setCameraCode(item.getCameraCode());
+                    baseCameraVO.setChannel(item.getChannel());
+                    redisService.addToSet(Constants.NORMAL_SET, baseCameraVO);
+                });
+            }
         log.info("---------alarmSet-----------"+alarmSet);
         Set<String> cameraCodeSet = alarmSet.stream()
                 .map(BaseCameraVO::getCameraCode)

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

@@ -1,10 +1,13 @@
 package com.ozs.web.controller.shotschedule;
 
 import com.ozs.common.core.domain.entity.SysDictData;
+import com.ozs.common.core.domain.entity.SysDictType;
+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;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
@@ -35,17 +38,33 @@ public class ShotPictureExecutors {
     private String storeAddress;
     @Resource
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+    @Autowired
+    private ISysDictTypeService iSysDictTypeService;
+    @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);
@@ -58,7 +77,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 - 22
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskService.java

@@ -47,22 +47,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){
@@ -70,6 +61,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 -> {
@@ -100,22 +94,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);
@@ -123,6 +108,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 -> {

+ 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));
     }