Jelajahi Sumber

fixed: 微调抓图调用

orgycat 7 bulan lalu
induk
melakukan
2fcc3f6f2f

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

@@ -19,8 +19,8 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.io.File;
 import java.time.LocalDate;
-import java.util.Calendar;
 
 @Component
 @Slf4j
@@ -93,7 +93,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 - 4
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/GenPictureTaskService.java

@@ -1,7 +1,6 @@
 package com.ozs.web.controller.shotschedule;
 
-import com.ozs.common.utils.uuid.IdUtils;
-import com.ozs.service.entity.vo.BaseCameraVO;
+import cn.hutool.core.thread.ThreadUtil;
 import com.ozs.service.service.impl.CameraCaptureService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -10,7 +9,6 @@ import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
 import java.net.URL;
-import java.util.concurrent.CountDownLatch;
 
 /**
  * @author lyao
@@ -30,7 +28,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 {
@@ -43,6 +41,10 @@ public class GenPictureTaskService {
 //                    log.debug("正常摄像头截图开始, url: " + url + ", fileName: " + fileName);
 //                }
                 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");
 //                }

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

@@ -32,7 +32,10 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.time.Duration;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -155,9 +158,9 @@ public class ShotPictureTaskExecutors {
     }
 
     /**
-     * 处理预警摄像头截图, 间隔: 5s
+     * 处理预警摄像头截图, 间隔: 5s
      */
-    @Scheduled(fixedDelay = 1 * 1000, initialDelay = 10 * 1000)
+    @Scheduled(fixedDelay = 5 * 1000, initialDelay = 10 * 1000)
     public void batchProcess() {
         if (!isMaster) return;
         // 填充默认路径
@@ -212,6 +215,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;