AlarmUtils.java
10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package com.sincere.haikangface.utils;
import com.sincere.haikangface.bean.FaceWaterRecoder;
import com.sincere.haikangface.dao.DeviceDao;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 报警事件处理
*/
public class AlarmUtils {
private static AlarmUtils alarmUtils;
private DeviceDao deviceDao;
private AlarmCallBack alarmCallBack;
// public static AlarmUtils getInstance(DeviceDao deviceDao) {
// if (alarmUtils == null) {
// synchronized (AlarmUtils.class) {
// if (null == alarmUtils) alarmUtils = new AlarmUtils(deviceDao);
// }
// }
// return alarmUtils;
// }
public AlarmUtils(DeviceDao deviceDao) {
this.deviceDao = deviceDao;
}
public void setCallBack(AlarmCallBack alarmCallBack) {
this.alarmCallBack = alarmCallBack;
}
public interface AlarmCallBack {
void callBack(String minorType, String deviceID, String cardNo, String time, String picDataUrlId);
}
public void deleAlarm(String strXML) {
if (strXML.contains("FACESNAPREPORT")) {//人脸抓拍机器
} else {//人脸识别
//主类型
String majirType = strXML.substring(strXML.indexOf("MajorType"), strXML.lastIndexOf("MajorType")).trim();
majirType = majirType.replace("MajorType>", "");
majirType = majirType.replace("</", "");
//次类型
String minorType = strXML.substring(strXML.indexOf("MinorType"), strXML.lastIndexOf("MinorType")).trim();
minorType = minorType.replace("MinorType>", "");
minorType = minorType.replace("</", "");
/**
* 2019-9-10 cardNo 变为student_id
*/
String cardNo = "";
if (strXML.contains("CardNo")) {
cardNo = strXML.substring(strXML.indexOf("CardNo"), strXML.lastIndexOf("CardNo")).trim();
cardNo = cardNo.replace("CardNo>", "");
cardNo = cardNo.replace("</", "");
}
String deviceID = strXML.substring(strXML.indexOf("DeviceID"), strXML.lastIndexOf("DeviceID")).trim();
deviceID = deviceID.replace("DeviceID>", "");
deviceID = deviceID.replace("</", "");
String time = strXML.substring(strXML.indexOf("Time"), strXML.lastIndexOf("Time")).trim();
time = time.replace("Time>", "");
time = time.replace("</", "");
String picDataUrl = "";
if (strXML.contains("PicDataUrl")) {
picDataUrl = strXML.substring(strXML.indexOf("PicDataUrl"), strXML.lastIndexOf("PicDataUrl")).trim();
picDataUrl = picDataUrl.replace("PicDataUrl>", "");
picDataUrl = picDataUrl.replace("</", "");
}
//System.out.println("alarmCallBack:"+alarmCallBack);
switch (majirType) {
case "0x1"://报警
baojing(minorType, deviceID, time);
break;
case "0x2"://异常
yichang(minorType, deviceID, time);
break;
case "0x3"://操作
caozuo(minorType, deviceID, time);
break;
case "0x5"://事件
shijian(minorType, deviceID, cardNo, time, picDataUrl);
break;
}
}
}
/**
* 事件次类型
*
* @param minorType
* @param deviceID
* @param cardNo
* @param time
* @param picDataUrl
*/
private void shijian(String minorType, String deviceID, String cardNo, String time, String picDataUrl) {
String content = "";
switch (minorType) {
case "0x01"://合法卡认证通过
content = "合法卡认证通过";
break;
case "0x07"://无效时段
content = "无效时段";
break;
case "0x8"://卡号过期
content = "卡号过期";
break;
case "0x9"://无此卡号
content = "无此卡号";
break;
case "0x4b"://人脸认证通过
if (!StringUtils.isEmpty(picDataUrl)&&picDataUrl.split("id=").length>1) {
String picDataUrlId = picDataUrl.split("id=")[1];
FileUtils.getInstance().writeLogs("0x4bdeviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId, FileUtils.faceSuccess);
content = "人脸认证通过";
if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId);
}
break;
case "0x4c"://人脸认证失败
content = "人脸认证失败";
break;
case "0x50"://人脸不存在
content = "人脸不存在";
break;
case "0x68"://真人检测失败
content = "真人检测失败";
break;
case "0x69"://人证比对通过
if (!StringUtils.isEmpty(picDataUrl)&&picDataUrl.split("id=").length>1) {
String picDataUrlId = picDataUrl.split("id=")[1];
FileUtils.getInstance().writeLogs("0x69deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId, FileUtils.faceSuccess);
content = "人脸认证通过";
if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId);
}
break;
case "0x70"://认证比对失败
FileUtils.getInstance().writeLogs("deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time, FileUtils.faceFail);
break;
}
saveWater(content, minorType, deviceID, cardNo, time, "0x05");
}
/**
* 操作次类型
*
* @param minorType
* @param deviceID
* @param time
*/
private void caozuo(String minorType, String deviceID, String time) {
String content = "";
switch (minorType) {
case "0x70"://远程登录
content = "远程登录";
break;
case "0x71"://远程注销登录
content = "远程注销登录";
break;
case "0x7b"://远程重启
content = "远程重启";
break;
case "0x400"://远程开门
content = "远程开门";
break;
case "0x401"://远程关门
content = "远程关门";
break;
case "0x404"://远程手动校时
content = "远程手动校时";
break;
case "0x406"://远程清空卡号
content = "远程清空卡号";
break;
case "0x40b"://远程抓拍
content = "远程抓拍";
break;
}
saveWater(content, minorType, deviceID, "", time, "0x03");
}
/**
* 异常次类型
*
* @param minorType
* @param deviceID
* @param time
*/
private void yichang(String minorType, String deviceID, String time) {
String content = "";
switch (minorType) {
case "0x3a"://网络断开
content = "网络断开";
break;
case "0x400"://设备上电启动
content = "设备上电启动";
break;
case "0x401"://设备掉电关闭
content = "设备掉电关闭";
break;
case "0x403"://蓄电池电压低
content = "蓄电池电压低";
break;
case "0x404"://蓄电池电压恢复正常
content = "蓄电池电压恢复正常";
break;
case "0x405"://交流电断电
content = "交流电断电";
break;
case "0x406"://交流电恢复
content = "交流电恢复";
break;
case "0x407"://网络恢复
content = "网络恢复";
break;
case "0x421"://摄像头未连接
content = "摄像头未连接";
break;
case "0x422"://摄像头连接恢复
content = "摄像头连接恢复";
break;
case "0x426"://人证设备在线
content = "人证设备在线";
if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "");
break;
case "0x427"://人证设备离线
content = "人证设备离线";
if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "");
break;
}
saveWater(content, minorType, deviceID, "", time, "0x02");
}
/**
* 报警次类型
*
* @param minorType
* @param deviceID
* @param time
*/
private void baojing(String minorType, String deviceID, String time) {
switch (minorType) {
case "0x413"://人脸图像画质低
break;
case "0x40d"://SD卡存储满报警
break;
case "0x40b"://离线事件满90%报警
break;
}
}
/**
* 存储流水记录
*
* @param content
* @param minorType
* @param deviceID
* @param cardNo
* @param time
* @param majorType
*/
private void saveWater(String content, String minorType, String deviceID, String cardNo, String time, String majorType) {
FaceWaterRecoder faceWaterRecoder = new FaceWaterRecoder();
faceWaterRecoder.setContent(content);
faceWaterRecoder.setDeviceId(deviceID);
faceWaterRecoder.setDeviceType(18);
faceWaterRecoder.setMajorType(majorType);
faceWaterRecoder.setMinorType(minorType);
faceWaterRecoder.setTime(time);
faceWaterRecoder.setCardNo(cardNo);
faceWaterRecoder.setSystime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
// System.out.println("deviceDao:" + deviceDao);
// System.out.println("faceWaterRecoder:" + faceWaterRecoder);
deviceDao.saveFaceWaterRecoder(faceWaterRecoder.getDeviceId(), faceWaterRecoder.getDeviceType() + "", faceWaterRecoder.getMinorType(),
faceWaterRecoder.getContent(), faceWaterRecoder.getMajorType(), faceWaterRecoder.getTime(), faceWaterRecoder.getCardNo(), faceWaterRecoder.getSystime());
}
}