Procházet zdrojové kódy

视频截图开启

gao.qiang před 9 měsíci
rodič
revize
e80fad91fa

+ 83 - 83
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/CaptureStreamListener.java

@@ -26,92 +26,92 @@ import java.time.LocalTime;
 @Slf4j
 public class CaptureStreamListener implements StreamListener<String, ObjectRecord<String, String>> {
 
-//    @Resource
-//    private StringRedisTemplate stringRedisTemplate;
-//
-//    @Resource
-//    public RedisTemplate<String, String> redisTemplate;
-//
-//    /**
-//     * 生成 runable 任务服务提供类
-//     */
-//    @Resource
-//    private GenPictureTaskService genPictureTaskService;
-//
-//    /**
-//     * Redis 缓存服务提供类
-//     */
-//    @Resource
-//    private RedisService redisService;
-//
-//    @Override
-//    protected void finalize() throws Throwable {
-//        super.finalize();
-//    }
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
+
+    @Resource
+    public RedisTemplate<String, String> redisTemplate;
+
+    /**
+     * 生成 runable 任务服务提供类
+     */
+    @Resource
+    private GenPictureTaskService genPictureTaskService;
+
+    /**
+     * Redis 缓存服务提供类
+     */
+    @Resource
+    private RedisService redisService;
 
     @Override
-//    @Async
+    protected void finalize() throws Throwable {
+        super.finalize();
+    }
+
+    @Override
+    @Async
     public void onMessage(ObjectRecord<String, String> message) {
-//        ShotPictureTaskExecutors.RUNNING_ATOMIC_INT.incrementAndGet();
-//        BaseCameraVO vo = null;
-//        try {
-//            // 消息ID
-//            RecordId recordId = message.getId();
-//            // 消息的key和value
-//            String value = message.getValue();
-//            if (StringUtils.isNotBlank(value) && value.indexOf("cameraCode") == -1) {
-//                stringRedisTemplate.opsForStream().acknowledge(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY, recordId.getValue());
-//                stringRedisTemplate.opsForStream().delete(RedisPushService.STREAM_KEY, recordId.getValue());
-//                ShotPictureTaskExecutors.RUNNING_ATOMIC_INT.decrementAndGet();
-//                return;
-//            }
-//            Dict dataDict = JSONUtil.toBean(value, Dict.class);
-//
-//            String cameraCode = dataDict.getStr("cameraCode");
-//            String railwayName = dataDict.getStr("railwayName");
-//            String installMiles = dataDict.getStr("installMiles");
-//            Boolean isAlarm = dataDict.getBool("isAlarm");
-//            String camera_type_hash = isAlarm ? ShotPictureTaskExecutors.CAMERA_ALARM_HASH : ShotPictureTaskExecutors.CAMERA_NORMAL_HASH;
-//
-//            Object cacheObj = redisTemplate.opsForHash().get(camera_type_hash, cameraCode);
-//            vo = JSONUtil.toBean(ObjectUtils.toString(cacheObj), BaseCameraVO.class);
-//            vo.setStatus("running");
-//            if (vo.getIsAlarm() == null) {
-//                vo.setIsAlarm(isAlarm);
-//            }
-//            redisService.addToHash(camera_type_hash, vo.getCameraCode(), vo);
-//
-//            DateTime nextExecuteTime = DateTime.now();
-//            if (StringUtils.isNotBlank(dataDict.getStr("nextExecuteTime"))) {
-//                nextExecuteTime = DateTime.of(dataDict.getStr("nextExecuteTime"), "yyyy-MM-dd HH:mm:ss");
-//            }
-//            DateTime now = DateTime.now();
-//            StringBuilder fileName = new StringBuilder(cameraCode);
-//            fileName.append("-");
-//            fileName.append(DateTime.now().toString("yyyyMMddHHmmss"));
-//            String isNormalPath = isAlarm ? "alarm" : "normal";
-//            String filePath = dataDict.getStr("address")+"/"+isNormalPath+"/"+railwayName+"/"+installMiles+"/"+ LocalDate.now().getYear() +"/"+ LocalDate.now().getMonthValue() +"/"+LocalDate.now().getDayOfMonth()+ "/"+ LocalTime.now().getHour()+"/" +fileName + ".jpeg";
-//            // 超过时间则进行抓拍
-//            if (now.isAfterOrEquals(nextExecuteTime) && nextExecuteTime.between(now, DateUnit.MINUTE) < 2) {
-//                genPictureTaskService.makePicture(cameraCode, dataDict.getStr("channel"), filePath, vo.getIsAlarm());
-//            }
-//            // 通过RedisTemplate手动确认消息
-//            stringRedisTemplate.opsForStream().acknowledge(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY, recordId.getValue());
-//            stringRedisTemplate.opsForStream().delete(RedisPushService.STREAM_KEY, recordId.getValue());
-//        } catch (Exception e) {
-//            log.error("摄像头抓图出现异常, ", e);
-//        } finally {
-//            Boolean isAlarm = vo.getIsAlarm();
-//            if (isAlarm) {
-//                vo.setNextExecuteTime(DateTime.now().offset(DateField.SECOND, 1).toString("yyyy-MM-dd HH:mm:ss"));
-//            } else {
-//                vo.setNextExecuteTime(DateTime.now().offset(DateField.MINUTE, 1).toString("yyyy-MM-dd HH:mm:ss"));
-//            }
-//            vo.setStatus("complete");
-//            redisService.addToHash(isAlarm ? ShotPictureTaskExecutors.CAMERA_ALARM_HASH :
-//                    ShotPictureTaskExecutors.CAMERA_NORMAL_HASH, vo.getCameraCode(), vo);
-//            ShotPictureTaskExecutors.RUNNING_ATOMIC_INT.decrementAndGet();
-//        }
+        ShotPictureTaskExecutors.RUNNING_ATOMIC_INT.incrementAndGet();
+        BaseCameraVO vo = null;
+        try {
+            // 消息ID
+            RecordId recordId = message.getId();
+            // 消息的key和value
+            String value = message.getValue();
+            if (StringUtils.isNotBlank(value) && value.indexOf("cameraCode") == -1) {
+                stringRedisTemplate.opsForStream().acknowledge(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY, recordId.getValue());
+                stringRedisTemplate.opsForStream().delete(RedisPushService.STREAM_KEY, recordId.getValue());
+                ShotPictureTaskExecutors.RUNNING_ATOMIC_INT.decrementAndGet();
+                return;
+            }
+            Dict dataDict = JSONUtil.toBean(value, Dict.class);
+
+            String cameraCode = dataDict.getStr("cameraCode");
+            String railwayName = dataDict.getStr("railwayName");
+            String installMiles = dataDict.getStr("installMiles");
+            Boolean isAlarm = dataDict.getBool("isAlarm");
+            String camera_type_hash = isAlarm ? ShotPictureTaskExecutors.CAMERA_ALARM_HASH : ShotPictureTaskExecutors.CAMERA_NORMAL_HASH;
+
+            Object cacheObj = redisTemplate.opsForHash().get(camera_type_hash, cameraCode);
+            vo = JSONUtil.toBean(ObjectUtils.toString(cacheObj), BaseCameraVO.class);
+            vo.setStatus("running");
+            if (vo.getIsAlarm() == null) {
+                vo.setIsAlarm(isAlarm);
+            }
+            redisService.addToHash(camera_type_hash, vo.getCameraCode(), vo);
+
+            DateTime nextExecuteTime = DateTime.now();
+            if (StringUtils.isNotBlank(dataDict.getStr("nextExecuteTime"))) {
+                nextExecuteTime = DateTime.of(dataDict.getStr("nextExecuteTime"), "yyyy-MM-dd HH:mm:ss");
+            }
+            DateTime now = DateTime.now();
+            StringBuilder fileName = new StringBuilder(cameraCode);
+            fileName.append("-");
+            fileName.append(DateTime.now().toString("yyyyMMddHHmmss"));
+            String isNormalPath = isAlarm ? "alarm" : "normal";
+            String filePath = dataDict.getStr("address")+"/"+isNormalPath+"/"+railwayName+"/"+installMiles+"/"+ LocalDate.now().getYear() +"/"+ LocalDate.now().getMonthValue() +"/"+LocalDate.now().getDayOfMonth()+ "/"+ LocalTime.now().getHour()+"/" +fileName + ".jpeg";
+            // 超过时间则进行抓拍
+            if (now.isAfterOrEquals(nextExecuteTime) && nextExecuteTime.between(now, DateUnit.MINUTE) < 2) {
+                genPictureTaskService.makePicture(cameraCode, dataDict.getStr("channel"), filePath, vo.getIsAlarm());
+            }
+            // 通过RedisTemplate手动确认消息
+            stringRedisTemplate.opsForStream().acknowledge(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY, recordId.getValue());
+            stringRedisTemplate.opsForStream().delete(RedisPushService.STREAM_KEY, recordId.getValue());
+        } catch (Exception e) {
+            log.error("摄像头抓图出现异常, ", e);
+        } finally {
+            Boolean isAlarm = vo.getIsAlarm();
+            if (isAlarm) {
+                vo.setNextExecuteTime(DateTime.now().offset(DateField.SECOND, 1).toString("yyyy-MM-dd HH:mm:ss"));
+            } else {
+                vo.setNextExecuteTime(DateTime.now().offset(DateField.MINUTE, 1).toString("yyyy-MM-dd HH:mm:ss"));
+            }
+            vo.setStatus("complete");
+            redisService.addToHash(isAlarm ? ShotPictureTaskExecutors.CAMERA_ALARM_HASH :
+                    ShotPictureTaskExecutors.CAMERA_NORMAL_HASH, vo.getCameraCode(), vo);
+            ShotPictureTaskExecutors.RUNNING_ATOMIC_INT.decrementAndGet();
+        }
     }
 
 }

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

@@ -23,37 +23,37 @@ public class GenPictureTaskService {
     /**
      * 摄像头截图服务接口
      */
-//    @Resource
-//    CameraCaptureService cameraCaptureService;
-//
-//    @Value("${shot.urlAddress}")
-//    private String urlAddress;
+    @Resource
+    CameraCaptureService cameraCaptureService;
 
-//    public boolean makePicture(String cameraCode, String channel, String filePath, boolean isAlarm) {
-//        long start = System.currentTimeMillis();
-//        if (!ObjectUtils.isEmpty(cameraCode)) {
-//            try {
-////                if (log.isDebugEnabled()) {
-////                    log.debug("请求url======" + urlAddress + cameraCode + "/" + channel);
-////                }
-//                URL url = new URL(urlAddress + cameraCode + "/" + channel);
-////                if (log.isDebugEnabled()) {
-////                    log.debug("正常摄像头截图开始, url: " + url + ", fileName: " + filePath);
-////                }
-//                boolean capture = cameraCaptureService.getCapture(url, cameraCode, filePath);
-//                if (capture && isAlarm) {
-//                    ThreadUtil.sleep(500);
-//                    cameraCaptureService.getCapture(url, cameraCode, filePath);
+    @Value("${shot.urlAddress}")
+    private String urlAddress;
+
+    public boolean makePicture(String cameraCode, String channel, String filePath, boolean isAlarm) {
+        long start = System.currentTimeMillis();
+        if (!ObjectUtils.isEmpty(cameraCode)) {
+            try {
+//                if (log.isDebugEnabled()) {
+//                    log.debug("请求url======" + urlAddress + cameraCode + "/" + channel);
+//                }
+                URL url = new URL(urlAddress + cameraCode + "/" + channel);
+//                if (log.isDebugEnabled()) {
+//                    log.debug("正常摄像头截图开始, url: " + url + ", fileName: " + filePath);
+//                }
+                boolean capture = cameraCaptureService.getCapture(url, cameraCode, filePath);
+                if (capture && isAlarm) {
+                    ThreadUtil.sleep(500);
+                    cameraCaptureService.getCapture(url, cameraCode, filePath);
+                }
+//                if (log.isDebugEnabled()) {
+//                    log.debug("正常摄像头截图结束, url: " + url + (capture ? "" : ", 出现错误") + ", 共计耗时: " + ((System.currentTimeMillis() - start) / 1000) + "s");
 //                }
-////                if (log.isDebugEnabled()) {
-////                    log.debug("正常摄像头截图结束, url: " + url + (capture ? "" : ", 出现错误") + ", 共计耗时: " + ((System.currentTimeMillis() - start) / 1000) + "s");
-////                }
-//                return capture;
-//            } catch (Throwable e) {
-//                log.error("正常摄像头截图异常", e);
-//            }
-//        }
-//        return false;
-//    }
+                return capture;
+            } catch (Throwable e) {
+                log.error("正常摄像头截图异常", e);
+            }
+        }
+        return false;
+    }
 
 }

+ 7 - 7
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/RedisPushService.java

@@ -19,12 +19,12 @@ public class RedisPushService {
     public final static String STREAM_KEY = "capture";
     public final static String STREAM_CONSUMER_GROUP_KEY = "capture_group_1";
 
-//    public void pushMsg(String msg) {
-//        // 创建消息记录, 以及指定stream
-//        StringRecord stringRecord = StreamRecords.string(Collections.singletonMap("data", msg)).withStreamKey(STREAM_KEY);
-//        // 将消息添加至消息队列中
-//        this.stringRedisTemplate.opsForStream().add(stringRecord);
-////        log.info("{}已发送消息: {}", STREAM_KEY, msg);
-//    }
+    public void pushMsg(String msg) {
+        // 创建消息记录, 以及指定stream
+        StringRecord stringRecord = StreamRecords.string(Collections.singletonMap("data", msg)).withStreamKey(STREAM_KEY);
+        // 将消息添加至消息队列中
+        this.stringRedisTemplate.opsForStream().add(stringRecord);
+//        log.info("{}已发送消息: {}", STREAM_KEY, msg);
+    }
 
 }

+ 76 - 76
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/RedisStreamConsumerConfig.java

@@ -20,81 +20,81 @@ import java.util.Collections;
 @Slf4j
 public class RedisStreamConsumerConfig {
 
-//    //注入Redis模板
-//    @Resource
-//    private RedisTemplate<String, Object> redisTemplate;
-//
-//    @Bean
-//    public StreamMessageListenerContainer<String, ObjectRecord<String, String>> captureConsumerListener(
-//            RedisConnectionFactory connectionFactory, CaptureStreamListener streamListener) {
-//        StreamMessageListenerContainer<String, ObjectRecord<String, String>> container =
-//                streamContainer(RedisPushService.STREAM_KEY, connectionFactory, streamListener);
-//        container.start();
-//        return container;
-//    }
-//
-//    /**
-//     * @param myStream 从哪个流接收数据
-//     * @param connectionFactory
-//     * @param streamListener 绑定的监听类
-//     * @return
-//     */
-//    private StreamMessageListenerContainer<String, ObjectRecord<String, String>> streamContainer(String myStream,
-//                                                                                                 RedisConnectionFactory connectionFactory, StreamListener<String, ObjectRecord<String, String>> streamListener) {
-//        StreamMessageListenerContainer.StreamMessageListenerContainerOptions<String, ObjectRecord<String, String>> options =
-//                StreamMessageListenerContainer.StreamMessageListenerContainerOptions
-//                        .builder()
-//                        .pollTimeout(Duration.ofSeconds(5)) // 拉取消息超时时间
-//                        .batchSize(1) // 批量抓取消息
-//                        .targetType(String.class) // 传递的数据类型
-////                        .executor(Executors.newFixedThreadPool(1))
-//                        .build();
-//        StreamMessageListenerContainer<String, ObjectRecord<String, String>> container = StreamMessageListenerContainer
-//                .create(connectionFactory, options);
-//        //指定消费最新的消息
-//        StreamOffset<String> offset = StreamOffset.create(myStream, ReadOffset.lastConsumed());
-//        //创建消费者
-//        StreamMessageListenerContainer.StreamReadRequest<String> streamReadRequest = null;
-//        try {
-//            streamReadRequest = buildStreamReadRequest(offset, streamListener);
-//        } catch (Exception e) {
-//            log.error(e.getMessage());
-//        }
-//        //指定消费者对象
-//        container.register(streamReadRequest, streamListener);
-//        return container;
-//    }
-//
-//    private StreamMessageListenerContainer.StreamReadRequest<String> buildStreamReadRequest(StreamOffset<String> offset,
-//                                                                                            StreamListener<String, ObjectRecord<String, String>> streamListener) throws Exception {
-//        Consumer consumer = null;
-//        if (streamListener instanceof CaptureStreamListener) {
-//            //如果 流不存在 创建 stream 流
-//            if( !redisTemplate.hasKey(RedisPushService.STREAM_KEY)){
-//                redisTemplate.opsForStream().add(RedisPushService.STREAM_KEY, Collections.singletonMap("status", "init"));
-//                log.debug("初始化stream: " + RedisPushService.STREAM_KEY + "成功!");
-//            }
-//            //创建消费者组
-//            try {
-//                redisTemplate.opsForStream().createGroup(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY);
-//            } catch (Exception e) {
-//                log.debug("消费者组: " + RedisPushService.STREAM_CONSUMER_GROUP_KEY + "已存在");
-//            }
-//            consumer = Consumer.from(RedisPushService.STREAM_CONSUMER_GROUP_KEY, RedisPushService.STREAM_KEY);
-//        } else {
-//            throw new Exception("无法识别的stream key");
-//        }
-//        StreamMessageListenerContainer.StreamReadRequest<String> streamReadRequest = StreamMessageListenerContainer.StreamReadRequest.builder(offset)
-//                .errorHandler((error) -> {
-//                    error.printStackTrace();
-//                    log.error(error.getMessage());
-//                })
-//                .cancelOnError(e -> false)
-//                .consumer(consumer)
-//                //关闭自动ack确认
-//                .autoAcknowledge(false)
-//                .build();
-//        return streamReadRequest;
-//    }
+    //注入Redis模板
+    @Resource
+    private RedisTemplate<String, Object> redisTemplate;
+
+    @Bean
+    public StreamMessageListenerContainer<String, ObjectRecord<String, String>> captureConsumerListener(
+            RedisConnectionFactory connectionFactory, CaptureStreamListener streamListener) {
+        StreamMessageListenerContainer<String, ObjectRecord<String, String>> container =
+                streamContainer(RedisPushService.STREAM_KEY, connectionFactory, streamListener);
+        container.start();
+        return container;
+    }
+
+    /**
+     * @param myStream 从哪个流接收数据
+     * @param connectionFactory
+     * @param streamListener 绑定的监听类
+     * @return
+     */
+    private StreamMessageListenerContainer<String, ObjectRecord<String, String>> streamContainer(String myStream,
+                                                                                                 RedisConnectionFactory connectionFactory, StreamListener<String, ObjectRecord<String, String>> streamListener) {
+        StreamMessageListenerContainer.StreamMessageListenerContainerOptions<String, ObjectRecord<String, String>> options =
+                StreamMessageListenerContainer.StreamMessageListenerContainerOptions
+                        .builder()
+                        .pollTimeout(Duration.ofSeconds(5)) // 拉取消息超时时间
+                        .batchSize(1) // 批量抓取消息
+                        .targetType(String.class) // 传递的数据类型
+//                        .executor(Executors.newFixedThreadPool(1))
+                        .build();
+        StreamMessageListenerContainer<String, ObjectRecord<String, String>> container = StreamMessageListenerContainer
+                .create(connectionFactory, options);
+        //指定消费最新的消息
+        StreamOffset<String> offset = StreamOffset.create(myStream, ReadOffset.lastConsumed());
+        //创建消费者
+        StreamMessageListenerContainer.StreamReadRequest<String> streamReadRequest = null;
+        try {
+            streamReadRequest = buildStreamReadRequest(offset, streamListener);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        //指定消费者对象
+        container.register(streamReadRequest, streamListener);
+        return container;
+    }
+
+    private StreamMessageListenerContainer.StreamReadRequest<String> buildStreamReadRequest(StreamOffset<String> offset,
+                                                                                            StreamListener<String, ObjectRecord<String, String>> streamListener) throws Exception {
+        Consumer consumer = null;
+        if (streamListener instanceof CaptureStreamListener) {
+            //如果 流不存在 创建 stream 流
+            if( !redisTemplate.hasKey(RedisPushService.STREAM_KEY)){
+                redisTemplate.opsForStream().add(RedisPushService.STREAM_KEY, Collections.singletonMap("status", "init"));
+                log.debug("初始化stream: " + RedisPushService.STREAM_KEY + "成功!");
+            }
+            //创建消费者组
+            try {
+                redisTemplate.opsForStream().createGroup(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY);
+            } catch (Exception e) {
+                log.debug("消费者组: " + RedisPushService.STREAM_CONSUMER_GROUP_KEY + "已存在");
+            }
+            consumer = Consumer.from(RedisPushService.STREAM_CONSUMER_GROUP_KEY, RedisPushService.STREAM_KEY);
+        } else {
+            throw new Exception("无法识别的stream key");
+        }
+        StreamMessageListenerContainer.StreamReadRequest<String> streamReadRequest = StreamMessageListenerContainer.StreamReadRequest.builder(offset)
+                .errorHandler((error) -> {
+                    error.printStackTrace();
+                    log.error(error.getMessage());
+                })
+                .cancelOnError(e -> false)
+                .consumer(consumer)
+                //关闭自动ack确认
+                .autoAcknowledge(false)
+                .build();
+        return streamReadRequest;
+    }
 
 }

+ 181 - 181
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureTaskExecutors.java

@@ -98,185 +98,185 @@ public class ShotPictureTaskExecutors {
      */
 //    @Async
 //    @Scheduled(fixedDelay = 60 * 1000, initialDelay = 3 * 1000)
-//    public synchronized void initCameraConfig() {
-//        if (!isMaster) return;
-//        // 获取分布式锁
-//        boolean lockSuccess = redisTemplate.opsForValue().setIfAbsent(LOCK_CAMELA_NORMAL_KEY, "execute", Duration.ofSeconds(60));
-//        if (lockSuccess) {
-//            // 查询未解除的报警摄像头(报警摄像头逻辑沿用wangyy代码)
-//            List<String> lockedMsgAlarmCameraCodes = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", 2))
-//                    .stream().map(f -> f.getCameraCode()).distinct().collect(Collectors.toList());
-//            try {
-//                QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
-//                queryWrapper.select("distinct camera_code, channel,railway_code,install_mile");
-//                // 获取数据库中最新摄像头相关内容
-//                List<BaseCameraManagement> dbAlarms = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toList());
-//                List<BaseRailwayManagement> dbRailways = baseRailwayManagementMapper.selectList(null);
-//                if (!CollectionUtils.isEmpty(dbAlarms)) {
-//                    for(BaseRailwayManagement dbRailway:dbRailways){
-//                        redisCache.setCacheObject(dbRailway.getRailwayCode(),dbRailway.getRailwayName());
-//                    }
-//                    Set<Object> hashAlarmKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_ALARM_HASH);
-//                    Set<Object> hashNormalKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_NORMAL_HASH);
-//                    // 数据库中存在的数据, 但是缓存中不存在, 则进行补全
-//                    for (BaseCameraManagement dbAlarm : dbAlarms) {
-//                        BaseCameraVO  vo = new BaseCameraVO();
-//                        vo.setCameraCode(dbAlarm.getCameraCode());
-//                        vo.setChannel(dbAlarm.getChannel());
-//                        vo.setInstallMiles(AppendUtils.stringAppend(dbAlarm.getInstallMile()));
-//                        vo.setRailwayName(redisCache.getCacheObject(dbAlarm.getRailwayCode()));
-//                        vo.setNextExecuteTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
-//                        if (lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashAlarmKeys.contains(vo.getCameraCode())) {
-//                            vo.setIsAlarm(true);
-//                            redisService.addToHash(CAMERA_ALARM_HASH, vo.getCameraCode(), vo);
-//                        } else if (!lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashNormalKeys.contains(vo.getCameraCode())) {
-//                            vo.setIsAlarm(false);
-//                            redisService.addToHash(CAMERA_NORMAL_HASH, vo.getCameraCode(), vo);
-//                        }
-//                    }
-//                    // 排除缓存中未删除, 但是系统中删除的情况
-//                    for (Object hashAlarmKey : hashAlarmKeys) {
-//                        //如果报警信息数据库不存在但报警缓存中存在, 则进行删除
-//                        if(!lockedMsgAlarmCameraCodes.contains(hashAlarmKey)){
-//                            redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
-//                        }
-//                        // 如果在数据库中都不存在, 则进行删除删除
-//                        if (!hashAlarmKeys.contains(hashAlarmKey) && !hashNormalKeys.contains(hashAlarmKey)) {
-//                            redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
-//                            redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
-//                        } else if (hashAlarmKeys.contains(hashAlarmKey) && hashNormalKeys.contains(hashAlarmKey)) {  // 如果存在于报警SET中, 则删除正常摄像头
-//                            redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
-//                        }
-//                    }
-//                } else {
-//                    // 如果未找到数据库数据, 则清空抓图摄像头集合
-//                    redisService.redisTemplate.delete(CAMERA_ALARM_HASH);
-//                    redisService.redisTemplate.delete(CAMERA_NORMAL_HASH);
-//                }
-//            } catch (Exception e) {
-//                log.error("缓存 [摄像头抓图] 调度任务配置出现异常, ", e);
-//            } finally {
-//                redisTemplate.delete(LOCK_CAMELA_NORMAL_KEY);
-//            }
-//        }
-//    }
-//
-//    /**
-//     * 处理预警摄像头截图, 间隔: 5s
-//     */
-////    @Scheduled(fixedDelay = 5 * 1000, initialDelay = 10 * 1000)
-//    public void batchProcess() {
-//        if (!isMaster) return;
-//        // 填充默认路径
-//        String address = storeAddress;
-//        //获取截图开关
-//        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) {
-//            return;
-//        }
-//        // 获取字典值: 截图存放路径
-//        List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
-//        if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
-//            DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
-//        }
-//        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
-//            address = addressDataList.get(0).getDictLabel();
-//        }
-//        // 设置路径地址为字典表最终值
-//        Map<Object, Object> entries = redisService.redisTemplate.opsForHash().entries(CAMERA_NORMAL_HASH);
-//        if (!CollectionUtils.isEmpty(entries)) {
-//            final String finalAddress = address;
-//            for (Map.Entry<Object, Object> entry : entries.entrySet()) {
-//                BaseCameraVO item = (BaseCameraVO) entry.getValue();
-//                DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
-//                boolean after = item.getNextExecuteTime() == null ||
-//                        DateTime.now().isAfterOrEquals(nextExecuteTime) ||
-//                        (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
-//                if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
-//                    item.setStatus("");
-//                }
-//                if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
-//                    Dict dict = new Dict();
-//                    dict.put("cameraCode", item.getCameraCode());
-//                    dict.put("channel", item.getChannel());
-//                    dict.put("address", finalAddress);
-//                    dict.put("railwayName", item.getRailwayName());
-//                    dict.put("installMiles", item.getInstallMiles());
-//                    dict.put("isAlarm", false);
-//                    dict.put("nextExecuteTime", item.getNextExecuteTime());
-//                    redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
-//                }
-//            }
-//        }
-//    }
-//
-//    /**
-//     * 处理预警摄像头截图, 间隔: 1s
-//     */
-////    @Scheduled(fixedDelay = 1 * 1000, initialDelay = 10 * 1000)
-//    public void batchAlarmProcess() {
-//        if (!isMaster) return;
-//        // 填充默认路径
-//        String address = storeAddress;
-//        //获取截图开关
-//        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) {
-//            return;
-//        }
-//        // 获取字典值: 截图存放路径
-//        List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
-//        if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
-//            DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
-//        }
-//        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
-//            address = addressDataList.get(0).getDictLabel();
-//        }
-//        Map<Object, Object> alarmEntries = redisService.redisTemplate.opsForHash().entries(CAMERA_ALARM_HASH);
-//        if (!CollectionUtils.isEmpty(alarmEntries)) {
-//            final String finalAddress = address;
-//            for (Map.Entry<Object, Object> entry : alarmEntries.entrySet()) {
-//                BaseCameraVO item = (BaseCameraVO) entry.getValue();
-//                DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
-//                boolean after = item.getNextExecuteTime() == null ||
-//                        DateTime.now().isAfterOrEquals(nextExecuteTime) ||
-//                        (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
-//                if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
-//                    item.setStatus("");
-//                }
-//                if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
-//                    Dict dict = new Dict();
-//                    dict.put("cameraCode", item.getCameraCode());
-//                    dict.put("channel", item.getChannel());
-//                    dict.put("address", finalAddress);
-//                    dict.put("railwayName", item.getRailwayName());
-//                    dict.put("installMiles", item.getInstallMiles());
-//                    dict.put("isAlarm", true);
-//                    dict.put("nextExecuteTime", item.getNextExecuteTime());
-//                    redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
-//                }
-//            }
-//        }
-//    }
+    public synchronized void initCameraConfig() {
+        if (!isMaster) return;
+        // 获取分布式锁
+        boolean lockSuccess = redisTemplate.opsForValue().setIfAbsent(LOCK_CAMELA_NORMAL_KEY, "execute", Duration.ofSeconds(60));
+        if (lockSuccess) {
+            // 查询未解除的报警摄像头(报警摄像头逻辑沿用wangyy代码)
+            List<String> lockedMsgAlarmCameraCodes = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", 2))
+                    .stream().map(f -> f.getCameraCode()).distinct().collect(Collectors.toList());
+            try {
+                QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
+                queryWrapper.select("distinct camera_code, channel,railway_code,install_mile");
+                // 获取数据库中最新摄像头相关内容
+                List<BaseCameraManagement> dbAlarms = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toList());
+                List<BaseRailwayManagement> dbRailways = baseRailwayManagementMapper.selectList(null);
+                if (!CollectionUtils.isEmpty(dbAlarms)) {
+                    for(BaseRailwayManagement dbRailway:dbRailways){
+                        redisCache.setCacheObject(dbRailway.getRailwayCode(),dbRailway.getRailwayName());
+                    }
+                    Set<Object> hashAlarmKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_ALARM_HASH);
+                    Set<Object> hashNormalKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_NORMAL_HASH);
+                    // 数据库中存在的数据, 但是缓存中不存在, 则进行补全
+                    for (BaseCameraManagement dbAlarm : dbAlarms) {
+                        BaseCameraVO  vo = new BaseCameraVO();
+                        vo.setCameraCode(dbAlarm.getCameraCode());
+                        vo.setChannel(dbAlarm.getChannel());
+                        vo.setInstallMiles(AppendUtils.stringAppend(dbAlarm.getInstallMile()));
+                        vo.setRailwayName(redisCache.getCacheObject(dbAlarm.getRailwayCode()));
+                        vo.setNextExecuteTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
+                        if (lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashAlarmKeys.contains(vo.getCameraCode())) {
+                            vo.setIsAlarm(true);
+                            redisService.addToHash(CAMERA_ALARM_HASH, vo.getCameraCode(), vo);
+                        } else if (!lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashNormalKeys.contains(vo.getCameraCode())) {
+                            vo.setIsAlarm(false);
+                            redisService.addToHash(CAMERA_NORMAL_HASH, vo.getCameraCode(), vo);
+                        }
+                    }
+                    // 排除缓存中未删除, 但是系统中删除的情况
+                    for (Object hashAlarmKey : hashAlarmKeys) {
+                        //如果报警信息数据库不存在但报警缓存中存在, 则进行删除
+                        if(!lockedMsgAlarmCameraCodes.contains(hashAlarmKey)){
+                            redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
+                        }
+                        // 如果在数据库中都不存在, 则进行删除删除
+                        if (!hashAlarmKeys.contains(hashAlarmKey) && !hashNormalKeys.contains(hashAlarmKey)) {
+                            redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
+                            redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
+                        } else if (hashAlarmKeys.contains(hashAlarmKey) && hashNormalKeys.contains(hashAlarmKey)) {  // 如果存在于报警SET中, 则删除正常摄像头
+                            redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
+                        }
+                    }
+                } else {
+                    // 如果未找到数据库数据, 则清空抓图摄像头集合
+                    redisService.redisTemplate.delete(CAMERA_ALARM_HASH);
+                    redisService.redisTemplate.delete(CAMERA_NORMAL_HASH);
+                }
+            } catch (Exception e) {
+                log.error("缓存 [摄像头抓图] 调度任务配置出现异常, ", e);
+            } finally {
+                redisTemplate.delete(LOCK_CAMELA_NORMAL_KEY);
+            }
+        }
+    }
+
+    /**
+     * 处理预警摄像头截图, 间隔: 5s
+     */
+//    @Scheduled(fixedDelay = 5 * 1000, initialDelay = 10 * 1000)
+    public void batchProcess() {
+        if (!isMaster) return;
+        // 填充默认路径
+        String address = storeAddress;
+        //获取截图开关
+        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) {
+            return;
+        }
+        // 获取字典值: 截图存放路径
+        List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
+        if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
+            DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
+        }
+        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
+            address = addressDataList.get(0).getDictLabel();
+        }
+        // 设置路径地址为字典表最终值
+        Map<Object, Object> entries = redisService.redisTemplate.opsForHash().entries(CAMERA_NORMAL_HASH);
+        if (!CollectionUtils.isEmpty(entries)) {
+            final String finalAddress = address;
+            for (Map.Entry<Object, Object> entry : entries.entrySet()) {
+                BaseCameraVO item = (BaseCameraVO) entry.getValue();
+                DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
+                boolean after = item.getNextExecuteTime() == null ||
+                        DateTime.now().isAfterOrEquals(nextExecuteTime) ||
+                        (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
+                if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
+                    item.setStatus("");
+                }
+                if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
+                    Dict dict = new Dict();
+                    dict.put("cameraCode", item.getCameraCode());
+                    dict.put("channel", item.getChannel());
+                    dict.put("address", finalAddress);
+                    dict.put("railwayName", item.getRailwayName());
+                    dict.put("installMiles", item.getInstallMiles());
+                    dict.put("isAlarm", false);
+                    dict.put("nextExecuteTime", item.getNextExecuteTime());
+                    redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
+                }
+            }
+        }
+    }
+
+    /**
+     * 处理预警摄像头截图, 间隔: 1s
+     */
+//    @Scheduled(fixedDelay = 1 * 1000, initialDelay = 10 * 1000)
+    public void batchAlarmProcess() {
+        if (!isMaster) return;
+        // 填充默认路径
+        String address = storeAddress;
+        //获取截图开关
+        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) {
+            return;
+        }
+        // 获取字典值: 截图存放路径
+        List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
+        if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
+            DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
+        }
+        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
+            address = addressDataList.get(0).getDictLabel();
+        }
+        Map<Object, Object> alarmEntries = redisService.redisTemplate.opsForHash().entries(CAMERA_ALARM_HASH);
+        if (!CollectionUtils.isEmpty(alarmEntries)) {
+            final String finalAddress = address;
+            for (Map.Entry<Object, Object> entry : alarmEntries.entrySet()) {
+                BaseCameraVO item = (BaseCameraVO) entry.getValue();
+                DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
+                boolean after = item.getNextExecuteTime() == null ||
+                        DateTime.now().isAfterOrEquals(nextExecuteTime) ||
+                        (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
+                if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
+                    item.setStatus("");
+                }
+                if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
+                    Dict dict = new Dict();
+                    dict.put("cameraCode", item.getCameraCode());
+                    dict.put("channel", item.getChannel());
+                    dict.put("address", finalAddress);
+                    dict.put("railwayName", item.getRailwayName());
+                    dict.put("installMiles", item.getInstallMiles());
+                    dict.put("isAlarm", true);
+                    dict.put("nextExecuteTime", item.getNextExecuteTime());
+                    redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
+                }
+            }
+        }
+    }
 }

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

@@ -45,99 +45,99 @@ public class TaskService {
     @Autowired
     private RedisService redisService;
 
-//    public void getNormalPicture() {
-//        String address = storeAddress;
-//        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(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 (log.isDebugEnabled()) {
-//            log.debug("正常摄像机数量:"+normalSet.size());
-//        }
-//        if (!CollectionUtils.isEmpty(normalSet)) {
-//            String finalAddress = address;
-//            normalSet.forEach(item -> {
-//                String uuid = IdUtils.fastSimpleUUID();
-//                if (!ObjectUtils.isEmpty(item.getCameraCode())) {
-//                    try {
-//                        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) {
-//                        log.error("正常摄像头截图异常",e);
-//                    }
-//                }
-//            });
-//        }
-//    }
-//
-//    public void getAlarmPicture() {
-//        String address = storeAddress;
-//        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(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 (log.isDebugEnabled()) {
-//            log.debug("报警摄像机数量:"+alarmSet.size());
-//        }
-//        if(!CollectionUtils.isEmpty(alarmSet)){
-//            String finalAddress = address;
-//            alarmSet.forEach(item -> {
-//                String uuid = IdUtils.fastSimpleUUID();
-//                if(!ObjectUtils.isEmpty(item.getCameraCode())) {
-//                    try {
-//                        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) {
-//                        log.error("报警摄像头截图异常",e);
-//                    }
-//                }
-//            });
-//        }
-//    }
+    public void getNormalPicture() {
+        String address = storeAddress;
+        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(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 (log.isDebugEnabled()) {
+            log.debug("正常摄像机数量:"+normalSet.size());
+        }
+        if (!CollectionUtils.isEmpty(normalSet)) {
+            String finalAddress = address;
+            normalSet.forEach(item -> {
+                String uuid = IdUtils.fastSimpleUUID();
+                if (!ObjectUtils.isEmpty(item.getCameraCode())) {
+                    try {
+                        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) {
+                        log.error("正常摄像头截图异常",e);
+                    }
+                }
+            });
+        }
+    }
+
+    public void getAlarmPicture() {
+        String address = storeAddress;
+        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(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 (log.isDebugEnabled()) {
+            log.debug("报警摄像机数量:"+alarmSet.size());
+        }
+        if(!CollectionUtils.isEmpty(alarmSet)){
+            String finalAddress = address;
+            alarmSet.forEach(item -> {
+                String uuid = IdUtils.fastSimpleUUID();
+                if(!ObjectUtils.isEmpty(item.getCameraCode())) {
+                    try {
+                        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) {
+                        log.error("报警摄像头截图异常",e);
+                    }
+                }
+            });
+        }
+    }
 
 }