hecheng hace 3 años
padre
commit
32eb57d82d

+ 2 - 2
zd-modules/zd-forward/src/main/java/com/zd/forward/listener/StartListener.java

@@ -45,9 +45,9 @@ public class StartListener implements CommandLineRunner {
                     }
                     while (true) {
                         fireImageService.catchImage();
-                        Thread.sleep(fireProperties.getWaitTime() * 15 * 1000L);
+                        Thread.sleep(fireProperties.getWaitTime() * 1000L);
                     }
-                } catch (Exception e) {
+                } catch (ServiceException | IOException | InterruptedException e) {
                     //异常回调,防止系统因异常问题被杀死
                     log.error("=========调用产生异常:{}============", e.getMessage());
                     run();

+ 7 - 11
zd-modules/zd-forward/src/main/java/com/zd/forward/serivce/FireImageService.java

@@ -1,7 +1,6 @@
 package com.zd.forward.serivce;
 
 import com.zd.common.core.exception.ServiceException;
-import com.zd.common.core.utils.IdGen;
 import com.zd.forward.config.AlgorithmYml;
 import com.zd.forward.domain.AnalysisData;
 import com.zd.forward.domain.DataPostAnalysisRespDto;
@@ -24,7 +23,6 @@ import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Files;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -67,7 +65,7 @@ public class FireImageService {
     @Value("${file.path:/home/AIPIC}")
     private String imagePath;
 
-    public void catchImage() throws Exception {
+    public void catchImage() throws IOException {
         String streamUrl = fireProperties.getStreamUrl();
         if (streamUrl == null) {
             throw new ServiceException("未配置流媒体地址");
@@ -75,10 +73,9 @@ public class FireImageService {
 
         try (FFmpegFrameGrabber grabber = VideoUtils.createGrabber(streamUrl)) {
             grabber.start();
-            String uuid = IdGen.uuid();
+            String fileName = "test";
             //文件储存对象
-            String fileName = imagePath + File.separator + uuid;
-            File tempFile = File.createTempFile(fileName, "." + IMAGE_FORMAT);
+            File file=new File(fileName+"." + IMAGE_FORMAT);
             //获取第一帧
             Frame frame = grabber.grabFrame();
             if (frame != null) {
@@ -86,16 +83,16 @@ public class FireImageService {
                 frame = grabber.grabImage();
                 BufferedImage bufferedImage = frameToBufferedImage(frame);
                 if (bufferedImage != null) {
-                    ImageIO.write(bufferedImage, IMAGE_FORMAT, tempFile);
+                    ImageIO.write(bufferedImage, IMAGE_FORMAT, file);
                 }
-                log.info("图片地址为[{}]", tempFile.getAbsoluteFile());
+                log.info("图片地址为[{}]", file.getAbsoluteFile());
                 grabber.stop();
-                send(tempFile);
+                send(file);
             }
         }
     }
 
-    private void send(File file) throws IOException {
+    private void send(File file) {
         if (fireProperties.getAlgoId() == null) {
             throw new ServiceException("未配置火焰算法ID");
         }
@@ -125,7 +122,6 @@ public class FireImageService {
                 sendSginAccessLogService.saveAlarm(fireProperties);
             }
         }
-        Files.delete(file.getAbsoluteFile().toPath());
     }
 
     /**

+ 9 - 11
zd-modules/zd-forward/src/main/java/com/zd/forward/serivce/SendSginAccessLogService.java

@@ -117,9 +117,14 @@ public class SendSginAccessLogService {
             if (currentTimeMillis > expiryTime) {
                 expiryMap.remove(hardwareNum);
                 alarmMap.remove(hardwareNum);
-            } else {
+            }else {
                 send(properties, hardwareNum);
             }
+            int count = alarmMap.get(hardwareNum) == null ? 0 : alarmMap.get(hardwareNum);
+            ++count;
+            alarmMap.put(hardwareNum, count);
+            expiryMap.put(hardwareNum, currentTimeMillis + 30 * 1000);
+            logger.info("已触发火焰警报:{}次",alarmMap.get(hardwareNum));
         } else {
             alarmMap.put(hardwareNum, 1);
             expiryMap.put(hardwareNum, currentTimeMillis + 30 * 1000);
@@ -127,16 +132,9 @@ public class SendSginAccessLogService {
     }
 
     private void send(FireProperties properties, String hardwareNum) {
-        if (alarmMap.containsKey(hardwareNum)) {
-            Integer count = alarmMap.get(hardwareNum);
-            if (count == null) {
-                count = 0;
-            }
-            alarmMap.put(hardwareNum, count + 1);
-            R<Object> r = send(properties);
-            if (r.getCode() != HttpStatus.SUCCESS) {
-                logger.error("火焰警报失败原因:{}", r.getMsg());
-            }
+        R<Object> r = send(properties);
+        if (r.getCode() != HttpStatus.SUCCESS) {
+            logger.error("火焰警报失败原因:{}", r.getMsg());
         }
     }
 

+ 1 - 1
zd-modules/zd-forward/src/main/java/com/zd/forward/utils/HttpUtils.java

@@ -85,7 +85,7 @@ public class HttpUtils {
         MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
         //1-同步(默认),0-异步
         form.add("sync", 1);
-        form.add("timestamp", LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli() / 1000);
+        form.add("timeStamp", LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli() / 1000);
         form.add("extension", extension);
         return form;
     }