Browse Source

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

gao.qiang 8 months ago
parent
commit
748c1ad784

+ 31 - 0
business-service/src/main/java/com/ozs/service/entity/vo/BaseCameraVO.java

@@ -0,0 +1,31 @@
+package com.ozs.service.entity.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2024/3/7
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class BaseCameraVO implements Serializable{
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 相机编码
+     */
+    private String cameraCode;
+
+    /**
+     * 通道编号
+     */
+    private String channel;
+}

+ 5 - 2
business-service/src/main/java/com/ozs/service/service/MsgAlarmService.java

@@ -9,6 +9,7 @@ import com.ozs.service.entity.vo.*;
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * <p>
@@ -54,7 +55,9 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
 
     IPage<MsgAlarm> queryPageHome(MsgAlarmVo msgAlarmVo);
 
-    List<BaseCameraManagement> getBaseCameraManagementsByLockedMsgAlarms(Integer isLock);
+    void getNormalBaseCameraManagementsCache(String setType);
 
-    List<BaseCameraManagement> getBaseCameraManagements();
+    void initializationCameraCache();
+
+    BaseCameraManagement getBaseCameraManagementByCamereCode(String camereCode);
 }

+ 126 - 0
business-service/src/main/java/com/ozs/service/service/RedisService.java

@@ -0,0 +1,126 @@
+package com.ozs.service.service;
+
+import com.ozs.service.entity.vo.BaseCameraVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2024/3/7
+ */
+@Service
+public class RedisService {
+
+    @Autowired
+    public RedisTemplate<String, BaseCameraVO> redisTemplate;
+
+    // =============================common============================
+    /**
+     * 指定缓存失效时间
+     * @param key 键
+     * @param time 时间(秒)
+     * @return
+     */
+    public boolean expire(String key, long time) {
+        try {
+            if (time > 0) {
+                redisTemplate.expire(key, time, TimeUnit.SECONDS);
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 根据key 获取过期时间
+     * @param key 键 不能为null
+     * @return 时间(秒) 返回0代表为永久有效
+     */
+    public long getExpire(String key) {
+        return redisTemplate.getExpire(key, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 判断key是否存在
+     * @param key 键
+     * @return true 存在 false不存在
+     */
+    public boolean hasKey(String key) {
+        try {
+            return redisTemplate.hasKey(key);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    // ============================String=============================
+    /**
+     * 普通缓存获取
+     * @param key 键
+     * @return 值
+     */
+    public Object get(String key) {
+        return key == null ? null : redisTemplate.opsForValue().get(key);
+    }
+
+    /**
+     * 普通缓存放入
+     * @param key 键
+     * @param value 值
+     * @return true成功 false失败
+     */
+    public boolean set(String key, BaseCameraVO value) {
+        try {
+            redisTemplate.opsForValue().set(key, value);
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+
+    }
+
+    /**
+     * 普通缓存放入并设置时间
+     * @param key 键
+     * @param value 值
+     * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
+     * @return true成功 false 失败
+     */
+    public boolean set(String key, BaseCameraVO value, long time) {
+        try {
+            if (time > 0) {
+                redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
+            } else {
+                set(key, value);
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    // 将对象添加到set集合
+    public void addToSet(String key, BaseCameraVO object) {
+        redisTemplate.opsForSet().add(key, object);
+    }
+
+    // 从set集合中删除对象
+    public long removeFromSet(String key, BaseCameraVO object) {
+        return redisTemplate.opsForSet().remove(key, object);
+    }
+
+    // 获取set集合中的所有对象
+    public Set<BaseCameraVO> getSetMembers(String key) {
+        return redisTemplate.opsForSet().members(key);
+    }
+}

+ 54 - 28
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -1,25 +1,20 @@
 package com.ozs.service.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.pagehelper.PageHelper;
-import com.ozs.common.utils.AppendUtils;
-import com.ozs.common.utils.StringUtils;
+import com.ozs.common.constant.Constants;
 import com.ozs.service.entity.BaseCameraManagement;
-import com.ozs.service.entity.BaseUser;
 import com.ozs.service.entity.MsgAlarm;
 import com.ozs.service.entity.vo.*;
 import com.ozs.service.mapper.BaseCameraManagementMapper;
-import com.ozs.service.mapper.BaseUserMapper;
 import com.ozs.service.mapper.MsgAlarmMapper;
 import com.ozs.service.service.MsgAlarmService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ozs.service.service.RedisService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.ObjectUtils;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -38,6 +33,9 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
     private MsgAlarmMapper msgAlarmMapper;
     @Autowired
     private BaseCameraManagementMapper baseCameraManagementMapper;
+    @Autowired
+    private RedisService redisService;
+
 
     public IPage listToPage(List list, int pageNum, int pageSize) {
         List pageList = new ArrayList<>();
@@ -157,34 +155,62 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
     }
 
     @Override
-    public List<BaseCameraManagement> getBaseCameraManagementsByLockedMsgAlarms(Integer isLock) {
-        // 查询MsgAlarm中isLock=的数据
-        List<MsgAlarm> lockedMsgAlarms = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", isLock));
-        if (lockedMsgAlarms.isEmpty()) {
-            return Collections.emptyList();
-        }
-        // 提取cameraCode列表
-        List<String> cameraCodeListR = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toList());
-        List<String> cameraCodeList = new ArrayList<>(new TreeSet<>(cameraCodeListR));
-        // 使用QueryWrapper和in方法根据cameraCode列表查询BaseCameraManagement数据
+    public void getNormalBaseCameraManagementsCache(String setType) {
+        Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
         QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("camera_code", cameraCodeList);
-        List<BaseCameraManagement> list = baseCameraManagementMapper.selectList(queryWrapper);
-        return list;
+        if(Constants.ALARM_SET.equals(setType)) {
+            // 使用QueryWrapper和notin方法根据cameraCode列表查询BaseCameraManagement数据
+            queryWrapper.notIn("camera_code", alarmSet);
+            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);
+            });
+        }
     }
 
     @Override
-    public List<BaseCameraManagement> getBaseCameraManagements() {
+    public void initializationCameraCache() {
         List<MsgAlarm> lockedMsgAlarms = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", 2));
         if (lockedMsgAlarms.isEmpty()) {
-            return Collections.emptyList();
+            Set<BaseCameraManagement> normalSet = baseCameraManagementMapper.selectList(null).stream().collect(Collectors.toSet());
+            normalSet.forEach(item ->{
+                BaseCameraVO  baseCameraVO=new BaseCameraVO();
+                baseCameraVO.setCameraCode(item.getCameraCode());
+                baseCameraVO.setChannel(item.getChannel());
+                redisService.addToSet(Constants.NORMAL_SET,baseCameraVO);
+            });
+            redisService.addToSet(Constants.ALARM_SET,null);
         }
-        List<String> cameraCodeListR = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toList());
-        List<String> cameraCodeList = new ArrayList<>(new TreeSet<>(cameraCodeListR));
-        // 使用QueryWrapper和in方法根据cameraCode列表查询BaseCameraManagement数据
+        // 提取cameraCode列表
+        Set<String> cameraCodeSet = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toSet());
+        QueryWrapper<BaseCameraManagement> queryWrapperAlarm = new QueryWrapper<>();
+        queryWrapperAlarm.in("camera_code", cameraCodeSet);
+        Set<BaseCameraManagement> alarmSet = baseCameraManagementMapper.selectList(queryWrapperAlarm).stream().collect(Collectors.toSet());
+        alarmSet.forEach(item->{
+            BaseCameraVO  baseCameraVO=new BaseCameraVO();
+            baseCameraVO.setCameraCode(item.getCameraCode());
+            baseCameraVO.setChannel(item.getChannel());
+            redisService.addToSet(Constants.ALARM_SET, baseCameraVO);
+        });
+        QueryWrapper<BaseCameraManagement> queryWrapperNormal = new QueryWrapper<>();
+        queryWrapperNormal.notIn("camera_code", cameraCodeSet);
+        Set<BaseCameraManagement> normalSet = baseCameraManagementMapper.selectList(queryWrapperNormal).stream().collect(Collectors.toSet());
+        normalSet.forEach(item->{
+            BaseCameraVO  baseCameraVO=new BaseCameraVO();
+            baseCameraVO.setCameraCode(item.getCameraCode());
+            baseCameraVO.setChannel(item.getChannel());
+            redisService.addToSet(Constants.NORMAL_SET, baseCameraVO);
+        });
+    }
+
+    @Override
+    public BaseCameraManagement getBaseCameraManagementByCamereCode(String camereCode) {
         QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
-        queryWrapper.notIn("camera_code", cameraCodeList);
-        List<BaseCameraManagement> list = baseCameraManagementMapper.selectList(queryWrapper);
-        return list;
+        queryWrapper.eq("camera_code", camereCode);
+        BaseCameraManagement baseCameraManagement = baseCameraManagementMapper.selectOne(queryWrapper);
+        return baseCameraManagement;
     }
 }

+ 36 - 0
business-service/src/main/java/com/ozs/service/utils/CustomRedisConfig.java

@@ -0,0 +1,36 @@
+package com.ozs.service.utils;
+
+import com.ozs.service.entity.vo.BaseCameraVO;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2024/3/7
+ */
+@Configuration
+public class CustomRedisConfig {
+    @Bean
+    @SuppressWarnings("all")
+    public RedisTemplate<String, BaseCameraVO> myObjectRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
+        RedisTemplate<String, BaseCameraVO> template = new RedisTemplate<String, BaseCameraVO>();
+        template.setConnectionFactory(redisConnectionFactory);
+        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(BaseCameraVO.class);
+        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
+        // key采用String的序列化方式
+        template.setKeySerializer(stringRedisSerializer);
+        // hash的key也采用String的序列化方式
+        template.setHashKeySerializer(stringRedisSerializer);
+        // value序列化方式采用jackson
+        template.setValueSerializer(jackson2JsonRedisSerializer);
+        // hash的value序列化方式采用jackson
+        template.setHashValueSerializer(jackson2JsonRedisSerializer);
+        template.afterPropertiesSet();
+        return template;
+    }
+}

+ 11 - 0
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/MsgAlarmController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ozs.common.annotation.Log;
+import com.ozs.common.constant.Constants;
 import com.ozs.common.core.controller.BaseController;
 import com.ozs.common.core.domain.AjaxResult;
 import com.ozs.common.core.domain.entity.SysDept;
@@ -12,6 +13,7 @@ import com.ozs.common.core.domain.entity.SysDictData;
 import com.ozs.common.core.domain.entity.SysDictType;
 import com.ozs.common.core.domain.entity.SysUser;
 import com.ozs.common.core.domain.model.LoginUser;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.enums.BusinessType;
 import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.StringUtils;
@@ -78,6 +80,9 @@ public class MsgAlarmController extends BaseController {
     private ISysDeptService deptService;
     @Autowired
     private MsgAppPushService msgAppPushService;
+    @Autowired
+    private RedisService redisService;
+
 
     /**
      * web更多消息-总数,已读数
@@ -492,7 +497,13 @@ public class MsgAlarmController extends BaseController {
         log.info("updateIsLock-------url" + url);
         msgAlarm.setReleasedUrl(url);
         log.info("updateIsLock----------msgAlarm" + msgAlarm);
+        BaseCameraManagement bcm = msgAlarmService.getBaseCameraManagementByCamereCode(msgAlarm.getCameraCode());
+        BaseCameraVO  baseCameraVO=new BaseCameraVO();
+        baseCameraVO.setCameraCode(bcm.getCameraCode());
+        baseCameraVO.setChannel(bcm.getChannel());
+        redisService.removeFromSet(Constants.ALARM_SET,baseCameraVO);
         boolean b = msgAlarmService.updateById(msgAlarm);
+        msgAlarmService.getNormalBaseCameraManagementsCache(Constants.ALARM_SET);
 //        LambdaQueryWrapper<MsgAppPush> wrapper = new LambdaQueryWrapper<>();
 //        wrapper.eq(MsgAppPush::getAlarmId, msgAlarm.getAlarmId());
 //        MsgAppPush app = new MsgAppPush();

+ 14 - 32
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureExecutors.java

@@ -1,22 +1,18 @@
 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.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.util.CollectionUtils;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
+import javax.annotation.Resource;
 
 /**
  * @author wyy
@@ -34,6 +30,10 @@ public class ShotPictureExecutors {
     private ISysDictTypeService iSysDictTypeService;
     @Autowired
     private TaskService taskService; //任务
+    @Value("${shot.storeAddress}")
+    private String storeAddress;
+    @Resource
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
     /**
      * 处理非预警摄像头截图
@@ -41,44 +41,26 @@ public class ShotPictureExecutors {
     @Async
     @Scheduled(fixedRate = 60000)
     public synchronized void handleNormalPicture() {
-        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(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
-                if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                        taskService.getNormalPicture();
-                }
-            }
+
+            this.threadPoolTaskExecutor.execute(taskService::getNormalPicture);
         } catch (Exception e) {
             e.getMessage();
-            log.error(e.getMessage());
+            log.error("正常摄像机截图定时任务失败",e);
         }
     }
 
     /**
      * 处理预警摄像头截图
      */
-    @Async
     @Scheduled(fixedRate = 500)
-    public synchronized void handleAlarmPicture() {
-        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);
-        }
+    public void handleAlarmPicture() {
         try {
-            if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
-                if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                    taskService.getAlarmPicture();
-                }
-            }
+            this.threadPoolTaskExecutor.execute(taskService::getAlarmPicture);
         } catch (Exception e) {
             e.getMessage();
-            log.error(e.getMessage());
+            log.error("报警摄像机截图定时任务失败",e);
         }
     }
 }

+ 100 - 72
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskService.java

@@ -1,33 +1,29 @@
 package com.ozs.web.controller.shotschedule;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.ozs.common.utils.MinioUtils;
+import com.ozs.common.constant.Constants;
+import com.ozs.common.core.domain.entity.SysDictData;
+import com.ozs.common.utils.DictUtils;
 import com.ozs.common.utils.uuid.IdUtils;
-import com.ozs.service.entity.BaseCameraManagement;
-import com.ozs.service.entity.MsgAlarm;
+import com.ozs.service.entity.vo.BaseCameraVO;
 import com.ozs.service.service.BaseCameraManagementService;
 import com.ozs.service.service.MsgAlarmService;
+import com.ozs.service.service.RedisService;
 import com.ozs.service.service.impl.CameraCaptureService;
-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.beans.factory.annotation.Value;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
-import java.util.concurrent.*;
-import java.util.stream.Collectors;
+import java.util.Set;
 
 /**
  * @author wyy
@@ -37,50 +33,66 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class TaskService {
-    private  static ExecutorService executorService = Executors.newFixedThreadPool(50);
-    private  static ExecutorService alarmExecutorService = Executors.newFixedThreadPool(10);
-    @Resource
-    BaseCameraManagementService baseCameraManagementService;
     @Resource
     MsgAlarmService msgAlarmService;
     @Resource
     CameraCaptureService cameraCaptureService;
-    @Autowired
-    private ISysDictDataService dictDataService;
-    private  static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
     @Value("${shot.urlAddress}")
     private String urlAddress;
+    @Value("${shot.storeAddress}")
+    private String storeAddress;
+    @Autowired
+    private ISysDictTypeService iSysDictTypeService;
+    @Autowired
+    private RedisService redisService;
 
     public void getNormalPicture() {
-        List<BaseCameraManagement> list = msgAlarmService.getBaseCameraManagements();
-        if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
-            list.forEach(l -> {
+        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();
+                }
+            }
+        }
+        boolean isHasKeyNormal = redisService.hasKey(Constants.NORMAL_SET);
+        if(!isHasKeyNormal){
+            msgAlarmService.initializationCameraCache();
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Set<BaseCameraVO> normalSet = redisService.getSetMembers(Constants.NORMAL_SET);
+        if (!CollectionUtils.isEmpty(normalSet)) {
+            String finalAddress = address;
+            normalSet.forEach(item -> {
                 String uuid = IdUtils.fastSimpleUUID();
-                if (!ObjectUtils.isEmpty(l.getCameraCode()) && !ObjectUtils.isEmpty(l.getChannel())) {
+                if (!ObjectUtils.isEmpty(item.getCameraCode())) {
                     try {
-                        System.out.println(urlAddress + l.getCameraCode() + "/" + l.getChannel());
-                        log.info("请求url======" + urlAddress + l.getCameraCode() + "/" + l.getChannel());
-                        URL url = new URL(urlAddress + l.getCameraCode() + "/" + l.getChannel());
-                        String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
-                        String dateString = format.format(new Date());
-                        String fileName = root + "/" + "normal" + "/" + dateString + "/" + uuid + ".jpeg";
-                        log.info("fileName======" + fileName);
-                        executorService.submit(new Runnable() {
-                            @Override
-                            public void run() {
-                                log.info("调用图片生成服务开始");
-                                try {
-                                    System.out.println("fileName"+fileName+"正常图片开始截图时间"+new Date());
-                                    cameraCaptureService.getCapture(url, fileName);
-                                } catch (IOException e) {
-                                    e.printStackTrace();
-                                }
-                                log.info("调用图片生成服务结束");
-                            }
-                        });
+                        if (log.isDebugEnabled()) {
+                            log.debug("请求url======" + urlAddress + item.getCameraCode() + "/" + item.getChannel());
+                        }
+                        URL url = new URL(urlAddress + item.getCameraCode() + "/" + item.getChannel());
+                        String dateString = sdf.format(new Date());
+                        String fileName = finalAddress + "/" + "normal" + "/" + dateString + "/" + uuid + ".jpeg";
+                        if (log.isDebugEnabled()) {
+                            log.debug("fileName======" + fileName);
+                            log.debug("正常摄像头截图开始");
+                        }
+                        cameraCaptureService.getCapture(url, fileName);
+                        if (log.isDebugEnabled()) {
+                            log.debug("正常摄像头截图结束");
+                        }
                     } catch (Throwable e) {
-                        e.printStackTrace();
-                        log.error(e.getMessage());
+                        log.error("正常摄像头截图异常",e);
                     }
                 }
             });
@@ -88,37 +100,53 @@ public class TaskService {
     }
 
     public void getAlarmPicture() {
-        List<BaseCameraManagement> msgAlarmList = msgAlarmService.getBaseCameraManagementsByLockedMsgAlarms(2);
-        if(!CollectionUtils.isEmpty(msgAlarmList) && Objects.nonNull(msgAlarmList.get(0))){
-            msgAlarmList.forEach(l -> {
+        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();
+                }
+            }
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        boolean isHasKeyAlarm = redisService.hasKey(Constants.ALARM_SET);
+        if(!isHasKeyAlarm){
+            msgAlarmService.initializationCameraCache();
+        }
+        Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
+        if(!CollectionUtils.isEmpty(alarmSet)){
+            String finalAddress = address;
+            alarmSet.forEach(item -> {
                 String uuid = IdUtils.fastSimpleUUID();
-                QueryWrapper<BaseCameraManagement> wrapper = new QueryWrapper<BaseCameraManagement>();
-                wrapper.lambda().eq(BaseCameraManagement::getCameraCode,l.getCameraCode());
-                BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
-                if(!ObjectUtils.isEmpty(l.getCameraCode()) &&!ObjectUtils.isEmpty(baseCameraManagement)){
+                if(!ObjectUtils.isEmpty(item.getCameraCode())) {
                     try {
-                        System.out.println(urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
-                        log.info("请求url======"+urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
-                        URL url = new URL(urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
-                        String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
-                        String dateString = format.format(new Date());
-                        String fileName = root + "/" + "alarm" + "/" + dateString + "/" + uuid + ".jpeg";
-                        log.info("fileName======"+fileName);
-                        alarmExecutorService.submit(new Runnable() {
-                            @Override
-                            public void run() {
-                                log.info("报警摄像头截图开始");
-                                try {
-                                    cameraCaptureService.getCapture(url, fileName);
-                                } catch (IOException e) {
-                                    e.printStackTrace();
-                                }
-                                log.info("报警摄像头截图结束");
-                            }
-                        });
+                        if (log.isDebugEnabled()) {
+                            log.debug("请求url======" + urlAddress + item.getCameraCode() + "/" + item.getChannel());
+                        }
+                        URL url = new URL(urlAddress + item.getCameraCode() + "/" + item.getChannel());
+                        String dateString = sdf.format(new Date());
+                        String fileName = finalAddress + "/" + "alarm" + "/" + dateString + "/" + uuid + ".jpeg";
+                        if (log.isDebugEnabled()) {
+                            log.debug("fileName======" + fileName);
+                            log.debug("报警摄像头截图开始");
+                        }
+                        cameraCaptureService.getCapture(url, fileName);
+                        if (log.isDebugEnabled()) {
+                            log.debug("报警摄像头截图结束");
+                        }
+
                     } catch (Throwable e) {
-                        e.printStackTrace();
-                        log.error(e.getMessage());
+                        log.error("报警摄像头截图异常",e);
                     }
                 }
             });

+ 9 - 0
hazard-admin/src/main/resources/application.yml

@@ -77,6 +77,14 @@ spring:
     restart:
       # 热部署开关
       enabled: true
+  #线程池配置
+  task:
+    execution:
+      pool:
+        #cpu内核数/2
+        core-size: 4
+        #cpu内核数 + 1
+        max-size: 8
   # redis 配置
   redis:
     # 地址
@@ -165,3 +173,4 @@ mqtt:
 
 shot:
   urlAddress: http://124.70.58.209:9080/snap/
+  storeAddress: camera_picture

+ 13 - 0
hazard-sdk/src/main/java/com/ozs/controller/upload/GeoHazardMonitorTokenController.java

@@ -3,7 +3,9 @@ package com.ozs.controller.upload;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ozs.common.annotation.SdkLog;
+import com.ozs.common.constant.Constants;
 import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.enums.BusinessType;
 import com.ozs.common.enums.BusinessTypeSdk;
@@ -17,6 +19,7 @@ import com.ozs.service.entity.BaseUser;
 import com.ozs.service.entity.MsgAlarm;
 import com.ozs.service.entity.MsgAlarmFrequency;
 import com.ozs.service.entity.SvcAddress;
+import com.ozs.service.entity.vo.BaseCameraVO;
 import com.ozs.service.service.*;
 import com.ozs.vo.ReqDeviceVo;
 import com.ozs.vo.ReqMsgAlarmVo;
@@ -26,6 +29,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.SetOperations;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -38,6 +42,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.nio.charset.StandardCharsets;
 import java.text.ParseException;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 1. 获取身份认证控制层
@@ -66,6 +71,8 @@ public class GeoHazardMonitorTokenController {
     private BaseUserService baseUserService;
     @Autowired
     private RedisCache redisCache;
+    @Autowired
+    private RedisService redisService;
 
     /**
      * 获取web访问令牌
@@ -191,6 +198,12 @@ public class GeoHazardMonitorTokenController {
                 log.info("时间++++" + new Date(reqMsgAlarmVo.getAlarmTime()));
                 msgAlarm.setAlarmTime(new Date(reqMsgAlarmVo.getAlarmTime()));
                 log.info("时间++++get" + msgAlarm.getAlarmTime());
+                BaseCameraManagement bcm = msgAlarmService.getBaseCameraManagementByCamereCode(msgAlarm.getCameraCode());
+                BaseCameraVO baseCameraVO=new BaseCameraVO();
+                baseCameraVO.setCameraCode(bcm.getCameraCode());
+                baseCameraVO.setChannel(bcm.getChannel());
+                redisService.addToSet(Constants.ALARM_SET,baseCameraVO);
+                msgAlarmService.getNormalBaseCameraManagementsCache(Constants.ALARM_SET);
                 msgAlarmService.save(msgAlarm);
                 msgAlarmVice.setImageUrl(url.substring(0, url.length() - 1));
                 msgAlarmVice.setCreateBy(admin.getUserId());