2 Коміти 5761332b1a ... 34a422a84f

Автор SHA1 Опис Дата
  wyyay 34a422a84f 截图注释测试代码 6 місяців тому
  wyyay 42252d393d 截图代码修改 7 місяців тому

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

@@ -33,6 +33,8 @@ public class CameraCaptureService {
 
     public boolean getCapture(URL url, String cameraCode, String fileName) throws IOException {
         HttpURLConnection connection = null;
+//        BufferedInputStream bis = null;
+//        BufferedOutputStream bos = null;
         ByteArrayOutputStream byteArrayOutputStream = null;
         ByteArrayInputStream byteArrayInputStream = null;
         FileOutputStream fileOutputStream = null;
@@ -72,17 +74,17 @@ public class CameraCaptureService {
                     byteArrayOutputStream.write(bytes,0,index);
                 }
                 byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-                String uploadUrl = "/data/test_picture/"+ IdUtils.fastSimpleUUID()+".jpeg";
+                //String uploadUrl = "/data/test_picture/"+ IdUtils.fastSimpleUUID()+".jpeg";
 //                String uploadUrl = "d://tmp/c/"+ (cameraCode + "-" + (System.currentTimeMillis() / 1000)) +".jpeg";
 //                if (log.isDebugEnabled()) {
 //                    log.debug("生成至服务器本地开始,路径为: " + uploadUrl);
 //                }
-                fileOutputStream = new FileOutputStream(uploadUrl);
-                IOUtils.copy(byteArrayInputStream, fileOutputStream);
+                //fileOutputStream = new FileOutputStream(uploadUrl);
+                //IOUtils.copy(byteArrayInputStream, fileOutputStream);
 //                if (log.isDebugEnabled()) {
 //                    log.debug("生成至服务器本地结束,路径为: " + uploadUrl);
 //                }
-                byteArrayInputStream.reset();
+                //byteArrayInputStream.reset();
 //                if (log.isDebugEnabled()) {
 //                    log.debug("getCapture======" + fileName);
 //                }

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

@@ -92,7 +92,7 @@ public class CaptureStreamListener implements StreamListener<String, ObjectRecor
             String filePath = dataDict.getStr("address")+"/"+isNormalPath+"/"+railwayName+"/"+installMiles+"/"+ LocalDate.now().getYear() +"/"+ LocalDate.now().getMonthValue() + "/" +fileName + ".jpeg";
             // 超过时间则进行抓拍
             if (now.isAfterOrEquals(nextExecuteTime) && nextExecuteTime.between(now, DateUnit.MINUTE) < 2) {
-                genPictureTaskService.makePicture(cameraCode, dataDict.getStr("channel"), filePath);
+                genPictureTaskService.makePicture(cameraCode, dataDict.getStr("channel"), filePath, vo.getIsAlarm());
             }
             // 通过RedisTemplate手动确认消息
             stringRedisTemplate.opsForStream().acknowledge(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY, recordId.getValue());

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

@@ -1,5 +1,6 @@
 package com.ozs.web.controller.shotschedule;
 
+import cn.hutool.core.thread.ThreadUtil;
 import com.ozs.common.utils.uuid.IdUtils;
 import com.ozs.service.service.impl.CameraCaptureService;
 import lombok.extern.slf4j.Slf4j;
@@ -28,7 +29,7 @@ public class GenPictureTaskService {
     @Value("${shot.urlAddress}")
     private String urlAddress;
 
-    public boolean makePicture(String cameraCode, String channel, String filePath) {
+    public boolean makePicture(String cameraCode, String channel, String filePath, boolean isAlarm) {
         long start = System.currentTimeMillis();
         if (!ObjectUtils.isEmpty(cameraCode)) {
             try {
@@ -40,6 +41,10 @@ public class GenPictureTaskService {
 //                    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");
 //                }

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

@@ -136,6 +136,10 @@ public class ShotPictureTaskExecutors {
                     }
                     // 排除缓存中未删除, 但是系统中删除的情况
                     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);
@@ -160,7 +164,7 @@ public class ShotPictureTaskExecutors {
     /**
      * 处理预警摄像头截图, 间隔: 5s
      */
-    @Scheduled(fixedDelay = 1 * 1000, initialDelay = 10 * 1000)
+    @Scheduled(fixedDelay = 5 * 1000, initialDelay = 10 * 1000)
     public void batchProcess() {
         if (!isMaster) return;
         // 填充默认路径
@@ -215,6 +219,40 @@ public class ShotPictureTaskExecutors {
                 }
             }
         }
+    }
+
+    /**
+     * 处理预警摄像头截图, 间隔: 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;
@@ -241,5 +279,4 @@ public class ShotPictureTaskExecutors {
             }
         }
     }
-
 }