张延森 5 anos atrás
pai
commit
dde3de729b

+ 46
- 0
src/main/java/com/huiju/welcome/hardware/libs/HeartMonitor.java Ver arquivo

@@ -0,0 +1,46 @@
1
+package com.huiju.welcome.hardware.libs;
2
+
3
+import com.huiju.welcome.hardware.websocket.Client;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.stereotype.Component;
6
+
7
+import java.net.URI;
8
+import java.util.Timer;
9
+import java.util.TimerTask;
10
+
11
+@Component
12
+public class HeartMonitor implements Runnable {
13
+    Client wsClient;
14
+
15
+    @Autowired
16
+    public HeartMonitor() {
17
+        initWSClient();
18
+    }
19
+
20
+    private void initWSClient() {
21
+        String url = Configer.pick("monitorhub.websocket");
22
+        if (null == url || "".equals(url.trim())) {
23
+            return;
24
+        }
25
+
26
+        url += Configer.pick("monitorhub.appid");
27
+
28
+        wsClient = new Client(URI.create(url));
29
+        wsClient.connect();
30
+    }
31
+
32
+    @Override
33
+    public void run() {
34
+        if (null == wsClient) {
35
+            return;
36
+        }
37
+
38
+        // 定时器
39
+        Timer timer = new Timer();
40
+        timer.schedule(new TimerTask() {
41
+            public void run() {
42
+                wsClient.send("ping");
43
+            }
44
+        }, 30000); // 30s
45
+    }
46
+}

+ 5
- 0
src/main/java/com/huiju/welcome/hardware/service/HikService.java Ver arquivo

@@ -46,6 +46,9 @@ public class HikService {
46 46
     @Autowired
47 47
     MainService mainService;
48 48
 
49
+    @Autowired
50
+    Monitor monitor;
51
+
49 52
     // 设备连接用户
50 53
     NativeLong user;
51 54
     // 报警 handle
@@ -77,6 +80,8 @@ public class HikService {
77 80
             log.error("探测人脸库失败: {}", e.getMessage());
78 81
         }
79 82
 
83
+        monitor.start();
84
+
80 85
         return true;
81 86
     }
82 87
 

+ 7
- 0
src/main/resources/application.properties Ver arquivo

@@ -33,3 +33,10 @@ hik.facelib=0
33 33
 # 是否记录日志, 不填则代表不写日志
34 34
 # 日志路径会拼在 hik.dlldir 后面。需要先手动创建好目录
35 35
 hik.log = \\logs
36
+
37
+# 监控中心
38
+# websocket, 最后需要以斜线结尾
39
+monitorhub.websocket=
40
+# appid 与监控中心一致的appid, 由监控中心统一指定
41
+monitorhub.appid=sz-car-detect
42
+monitorhub.appname=苏州原溪-车辆抓拍服务