Explorar el Código

修改视频监控问题

zhangchun hace 1 mes
padre
commit
476237e1a0

+ 6 - 0
src/main/java/com/unissoft/SmartGrpNofDevicesApplication.java

@@ -1,10 +1,16 @@
1 1
 package com.unissoft;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.unissoft.pushMsg.AddressModel;
3 5
 import org.springframework.boot.SpringApplication;
4 6
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 7
 import org.springframework.context.annotation.Bean;
6 8
 import org.springframework.web.client.RestTemplate;
7 9
 
10
+import java.io.IOException;
11
+import java.nio.file.Files;
12
+import java.nio.file.Paths;
13
+
8 14
 @SpringBootApplication
9 15
 public class SmartGrpNofDevicesApplication {
10 16
 

+ 4 - 2
src/main/java/com/unissoft/common/CommonMethod.java

@@ -33,8 +33,10 @@ public class CommonMethod {
33 33
             e.printStackTrace();
34 34
             throw e;
35 35
         } finally {
36
-            bos.close();
37
-            in.close();
36
+            if(bos != null)
37
+                bos.close();
38
+            if(in != null)
39
+                in.close();
38 40
         }
39 41
     }
40 42
 

+ 35 - 30
src/main/java/com/unissoft/face/FaceMain.java

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
14 14
 
15 15
 import javax.annotation.Resource;
16 16
 import java.io.BufferedReader;
17
+import java.io.File;
17 18
 import java.io.IOException;
18 19
 import java.io.InputStreamReader;
19 20
 import java.time.LocalDate;
@@ -77,7 +78,7 @@ public class FaceMain implements ApplicationRunner {
77 78
             hCNetSDK.NET_DVR_Init();
78 79
 
79 80
             //加载日志
80
-            hCNetSDK.NET_DVR_SetLogToFile(3, "..//sdklog", false);
81
+            hCNetSDK.NET_DVR_SetLogToFile(3, ".." + File.separator + "sdklog", false);
81 82
 
82 83
             //登录设备,每一台设备分别登录; 登录句柄是唯一的,可以区分设备
83 84
             HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
@@ -130,52 +131,56 @@ public class FaceMain implements ApplicationRunner {
130 131
             Calendar c1 = Calendar.getInstance();
131 132
             c1.setTime(satart);
132 133
             while (true) {
134
+                /*
133 135
                 //这里加入控制台输入控制,是为了保持连接状态,当输入Y表示布防结束
134 136
                 log.info("监听进行中,输入字母Q可退出监听");
135 137
                 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
136 138
                 String str = bufferedReader.readLine();
137 139
                 if (str.toUpperCase().equals("Q")) {
138 140
                     break;
139
-                 /*
141
+                 */
140 142
                 Thread.sleep(60000);
141 143
                 Date end = new Date();
142 144
                 Calendar c2 = Calendar.getInstance();
143 145
                 c2.setTime(end);
144 146
                 long millis = c2.getTimeInMillis() - c1.getTimeInMillis();
145
-                long hours = millis/(1000*60*60);
146
-                if(hours > 10) {
147
+                long hours = millis / (1000 * 60 * 60);
148
+                /*if (hours > 10) {
147 149
                     log.info("时间过去10小时,退出程序");
148 150
                     break;
149 151
                 }
150
-                }*/
151
-                }
152
+                */
153
+            }
152 154
 
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
-                    }
155
+            /*
156
+            //退出之前判断布防监听状态,并做撤防和停止监听操作
157
+            if (lAlarmHandle >= 0) {
158
+                if (!hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
159
+                    log.error("撤防失败,错误码: {}", hCNetSDK.NET_DVR_GetLastError());
160
+                } else {
161
+                    log.info("撤防成功!!!");
167 162
                 }
168
-
169
-                //注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄
170
-                if (lUserID >= 0) {
171
-                    hCNetSDK.NET_DVR_Logout(lUserID);
163
+            }
164
+            if (lListenHandle >= 0) {
165
+                if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
166
+                    log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
167
+                } else {
168
+                    log.info("停止监听成功!!!");
172 169
                 }
170
+            }
173 171
 
174
-                //SDK反初始化,释放资源,程序退出时调用
175
-                boolean b = hCNetSDK.NET_DVR_Cleanup();
176
-                if (b)
177
-                    log.info("释放资源,程序退出!");
172
+            //注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄
173
+            if (lUserID >= 0) {
174
+                hCNetSDK.NET_DVR_Logout(lUserID);
178 175
             }
176
+
177
+            //SDK反初始化,释放资源,程序退出时调用
178
+            boolean b = hCNetSDK.NET_DVR_Cleanup();
179
+            if (b)
180
+                log.info("释放资源,程序退出!");
181
+
182
+             */
183
+
179 184
         } catch (Exception e) {
180 185
             e.printStackTrace();
181 186
         }
@@ -247,17 +252,17 @@ public class FaceMain implements ApplicationRunner {
247 252
         try {
248 253
             while (true) {
249 254
                 Thread.sleep(60000);
255
+                /*
250 256
                 log.info("监听进行中,如需退出监听请输入字母Q");
251 257
                 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
252 258
                 String str = bufferedReader.readLine();
253 259
                 if (str.toUpperCase().equals("Q")) {
254 260
                     break;
255 261
                 }
262
+                */
256 263
             }
257 264
         } catch (InterruptedException e) {
258 265
             e.printStackTrace();
259
-        } catch (IOException ioe) {
260
-            ioe.printStackTrace();
261 266
         }
262 267
 
263 268
         //停止监听

+ 3 - 2
src/main/java/com/unissoft/face/FacePicManage.java

@@ -9,6 +9,7 @@ import org.dom4j.DocumentException;
9 9
 import org.dom4j.DocumentHelper;
10 10
 import org.dom4j.Element;
11 11
 
12
+import java.io.File;
12 13
 import java.io.IOException;
13 14
 import java.io.UnsupportedEncodingException;
14 15
 import java.util.Iterator;
@@ -50,7 +51,7 @@ public class FacePicManage {
50 51
         struSendParam.read();
51 52
         
52 53
         //本地jpg图片转成二进制byte数组
53
-        byte[] picbyte = CommonMethod.toByteArray(".\\pic\\test1.jpg");
54
+        byte[] picbyte = CommonMethod.toByteArray("." + File.separator + "pic" + File.separator + "test1.jpg");
54 55
         HCNetSDK.BYTE_ARRAY arraybyte = new HCNetSDK.BYTE_ARRAY(picbyte.length);
55 56
         arraybyte.read();
56 57
         arraybyte.byValue = picbyte;
@@ -127,7 +128,7 @@ public class FacePicManage {
127 128
         stringRequest.write();
128 129
         
129 130
         //读取二进制文件
130
-        byte[] picbyte = CommonMethod.toByteArray(".\\pic\\FDLib.jpg");
131
+        byte[] picbyte = CommonMethod.toByteArray("." + File.separator + "pic" + File.separator + "FDLib.jpg");
131 132
         HCNetSDK.BYTE_ARRAY byte_array = new HCNetSDK.BYTE_ARRAY(picbyte.length);
132 133
         byte_array.read();
133 134
         byte_array.byValue = picbyte;

+ 0 - 1
src/main/java/com/unissoft/mqtt/MqttTestSendController.java

@@ -30,5 +30,4 @@ public class MqttTestSendController {
30 30
         restTemplate.postForObject("http://localhost:8072/pushIntrusion", requestEntity, Object.class);
31 31
         return "200";
32 32
     }
33
-
34 33
 }

+ 38 - 17
src/main/java/com/unissoft/netSDKDemo/FMSGCallBack_V31.java

@@ -29,7 +29,7 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
29 29
     }
30 30
 
31 31
     public void AlarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
32
-        log.info("报警事件发生,进入回调");
32
+        //log.info("报警事件发生,进入回调");
33 33
         /*String hexString = Integer.toHexString(lCommand);
34 34
         log.info("报警类型 hexString {}", hexString);*/
35 35
         HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm;
@@ -46,11 +46,10 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
46 46
                 System.out.println("行为类型:" + ruleAlarm.struRuleInfo.wEventTypeEx);
47 47
                 System.out.println("报警通道对应设备的通道号:" + ruleAlarm.struDevInfo.byChannel);
48 48
                 System.out.println("SDK接入设备的通道号:" + ruleAlarm.struDevInfo.byIvmsChannel);
49
-                System.out.println("报警通道对应设备的IP地址:" + ruleAlarm.struDevInfo.struDevIP.toString());
49
+                System.out.println("报警通道对应设备的IP地址:" +  new String(ruleAlarm.struDevInfo.struDevIP.sIpV4));
50 50
                 System.out.println("报警通道对应设备的端口号:" + ruleAlarm.struDevInfo.wPort);
51 51
 
52
-                
53
-                alarmDSService.pushLCommandEx(lCommand, ruleAlarm);
52
+                alarmDSService.pushLCommand(lCommand, ruleAlarm);
54 53
                 log.info(
55 54
                         "行为分析事件,lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
56 55
                         lCommand, JSON.toJSONString(pAlarmer), JSON.toJSONString(pAlarmInfo),dwBufLen,JSON.toJSONString(pUser)
@@ -68,7 +67,7 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
68 67
                 ruleAlarmPointer.write(0, pAlarmInfo.getByteArray(0, ruleAlarm.size()), 0, ruleAlarm.size());
69 68
                 ruleAlarm.read();
70 69
                 //log.info("alarm type in the COMM_VEHICLE_CONTROL_ALARM ---------->: {}", JSON.toJSONString(ruleAlarm));
71
-                alarmDSService.pushLCommand(lCommand);
70
+                alarmDSService.pushLCommand(lCommand, ruleAlarm);
72 71
                 break;
73 72
             case HCNetSDK.COMM_ALARMHOST_CID_ALARM:
74 73
                 log.info("报警主机防区报警");
@@ -103,9 +102,9 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
103 102
                 if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
104 103
                     SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
105 104
                     String newName = sf.format(new Date());
106
-                    FileOutputStream fout;
105
+                    FileOutputStream fout = null;
107 106
                     try {
108
-                        String filename = ".//pic//" + newName + "_pSnapPicBuffer" + ".jpg";
107
+                        String filename = "." + File.separator + "pic" + File.separator + newName + "_pSnapPicBuffer" + ".jpg";
109 108
                         fout = new FileOutputStream(filename);
110 109
                         //将字节写入文件
111 110
                         long offset = 0;
@@ -114,11 +113,18 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
114 113
                         buffers.rewind();
115 114
                         buffers.get(bytes);
116 115
                         fout.write(bytes);
117
-                        fout.close();
118 116
                     } catch (IOException e) {
119 117
                         // TODO Auto-generated catch block
120 118
                         e.printStackTrace();
119
+                    }finally {
120
+                        try {
121
+                            if (fout != null)
122
+                                fout.close();
123
+                        }catch(IOException ioe){
124
+                            ioe.printStackTrace();
125
+                        }
121 126
                     }
127
+
122 128
                 }
123 129
                 //保存抓拍人脸图URL,图片数据传输方式: 1- URL 注:超脑设备人脸比对报警图片一般按照URL上传,根据URL去下载设备中存储的图片,认证方式选择:摘要认证
124 130
                 if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
@@ -132,9 +138,9 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
132 138
                 if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
133 139
                     SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
134 140
                     String newName = sf.format(new Date());
135
-                    FileOutputStream fout;
141
+                    FileOutputStream fout = null;
136 142
                     try {
137
-                        String filename = ".//pic//" + newName + "_struSnapInfo_pBuffer1" + ".jpg";
143
+                        String filename = "." + File.separator + "pic" + File.separator + newName + "_struSnapInfo_pBuffer1" + ".jpg";
138 144
                         fout = new FileOutputStream(filename);
139 145
                         //将字节写入文件
140 146
                         long offset = 0;
@@ -143,10 +149,16 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
143 149
                         buffers.rewind();
144 150
                         buffers.get(bytes);
145 151
                         fout.write(bytes);
146
-                        fout.close();
147 152
                     } catch (IOException e) {
148 153
                         // TODO Auto-generated catch block
149 154
                         e.printStackTrace();
155
+                    }finally {
156
+                        try {
157
+                            if (fout != null)
158
+                                fout.close();
159
+                        }catch(IOException ioe){
160
+                            ioe.printStackTrace();
161
+                        }
150 162
                     }
151 163
                 }
152 164
                 if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
@@ -161,9 +173,9 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
161 173
                 if ((strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
162 174
                     SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
163 175
                     String newName = sf.format(new Date());
164
-                    FileOutputStream fout;
176
+                    FileOutputStream  fout = null;
165 177
                     try {
166
-                        String filename = ".//pic//" + newName + "_fSimilarity_" + strFaceSnapMatch.fSimilarity + "_struBlackListInfo_pBuffer1" + ".jpg";
178
+                        String filename = "." + File.separator + "pic" + File.separator  + newName + "_fSimilarity_" + strFaceSnapMatch.fSimilarity + "_struBlackListInfo_pBuffer1" + ".jpg";
167 179
                         fout = new FileOutputStream(filename);
168 180
                         //将字节写入文件
169 181
                         long offset = 0;
@@ -172,11 +184,16 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
172 184
                         buffers.rewind();
173 185
                         buffers.get(bytes);
174 186
                         fout.write(bytes);
175
-                        fout.close();
176
-
177 187
                     } catch (IOException e) {
178 188
                         // TODO Auto-generated catch block
179 189
                         e.printStackTrace();
190
+                    }finally {
191
+                        try {
192
+                            if (fout != null)
193
+                                fout.close();
194
+                        }catch(IOException ioe){
195
+                            ioe.printStackTrace();
196
+                        }
180 197
                     }
181 198
                 }
182 199
                 //保存人脸库图片,图片数据传输方式: 1-URL
@@ -197,16 +214,20 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
197 214
                     buffers.get(bytes);
198 215
                     log.info("抓拍库附加信息: {}", new String(bytes));
199 216
                 }
200
-                alarmDSService.pushLCommand(lCommand);
217
+                //TODO 参数完善
218
+                alarmDSService.pushLCommand(lCommand, null);
201 219
                 break;
202 220
             default:
203 221
                 // TODO 单报警设备 目前不需要 sAlarmType alarmNow
204 222
                 //log.info("alarm type in the FMSGCallBack_V31 ->int: {}", lCommand);
223
+                /*
205 224
                 log.info(
206 225
                         "不分类事件,不返回报警具体数据,lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
207 226
                         lCommand, JSON.toJSONString(pAlarmer), JSON.toJSONString(pAlarmInfo),dwBufLen,JSON.toJSONString(pUser)
208 227
                 );
209
-                alarmDSService.pushLCommand(lCommand);
228
+                */
229
+                //TODO 参数完善
230
+                alarmDSService.pushLCommand(lCommand, null);
210 231
                 break;
211 232
         }
212 233
     }

+ 51 - 7
src/main/java/com/unissoft/pushMsg/AddressModel.java

@@ -1,35 +1,79 @@
1 1
 package com.unissoft.pushMsg;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
3 4
 import lombok.Data;
4 5
 import org.springframework.beans.factory.annotation.Value;
5 6
 import org.springframework.stereotype.Component;
6 7
 
8
+import java.io.IOException;
9
+import java.nio.file.Files;
10
+import java.nio.file.Paths;
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+
7 14
 /**
8 15
  * @author qingsong.han
9 16
  * @description:
10 17
  * @create 2022-10-14 16:50
11 18
  */
12
-@Data
19
+//@Data
13 20
 @Component
14 21
 public class AddressModel {
15 22
 
23
+    public AddressModel(){
24
+        String fileName = "./config.txt";
25
+        List<String> content = new ArrayList<>();
26
+        try {
27
+            content = Files.readAllLines(Paths.get(fileName));
28
+           if(content.size() > 0) {
29
+               JSONObject json = JSONObject.parseObject(content.get(0));
30
+               deviceIP = json.getString("deviceIP");
31
+               orgCode = json.getString("orgCode");
32
+               userName = json.getString("userName");
33
+               password = json.getString("password");
34
+               push = json.getString("push");
35
+           }
36
+        } catch (IOException e) {
37
+            throw new RuntimeException(e);
38
+        }
39
+    }
40
+
41
+    public String getPush() {
42
+        return push;
43
+    }
44
+
45
+    public String getDeviceIP() {
46
+        return deviceIP;
47
+    }
48
+
49
+    public String getOrgCode() {
50
+        return orgCode;
51
+    }
52
+
53
+    public String getUserName() {
54
+        return userName;
55
+    }
56
+
57
+    public String getPassword() {
58
+        return password;
59
+    }
60
+
16 61
     // 推送地址
17 62
     //@Value("${address.pushToIntrusion}")
18 63
     //private String pushToIntrusion;
19
-    @Value("${address.push}")
64
+    //@Value("${address.push}")
20 65
     private String push;
21
-
22 66
     // 设备ip
23
-    @Value("${exceptionAlarm.deviceIP}")
67
+    //@Value("${exceptionAlarm.deviceIP}")
24 68
     private String deviceIP;
25 69
     // 设备ip
26
-    @Value("${exceptionAlarm.org-code}")
70
+    //@Value("${exceptionAlarm.org-code}")
27 71
     private String orgCode;
28 72
     // 设备登录用户名
29
-    @Value("${exceptionAlarm.userName}")
73
+    //@Value("${exceptionAlarm.userName}")
30 74
     private String userName;
31 75
     // 设备登录密码
32
-    @Value("${exceptionAlarm.password}")
76
+    //@Value("${exceptionAlarm.password}")
33 77
     private String password;
34 78
 
35 79
 }

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

@@ -10,7 +10,7 @@ import com.unissoft.netSDKDemo.HCNetSDK;
10 10
  */
11 11
 public interface AlarmDSService extends Callback {
12 12
 
13
-    void pushLCommand(Integer lCommand);
13
+    //void pushLCommand(Integer lCommand);
14 14
 
15
-    void pushLCommandEx(Integer lCommand, HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm);
15
+    void pushLCommand(Integer lCommand, HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm);
16 16
 }

+ 46 - 51
src/main/java/com/unissoft/pushMsg/AlarmDSServiceImpl.java

@@ -31,7 +31,7 @@ import java.util.Date;
31 31
 @Service
32 32
 public class AlarmDSServiceImpl implements AlarmDSService {
33 33
 
34
-    @Override
34
+/*    @Override
35 35
     public void pushLCommand(Integer lCommand) {
36 36
         // 获取spring RestTemple bean
37 37
         RestTemplate restTemplate = (RestTemplate) GetBeanUtil.getBean("restTemplate");
@@ -52,69 +52,64 @@ public class AlarmDSServiceImpl implements AlarmDSService {
52 52
         Object object = restTemplate.postForObject(addressModel.getPush(), requestEntity, Object.class);
53 53
         log.info("AlarmDSServiceImpl push alarm result: {}", object);
54 54
     }
55
-
55
+*/
56 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");
57
+    public void pushLCommand(Integer lCommand, HCNetSDK.NET_VCA_RULE_ALARM ruleAlarm) {
58
+        RestTemplate rest = new RestTemplate();
59
+        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
60
+        headers.add("content-type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
61
+        // headers.add("Accept", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
62
+        // 请求体
63
+        MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
60 64
         // get push class AddressModel bean
61 65
         AddressModel addressModel = (AddressModel) GetBeanUtil.getBean("addressModel");
62
-        // MultiValueMap requestEntity
63
-        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
64 66
         // 报警类型(异常闯入/入侵) int 4354
65
-        requestEntity.add("sAlarmType", lCommand);
67
+        body.add("sAlarmType", String.valueOf(lCommand));
66 68
         // 报警时间
67
-        requestEntity.add("alarmNow", new Date());
69
+        body.add("alarmNow",
70
+                (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
71
+                        .format(new Date()));
68 72
         // 设备ip
69
-        requestEntity.add("deviceIP", addressModel.getDeviceIP());
73
+        body.add("deviceIP", addressModel.getDeviceIP());
70 74
         // 机构编码
71
-        requestEntity.add("orgCode", addressModel.getOrgCode());
75
+        body.add("orgCode", addressModel.getOrgCode());
76
+        byte[] bytes = null;
77
+        if(ruleAlarm != null) {
78
+            body.add("cameraIP", ruleAlarm.struDevInfo.struDevIP.sIpV4.toString());
79
+            //将字节写入文件
80
+            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
81
+            String newName = sf.format(new Date());
82
+            //FileOutputStream fout;
83
+            String filename = ".//pic//" + newName + "_pSnapPicBuffer" + ".jpg";
84
+            /*try {
85
+                long offset = 0;
86
+                fout = new FileOutputStream(filename);
87
+                ByteBuffer buffers = ruleAlarm.pImage.getByteBuffer(offset, ruleAlarm.dwPicDataLen);
88
+                bytes = new byte[ruleAlarm.dwPicDataLen];
89
+                buffers.rewind();
90
+                buffers.get(bytes);
91
+                fout.write(bytes);
92
+                fout.close();
93
+            } catch (FileNotFoundException e) {
94
+                throw new RuntimeException(e);
95
+            } catch (IOException e) {
96
+                throw new RuntimeException(e);
97
+            }*/
72 98
 
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 99
             long offset = 0;
81
-            fout = new FileOutputStream(filename);
82 100
             ByteBuffer buffers = ruleAlarm.pImage.getByteBuffer(offset, ruleAlarm.dwPicDataLen);
83
-            byte[] bytes = new byte[ruleAlarm.dwPicDataLen];
101
+            bytes = new byte[ruleAlarm.dwPicDataLen];
84 102
             buffers.rewind();
85 103
             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
-        }
104
+            buffers.flip();
105
+            body.add("picByte", Base64.encodeBase64String(bytes));
106
+            body.add("picSize", String.valueOf(ruleAlarm.dwPicDataLen));
107
+            log.info("准备上传数据,报警类型: {}\t超脑IP:{}\t摄像头IP:{}",
108
+                    body.get("sAlarmType"), body.get("deviceIP"), body.get("cameraIP"));
93 109
 
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");
110
+        }else{
111
+            //log.info("报警类型: {}\t超脑IP:{}", body.get("sAlarmType"), body.get("deviceIP"));
112
+        }
118 113
 
119 114
         HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(body, headers);
120 115
         ResponseEntity<String> response = rest.postForEntity(addressModel.getPush(), httpEntity, String.class);

+ 2 - 2
src/main/resources/bootstrap.yml

@@ -46,5 +46,5 @@ exceptionAlarm:
46 46
 # 只支持post
47 47
 address:
48 48
   # 推送异常闯入/入侵信息地址
49
-  #push: http://23.99.21.201:59882/pushIntrusion
50
-  push: http://10.105.101.60:8072/pushIntrusion
49
+  push: http://23.99.21.201:59882/pushIntrusion
50
+  #push: http://10.105.101.60:8072/pushIntrusion

+ 6 - 0
src/test/java/com/unissoft/SmartGrpNofDevicesApplicationTests.java

@@ -1,8 +1,14 @@
1 1
 package com.unissoft;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
3 4
 import org.junit.jupiter.api.Test;
4 5
 import org.springframework.boot.test.context.SpringBootTest;
5 6
 
7
+import java.io.IOException;
8
+import java.nio.file.Files;
9
+import java.nio.file.OpenOption;
10
+import java.nio.file.Paths;
11
+
6 12
 @SpringBootTest
7 13
 class SmartGrpNofDevicesApplicationTests {
8 14