Selaa lähdekoodia

1、报警记录的获取由原来的直接从摄像头获取改为从超脑获取
2、报警记录中增加图片信息

zhangchun 9 kuukautta sitten
vanhempi
commit
4675f7d8b3

+ 49 - 8
pom.xml

@@ -3,20 +3,27 @@
3 3
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4 4
     <modelVersion>4.0.0</modelVersion>
5 5
     <parent>
6
-        <groupId>com.unitssoft</groupId>
7
-        <artifactId>smart-grp-nof-pom</artifactId>
8
-        <version>0.0.1-SNAPSHOT</version>
9
-        <relativePath>../smart-grp-nof-pom/pom.xml</relativePath>
6
+        <groupId>org.springframework.boot</groupId>
7
+        <artifactId>spring-boot-starter-parent</artifactId>
8
+        <version>2.3.12.RELEASE</version>
9
+        <relativePath/> <!-- lookup parent from repository -->
10 10
     </parent>
11 11
 
12 12
     <artifactId>smart-grp-nof-devices</artifactId>
13 13
     <groupId>com.unissoft</groupId>
14
-    <version>0.0.1-SNAPSHOT</version>
14
+    <version>1.0</version>
15 15
     <name>smart-grp-nof-devices</name>
16
-    <description>Demo project for Spring Boot</description>
17 16
     <packaging>jar</packaging>
18 17
     <properties>
19 18
         <java.version>1.8</java.version>
19
+        <springboot.version>2.3.12.RELEASE</springboot.version>
20
+        <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
21
+        <logstash.version>7.0.1</logstash.version>
22
+        <fastjson.version>1.2.83</fastjson.version>
23
+        <lombok.version>1.18.20</lombok.version>
24
+        <jna.version>1.0</jna.version>
25
+        <dom4j.version>2.1.4</dom4j.version>
26
+        <spring-web.version>5.2.15.RELEASE</spring-web.version>
20 27
     </properties>
21 28
     <dependencies>
22 29
         <!-- cloud -->
@@ -33,6 +40,7 @@
33 40
             <groupId>com.alibaba</groupId>
34 41
             <artifactId>fastjson</artifactId>
35 42
             <version>${fastjson.version}</version>
43
+
36 44
         </dependency>
37 45
         <dependency>
38 46
             <groupId>org.projectlombok</groupId>
@@ -42,7 +50,6 @@
42 50
             <groupId>org.springframework.boot</groupId>
43 51
             <artifactId>spring-boot-starter-integration</artifactId>
44 52
         </dependency>
45
-        <!-- 引入本地依赖 start -->
46 53
         <dependency>
47 54
             <groupId>com.sun.jna</groupId>
48 55
             <artifactId>jna</artifactId>
@@ -58,7 +65,33 @@
58 65
             <artifactId>dom4j</artifactId>
59 66
             <version>${dom4j.version}</version>
60 67
         </dependency>
61
-        <!-- 引入外部依赖 end -->
68
+        <!-- SpringWeb模块-->
69
+        <dependency>
70
+            <groupId>org.springframework</groupId>
71
+            <artifactId>spring-web</artifactId>
72
+            <version>${spring-web.version}</version>
73
+        </dependency>
74
+        <dependency>
75
+            <groupId>com.google.code.findbugs</groupId>
76
+            <artifactId>annotations</artifactId>
77
+            <version>3.0.1</version>
78
+        </dependency>
79
+        <dependency>
80
+            <groupId>commons-codec</groupId>
81
+            <artifactId>commons-codec</artifactId>
82
+            <version>1.14</version>
83
+        </dependency>
84
+        <dependency>
85
+            <groupId>org.junit.jupiter</groupId>
86
+            <artifactId>junit-jupiter</artifactId>
87
+            <scope>test</scope>
88
+        </dependency>
89
+        <dependency>
90
+            <groupId>org.springframework.boot</groupId>
91
+            <artifactId>spring-boot-test</artifactId>
92
+            <version>${springboot.version}</version>
93
+            <scope>test</scope>
94
+        </dependency>
62 95
     </dependencies>
63 96
 
64 97
     <!-- springCloud version -->
@@ -80,6 +113,14 @@
80 113
                 <groupId>org.springframework.boot</groupId>
81 114
                 <artifactId>spring-boot-maven-plugin</artifactId>
82 115
             </plugin>
116
+            <!--打包时跳过测试-->
117
+            <plugin>
118
+                <groupId>org.apache.maven.plugins</groupId>
119
+                <artifactId>maven-surefire-plugin</artifactId>
120
+                <configuration>
121
+                    <skipTests>true</skipTests>
122
+                </configuration>
123
+            </plugin>
83 124
         </plugins>
84 125
     </build>
85 126
 </project>

+ 10 - 4
src/main/java/com/unissoft/face/Alarm.java

@@ -57,19 +57,25 @@ public class Alarm {
57 57
      * 注意: 设置监听前需要现在本机pc配置端口
58 58
      * 具体步骤:库文件ClientDemo->登录设备->配置->网络参数配置->配置告警管理主机地址、告警管理主机端口(需要与NET_DVR_StartListen_V30接口中对应)
59 59
      */
60
-    public void StartListen() {
60
+    public static void StartListen() {
61 61
         if (fMSFCallBack_V31 == null) {
62 62
             fMSFCallBack_V31 = new FMSGCallBack_V31();
63
+            Pointer pUser = null;
64
+            if (!FaceMain.hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) {
65
+                log.error("设置回调函数失败!");
66
+            } else {
67
+                log.info("设置回调函数成功!");
68
+            }
63 69
         }
64 70
         /**
65 71
          * 这里NET_DVR_StartListen_V30接口中的ip和端口需要和配置的ip和端口对应
66 72
          * NET_DVR_StartListen_V30中传入的IP和端口是服务器或者测试PC的IP地址和端口,不是设备的IP和端口!!!
67 73
          */
68
-        FaceMain.lListenHandle = FaceMain.hCNetSDK.NET_DVR_StartListen_V30("10.17.36.14", (short) 7201, fMSFCallBack_V31, null);
74
+        FaceMain.lListenHandle = FaceMain.hCNetSDK.NET_DVR_StartListen_V30(null, (short) 17201, fMSFCallBack_V31, null);
69 75
         if (FaceMain.lListenHandle == -1) {
70
-            log.error("监听失败: {}", FaceMain.hCNetSDK.NET_DVR_GetLastError());
76
+            log.error("在端口17201启动报警监听失败: {}", FaceMain.hCNetSDK.NET_DVR_GetLastError());
71 77
         } else {
72
-            log.info("监听成功");
78
+            log.info("在端口17201启动报警监听成功");
73 79
         }
74 80
     }
75 81
 

+ 129 - 32
src/main/java/com/unissoft/face/FaceMain.java

@@ -1,10 +1,12 @@
1 1
 package com.unissoft.face;
2 2
 
3 3
 import com.sun.jna.Native;
4
+import com.sun.jna.Pointer;
4 5
 import com.unissoft.common.osSelect;
5 6
 import com.unissoft.netSDKDemo.HCNetSDK;
6 7
 import com.unissoft.pushMsg.AddressModel;
7 8
 import lombok.extern.slf4j.Slf4j;
9
+import org.dom4j.util.StringUtils;
8 10
 import org.springframework.boot.ApplicationArguments;
9 11
 import org.springframework.boot.ApplicationRunner;
10 12
 import org.springframework.core.annotation.Order;
@@ -14,6 +16,9 @@ import javax.annotation.Resource;
14 16
 import java.io.BufferedReader;
15 17
 import java.io.IOException;
16 18
 import java.io.InputStreamReader;
19
+import java.time.LocalDate;
20
+import java.util.Calendar;
21
+import java.util.Date;
17 22
 import java.util.Scanner;
18 23
 
19 24
 @Slf4j
@@ -35,6 +40,7 @@ public class FaceMain implements ApplicationRunner {
35 40
      */
36 41
     private void mainMethod() {
37 42
         log.info("FaceMain mainMethod===========================================================init thread");
43
+
38 44
         try {
39 45
             if (hCNetSDK == null) {
40 46
                 if (!CreateSDKInstance()) {
@@ -42,13 +48,16 @@ public class FaceMain implements ApplicationRunner {
42 48
                     return;
43 49
                 }
44 50
             }
51
+
45 52
             //linux系统建议调用以下接口加载组件库
46 53
             if (osSelect.isLinux()) {
54
+                System.out.println("linux system come in here");
47 55
                 HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
48 56
                 HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
49 57
                 //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
50 58
                 String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
51 59
                 String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
60
+                System.out.println("strPath1:" + strPath1);
52 61
 
53 62
                 System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
54 63
                 ptrByteArray1.write();
@@ -64,7 +73,6 @@ public class FaceMain implements ApplicationRunner {
64 73
                 struComPath.write();
65 74
                 hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
66 75
             }
67
-
68 76
             //初始化
69 77
             hCNetSDK.NET_DVR_Init();
70 78
 
@@ -74,7 +82,7 @@ public class FaceMain implements ApplicationRunner {
74 82
             //登录设备,每一台设备分别登录; 登录句柄是唯一的,可以区分设备
75 83
             HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
76 84
             HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
77
-
85
+            //m_strDeviceInfo.struDeviceV30.
78 86
             String m_sDeviceIP = addressModel.getDeviceIP();//设备ip地址
79 87
             m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
80 88
             System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
@@ -92,6 +100,7 @@ public class FaceMain implements ApplicationRunner {
92 100
             m_strLoginInfo.byLoginMode = 0;  //登录模式:0- SDK私有协议,1- ISAPI协议
93 101
             m_strLoginInfo.write();
94 102
 
103
+
95 104
             lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
96 105
             if (lUserID == -1) {
97 106
                 log.error("登录失败,错误码为: {}", hCNetSDK.NET_DVR_GetLastError());
@@ -100,49 +109,74 @@ public class FaceMain implements ApplicationRunner {
100 109
                 m_strDeviceInfo.read();
101 110
             }
102 111
 
112
+            try {
113
+                log.info("進行撤防");
114
+                hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle);
115
+            } catch (Exception e) {
116
+                log.info("不需要撤防");
117
+            }
118
+            try {
119
+                log.info("停止监听");
120
+                hCNetSDK.NET_DVR_StopListen_V30(lListenHandle);
121
+            } catch (Exception e) {
122
+                log.info("不需要停止监听");
123
+            }
124
+
103 125
             //报警布防实时接收人脸比对的结果信息,也可以单独参考“2-报警布防监听”这个Demo示例
104 126
             Alarm.SetAlarm(lUserID);
105 127
 
106 128
             // TODO 暂停状态 需要测试改造
129
+            Date satart = new Date();
130
+            Calendar c1 = Calendar.getInstance();
131
+            c1.setTime(satart);
107 132
             while (true) {
108 133
                 //这里加入控制台输入控制,是为了保持连接状态,当输入Y表示布防结束
109
-                log.info("请选择是否撤出布防(Y/N):");
134
+                log.info("监听进行中,输入字母Q可退出监听");
110 135
                 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
111 136
                 String str = bufferedReader.readLine();
112
-                if (str.toUpperCase().equals("Y")) {
137
+                if (str.toUpperCase().equals("Q")) {
138
+                    break;
139
+                 /*
140
+                Thread.sleep(60000);
141
+                Date end = new Date();
142
+                Calendar c2 = Calendar.getInstance();
143
+                c2.setTime(end);
144
+                long millis = c2.getTimeInMillis() - c1.getTimeInMillis();
145
+                long hours = millis/(1000*60*60);
146
+                if(hours > 10) {
147
+                    log.info("时间过去10小时,退出程序");
113 148
                     break;
114 149
                 }
115
-            }
116
-            Thread.sleep(3000);
117
-
118
-            //退出之前判断布防监听状态,并做撤防和停止监听操作
119
-            if (lAlarmHandle >= 0) {
120
-                if (!hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
121
-                    log.error("撤防失败,错误码: {}", hCNetSDK.NET_DVR_GetLastError());
122
-                } else {
123
-                    log.info("撤防成功!!!");
150
+                }*/
124 151
                 }
125
-            }
126
-            if (lListenHandle >= 0) {
127
-                if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
128
-                    log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
129
-                } else {
130
-                    log.info("停止监听成功!!!");
152
+
153
+                //退出之前判断布防监听状态,并做撤防和停止监听操作
154
+                if (lAlarmHandle >= 0) {
155
+                    if (!hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
156
+                        log.error("撤防失败,错误码: {}", hCNetSDK.NET_DVR_GetLastError());
157
+                    } else {
158
+                        log.info("撤防成功!!!");
159
+                    }
160
+                }
161
+                if (lListenHandle >= 0) {
162
+                    if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
163
+                        log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
164
+                    } else {
165
+                        log.info("停止监听成功!!!");
166
+                    }
131 167
                 }
132
-            }
133 168
 
134
-            //注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄
135
-            if (lUserID >= 0) {
136
-                hCNetSDK.NET_DVR_Logout(lUserID);
137
-            }
169
+                //注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄
170
+                if (lUserID >= 0) {
171
+                    hCNetSDK.NET_DVR_Logout(lUserID);
172
+                }
138 173
 
139
-            //SDK反初始化,释放资源,程序退出时调用
140
-            boolean b = hCNetSDK.NET_DVR_Cleanup();
141
-            if (b)
142
-                log.info("释放资源,程序退出!");
143
-        } catch (InterruptedException e) {
144
-            e.printStackTrace();
145
-        } catch (IOException e) {
174
+                //SDK反初始化,释放资源,程序退出时调用
175
+                boolean b = hCNetSDK.NET_DVR_Cleanup();
176
+                if (b)
177
+                    log.info("释放资源,程序退出!");
178
+            }
179
+        } catch (Exception e) {
146 180
             e.printStackTrace();
147 181
         }
148 182
     }
@@ -174,9 +208,72 @@ public class FaceMain implements ApplicationRunner {
174 208
         return true;
175 209
     }
176 210
 
211
+    private void alarmListenMethod() {
212
+
213
+        if (hCNetSDK == null) {
214
+            if (!CreateSDKInstance()) {
215
+                log.error("Load SDK fail");
216
+                return;
217
+            }
218
+        }
219
+
220
+        //linux系统建议调用以下接口加载组件库
221
+        if (osSelect.isLinux()) {
222
+            System.out.println("linux system come in here");
223
+            HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
224
+            HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
225
+            //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
226
+            String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
227
+            String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
228
+            System.out.println("strPath1:" + strPath1);
229
+
230
+            System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
231
+            ptrByteArray1.write();
232
+            hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
233
+
234
+            System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
235
+            ptrByteArray2.write();
236
+            hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
237
+
238
+            String strPathCom = System.getProperty("user.dir") + "/lib";
239
+            HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
240
+            System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
241
+            struComPath.write();
242
+            hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
243
+        }
244
+        //初始化
245
+        hCNetSDK.NET_DVR_Init();
246
+        Alarm.StartListen();
247
+        try {
248
+            while (true) {
249
+                Thread.sleep(60000);
250
+                log.info("监听进行中,如需退出监听请输入字母Q");
251
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
252
+                String str = bufferedReader.readLine();
253
+                if (str.toUpperCase().equals("Q")) {
254
+                    break;
255
+                }
256
+            }
257
+        } catch (InterruptedException e) {
258
+            e.printStackTrace();
259
+        } catch (IOException ioe) {
260
+            ioe.printStackTrace();
261
+        }
262
+
263
+        //停止监听
264
+        if (lListenHandle >= 0) {
265
+            if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
266
+                log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
267
+            } else {
268
+                log.info("停止监听成功!!!");
269
+            }
270
+        }
271
+        hCNetSDK.NET_DVR_Cleanup();
272
+    }
177 273
     @Override
178 274
     public void run(ApplicationArguments args) throws Exception {
179
-        // after behind for application run,because implements ApplicationRunner
275
+        //after behind for application run,because implements ApplicationRunner
180 276
         this.mainMethod();
277
+        //this.alarmListenMethod();
181 278
     }
182 279
 }

+ 39 - 5
src/main/java/com/unissoft/netSDKDemo/FMSGCallBack_V31.java

@@ -6,6 +6,8 @@ import com.unissoft.pushMsg.AlarmDSService;
6 6
 import com.unissoft.pushMsg.AlarmDSServiceImpl;
7 7
 import lombok.extern.slf4j.Slf4j;
8 8
 
9
+import java.io.File;
10
+import java.io.FileNotFoundException;
9 11
 import java.io.FileOutputStream;
10 12
 import java.io.IOException;
11 13
 import java.nio.ByteBuffer;
@@ -30,20 +32,47 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
30 32
         log.info("报警事件发生,进入回调");
31 33
         /*String hexString = Integer.toHexString(lCommand);
32 34
         log.info("报警类型 hexString {}", hexString);*/
35
+        HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm;
36
+        Pointer ruleAlarmPointer;
33 37
         switch (lCommand) {
34 38
             case HCNetSDK.COMM_ALARM_RULE://行为分析信息上传
39
+
40
+                ruleAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
41
+                ruleAlarm.write();
42
+                ruleAlarmPointer = ruleAlarm.getPointer();
43
+                ruleAlarmPointer.write(0, pAlarmInfo.getByteArray(0, ruleAlarm.size()), 0, ruleAlarm.size());
44
+                ruleAlarm.read();
45
+                //log.info("alarm type in the COMM_ALARM_RULE ---------->: {}", JSON.toJSONString(ruleAlarm));
46
+                System.out.println("行为类型:" + ruleAlarm.struRuleInfo.wEventTypeEx);
47
+                System.out.println("报警通道对应设备的通道号:" + ruleAlarm.struDevInfo.byChannel);
48
+                System.out.println("SDK接入设备的通道号:" + ruleAlarm.struDevInfo.byIvmsChannel);
49
+                System.out.println("报警通道对应设备的IP地址:" + ruleAlarm.struDevInfo.struDevIP.toString());
50
+                System.out.println("报警通道对应设备的端口号:" + ruleAlarm.struDevInfo.wPort);
51
+
52
+                
53
+                alarmDSService.pushLCommandEx(lCommand, ruleAlarm);
35 54
                 log.info(
36
-                        "lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
55
+                        "行为分析事件,lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
37 56
                         lCommand, JSON.toJSONString(pAlarmer), JSON.toJSONString(pAlarmInfo),dwBufLen,JSON.toJSONString(pUser)
38 57
                 );
39
-                HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
58
+                break;
59
+
60
+            case HCNetSDK.COMM_VEHICLE_CONTROL_ALARM://车辆报警上传
61
+                log.info(
62
+                        "车辆报警事件,lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
63
+                        lCommand, JSON.toJSONString(pAlarmer), JSON.toJSONString(pAlarmInfo),dwBufLen,JSON.toJSONString(pUser)
64
+                );
65
+                ruleAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
40 66
                 ruleAlarm.write();
41
-                Pointer ruleAlarmPointer = ruleAlarm.getPointer();
67
+                ruleAlarmPointer = ruleAlarm.getPointer();
42 68
                 ruleAlarmPointer.write(0, pAlarmInfo.getByteArray(0, ruleAlarm.size()), 0, ruleAlarm.size());
43 69
                 ruleAlarm.read();
44
-                log.info("alarm type in the NET_VCA_RULE_ALARM ---------->: {}", JSON.toJSONString(ruleAlarm));
70
+                //log.info("alarm type in the COMM_VEHICLE_CONTROL_ALARM ---------->: {}", JSON.toJSONString(ruleAlarm));
45 71
                 alarmDSService.pushLCommand(lCommand);
46 72
                 break;
73
+            case HCNetSDK.COMM_ALARMHOST_CID_ALARM:
74
+                log.info("报警主机防区报警");
75
+                break;
47 76
             case HCNetSDK.COMM_SNAP_MATCH_ALARM:
48 77
                 //人脸黑名单比对报警
49 78
                 log.info("SNAP_MATCH_ALARM");
@@ -144,6 +173,7 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
144 173
                         buffers.get(bytes);
145 174
                         fout.write(bytes);
146 175
                         fout.close();
176
+
147 177
                     } catch (IOException e) {
148 178
                         // TODO Auto-generated catch block
149 179
                         e.printStackTrace();
@@ -171,7 +201,11 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
171 201
                 break;
172 202
             default:
173 203
                 // TODO 单报警设备 目前不需要 sAlarmType alarmNow
174
-                log.info("alarm type in the FMSGCallBack_V31 ->int: {}", lCommand);
204
+                //log.info("alarm type in the FMSGCallBack_V31 ->int: {}", lCommand);
205
+                log.info(
206
+                        "不分类事件,不返回报警具体数据,lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
207
+                        lCommand, JSON.toJSONString(pAlarmer), JSON.toJSONString(pAlarmInfo),dwBufLen,JSON.toJSONString(pUser)
208
+                );
175 209
                 alarmDSService.pushLCommand(lCommand);
176 210
                 break;
177 211
         }

+ 1 - 0
src/main/java/com/unissoft/netSDKDemo/HCNetSDK.java

@@ -8647,6 +8647,7 @@ public class NET_DVR_PIC_PARAM extends Structure {
8647 8647
         public byte[] byRes = new byte[128];
8648 8648
     }
8649 8649
 
8650
+
8650 8651
     public static class BYTE_ARRAY extends Structure {
8651 8652
         public byte[] byValue;
8652 8653
 

+ 5 - 2
src/main/java/com/unissoft/pushMsg/AddressModel.java

@@ -14,8 +14,11 @@ import org.springframework.stereotype.Component;
14 14
 public class AddressModel {
15 15
 
16 16
     // 推送地址
17
-    @Value("${address.pushToIntrusion}")
18
-    private String pushToIntrusion;
17
+    //@Value("${address.pushToIntrusion}")
18
+    //private String pushToIntrusion;
19
+    @Value("${address.push}")
20
+    private String push;
21
+
19 22
     // 设备ip
20 23
     @Value("${exceptionAlarm.deviceIP}")
21 24
     private String deviceIP;

+ 2 - 0
src/main/java/com/unissoft/pushMsg/AlarmDSService.java

@@ -1,6 +1,7 @@
1 1
 package com.unissoft.pushMsg;
2 2
 
3 3
 import com.sun.jna.Callback;
4
+import com.unissoft.netSDKDemo.HCNetSDK;
4 5
 
5 6
 /**
6 7
  * @author qingsong.han
@@ -11,4 +12,5 @@ public interface AlarmDSService extends Callback {
11 12
 
12 13
     void pushLCommand(Integer lCommand);
13 14
 
15
+    void pushLCommandEx(Integer lCommand, HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm);
14 16
 }

+ 79 - 1
src/main/java/com/unissoft/pushMsg/AlarmDSServiceImpl.java

@@ -1,14 +1,25 @@
1 1
 package com.unissoft.pushMsg;
2 2
 
3
+import com.unissoft.netSDKDemo.HCNetSDK;
3 4
 import com.unissoft.utils.GetBeanUtil;
4 5
 import lombok.extern.slf4j.Slf4j;
6
+import org.apache.commons.codec.binary.Base64;
5 7
 import org.springframework.beans.factory.annotation.Value;
8
+import org.springframework.http.HttpEntity;
9
+import org.springframework.http.MediaType;
10
+import org.springframework.http.ResponseEntity;
6 11
 import org.springframework.stereotype.Service;
7 12
 import org.springframework.util.LinkedMultiValueMap;
8 13
 import org.springframework.util.MultiValueMap;
9 14
 import org.springframework.web.client.RestTemplate;
10 15
 
16
+import java.io.FileNotFoundException;
17
+import java.io.FileOutputStream;
18
+import java.io.IOException;
11 19
 import java.net.URL;
20
+import java.nio.ByteBuffer;
21
+import java.nio.charset.StandardCharsets;
22
+import java.text.SimpleDateFormat;
12 23
 import java.util.Date;
13 24
 
14 25
 /**
@@ -38,7 +49,74 @@ public class AlarmDSServiceImpl implements AlarmDSService {
38 49
         requestEntity.add("orgCode", addressModel.getOrgCode());
39 50
         log.info("报警类型 int: {}", requestEntity);
40 51
         // push of post for object
41
-        Object object = restTemplate.postForObject(addressModel.getPushToIntrusion(), requestEntity, Object.class);
52
+        Object object = restTemplate.postForObject(addressModel.getPush(), requestEntity, Object.class);
42 53
         log.info("AlarmDSServiceImpl push alarm result: {}", object);
43 54
     }
55
+
56
+    @Override
57
+    public void pushLCommandEx(Integer lCommand, HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm) {
58
+        // 获取spring RestTemple bean
59
+        RestTemplate restTemplate = (RestTemplate) GetBeanUtil.getBean("restTemplate");
60
+        // get push class AddressModel bean
61
+        AddressModel addressModel = (AddressModel) GetBeanUtil.getBean("addressModel");
62
+        // MultiValueMap requestEntity
63
+        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
64
+        // 报警类型(异常闯入/入侵) int 4354
65
+        requestEntity.add("sAlarmType", lCommand);
66
+        // 报警时间
67
+        requestEntity.add("alarmNow", new Date());
68
+        // 设备ip
69
+        requestEntity.add("deviceIP", addressModel.getDeviceIP());
70
+        // 机构编码
71
+        requestEntity.add("orgCode", addressModel.getOrgCode());
72
+
73
+        requestEntity.add("cameraIP", ruleAlarm.struDevInfo.struDevIP.toString());
74
+        //将字节写入文件
75
+        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
76
+        String newName = sf.format(new Date());
77
+        FileOutputStream fout;
78
+        String filename = ".//pic//" + newName + "_pSnapPicBuffer" + ".jpg";
79
+        try {
80
+            long offset = 0;
81
+            fout = new FileOutputStream(filename);
82
+            ByteBuffer buffers = ruleAlarm.pImage.getByteBuffer(offset, ruleAlarm.dwPicDataLen);
83
+            byte[] bytes = new byte[ruleAlarm.dwPicDataLen];
84
+            buffers.rewind();
85
+            buffers.get(bytes);
86
+            fout.write(bytes);
87
+            fout.close();
88
+        } catch (FileNotFoundException e) {
89
+            throw new RuntimeException(e);
90
+        } catch (IOException e) {
91
+            throw new RuntimeException(e);
92
+        }
93
+
94
+        long offset = 0;
95
+        ByteBuffer buffers = ruleAlarm.pImage.getByteBuffer(offset, ruleAlarm.dwPicDataLen);
96
+        byte[] bytes = new byte[ruleAlarm.dwPicDataLen];
97
+        buffers.rewind();
98
+        buffers.get(bytes);
99
+        buffers.flip();
100
+        String picStr = StandardCharsets.UTF_8.decode(buffers).toString();
101
+        log.info("pic-string length:"+picStr.length());
102
+        requestEntity.add("pic", picStr);
103
+        requestEntity.add("picSize", ruleAlarm.dwPicDataLen);
104
+        log.info("报警类型: %d", requestEntity.get("sAlarmType") + "超脑IP:"+requestEntity.get("deviceIP")+"\t摄像头IP:"+requestEntity.get("cameraIP"));
105
+        // push of post for object
106
+        //Object object = restTemplate.postForObject(addressModel.getPush(), requestEntity, Object.class);
107
+        //log.info("AlarmDSServiceImpl push alarm result: {}", object);
108
+
109
+        RestTemplate rest = new RestTemplate();
110
+        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
111
+        headers.add("content-type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
112
+        // headers.add("Accept", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
113
+        // 请求体
114
+        MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
115
+        body.add("file", "picture");
116
+        body.add("base64", Base64.encodeBase64String(bytes));
117
+        body.add("key", "123456");
118
+
119
+        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(body, headers);
120
+        ResponseEntity<String> response = rest.postForEntity(addressModel.getPush(), httpEntity, String.class);
121
+    }
44 122
 }

+ 9 - 8
src/main/resources/bootstrap.yml

@@ -1,5 +1,5 @@
1 1
 server:
2
-  port: 8072
2
+  port: 18071
3 3
   tomcat:
4 4
     uri-encoding: UTF-8
5 5
 spring:
@@ -10,7 +10,7 @@ spring:
10 10
     time-zone: GMT+8
11 11
   # dev: 开发环境,test: 测试环境,prod: 生产环境(线上)
12 12
   profiles:
13
-    active: prop
13
+    active: prod
14 14
 ---
15 15
 spring:
16 16
   profiles: dev
@@ -28,22 +28,23 @@ exceptionAlarm:
28 28
 # 只支持post
29 29
 address:
30 30
   # 推送异常闯入/入侵信息地址
31
-  pushToIntrusion: http://localhost:8077/pushIntrusion
31
+  pushToIntrusion1: http://localhost:8077/pushIntrusion
32 32
 ---
33 33
 spring:
34
-  profiles: prop
34
+  profiles: prod
35 35
 # 异常闯入异常,入侵分析
36 36
 # 设备登录
37 37
 exceptionAlarm:
38 38
   # 设备ip地址 DS-2CD7T27DWD-IZS(16384)/DS-7716NX-I4(4354)-->4432
39
-  deviceIP: 192.168.173.162
39
+  deviceIP: 192.168.193.1
40 40
   # orgCode
41
-  org-code: WZZ
41
+  org-code: SJG
42 42
   # 设备用户名
43 43
   userName: admin
44 44
   # 设备密码
45
-  password: JL@123456
45
+  password: Relax123
46 46
 # 只支持post
47 47
 address:
48 48
   # 推送异常闯入/入侵信息地址
49
-  pushToIntrusion: http://23.99.21.201:59882/pushIntrusion
49
+  #push: http://23.99.21.201:59882/pushIntrusion
50
+  push: http://10.105.101.60:8072/pushIntrusion