|
@@ -1,11 +1,13 @@
|
1
|
1
|
package com.unissoft.intrusion;
|
2
|
2
|
|
|
3
|
+import cn.hutool.core.convert.Convert;
|
3
|
4
|
import com.alibaba.fastjson.JSON;
|
4
|
5
|
import com.unissoft.common.DateUtils;
|
5
|
6
|
import com.unissoft.common.MyConstant;
|
6
|
7
|
import com.unissoft.utils.RedisUtil;
|
7
|
8
|
import lombok.Data;
|
8
|
9
|
import lombok.extern.slf4j.Slf4j;
|
|
10
|
+import org.apache.tomcat.util.codec.binary.Base64;
|
9
|
11
|
import org.springframework.beans.factory.annotation.Value;
|
10
|
12
|
import org.springframework.http.HttpEntity;
|
11
|
13
|
import org.springframework.http.HttpMethod;
|
|
@@ -17,6 +19,12 @@ import org.springframework.util.StringUtils;
|
17
|
19
|
import org.springframework.web.client.RestTemplate;
|
18
|
20
|
|
19
|
21
|
import javax.annotation.Resource;
|
|
22
|
+import java.io.File;
|
|
23
|
+import java.io.FileNotFoundException;
|
|
24
|
+import java.io.FileOutputStream;
|
|
25
|
+import java.io.IOException;
|
|
26
|
+import java.nio.ByteBuffer;
|
|
27
|
+import java.text.SimpleDateFormat;
|
20
|
28
|
import java.util.Date;
|
21
|
29
|
import java.util.HashMap;
|
22
|
30
|
import java.util.Map;
|
|
@@ -27,10 +35,13 @@ import java.util.Map;
|
27
|
35
|
* @create 2022-11-07 10:21
|
28
|
36
|
*/
|
29
|
37
|
public interface IntrusionService {
|
30
|
|
- void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode);
|
|
38
|
+
|
|
39
|
+ void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode,
|
|
40
|
+ String cameraIP, String picByte, Integer size);
|
31
|
41
|
|
32
|
42
|
void editChannelCode(Map<String, String> channelCodes);
|
33
|
43
|
|
|
44
|
+
|
34
|
45
|
@Data
|
35
|
46
|
@Component
|
36
|
47
|
class IntrusionModel {
|
|
@@ -38,12 +49,18 @@ public interface IntrusionService {
|
38
|
49
|
private Integer alarmType;
|
39
|
50
|
// 报警时间
|
40
|
51
|
private String alarmNow;
|
41
|
|
- // 设备ip
|
|
52
|
+ // 超脑设备ip
|
42
|
53
|
private String deviceIP;
|
43
|
54
|
// 机构编码
|
44
|
55
|
private String orgCode;
|
45
|
56
|
// ICC通道号
|
46
|
57
|
private String channelCode;
|
|
58
|
+ //图片base64格式字节
|
|
59
|
+ private String picByte;
|
|
60
|
+ //图片大小
|
|
61
|
+ private Integer picSize;
|
|
62
|
+ //报警摄像头IP
|
|
63
|
+ private String cameraIP;
|
47
|
64
|
}
|
48
|
65
|
|
49
|
66
|
// 定义内部类
|
|
@@ -63,30 +80,54 @@ public interface IntrusionService {
|
63
|
80
|
private IntrusionModel intrusionModel;
|
64
|
81
|
|
65
|
82
|
@Override
|
66
|
|
- public void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode) {
|
67
|
|
- /*// redis key
|
68
|
|
- if (redisUtil.hasKey(deviceIP)) {
|
69
|
|
- // key 存在丢弃报警数据,不上报
|
70
|
|
- log.info("Don't up!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
|
71
|
|
- } else {
|
72
|
|
- // 上报数据-接口
|
73
|
|
- log.info("Up it!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
|
74
|
|
- intrusionModel.setDeviceIP(deviceIP);
|
75
|
|
- intrusionModel.setSAlarmType(sAlarmType);
|
76
|
|
- intrusionModel.setAlarmNow(alarmNow);
|
77
|
|
- intrusionModel.setOrgCode(orgCode);
|
78
|
|
- HttpEntity<IntrusionModel> httpEntity = new HttpEntity<>(intrusionModel);
|
79
|
|
- restTemplate.exchange(pushToIntrusion, HttpMethod.POST, httpEntity, Object.class);
|
80
|
|
- // 设置缓存
|
81
|
|
- redisUtil.set(deviceIP, JSON.toJSONString(intrusionModel), tenMinutes);
|
82
|
|
- }*/
|
|
83
|
+ public void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode,
|
|
84
|
+ String cameraIP, String picByte, Integer size) {
|
|
85
|
+
|
83
|
86
|
// TODO 物联网到业务平台推送数据网络不通,修改为业务平台主动获取数据
|
84
|
87
|
// 上报数据-接口
|
|
88
|
+ //
|
|
89
|
+ log.info("接收到报警数据,类型:" + sAlarmType + "\t时间:" + alarmNow + "\t超脑IP:" + deviceIP);
|
|
90
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
91
|
+ String newName = sf.format(new Date());
|
|
92
|
+ String filename = "";
|
|
93
|
+ FileOutputStream fout;
|
|
94
|
+ byte[] bytes = Base64.decodeBase64(picByte);
|
|
95
|
+ log.info("pic size:{}", bytes.length);
|
|
96
|
+ try {
|
|
97
|
+ File file = new File( "." + File.separator + "mypic" + File.separator);
|
|
98
|
+ if(!file.exists())
|
|
99
|
+ file.mkdir();
|
|
100
|
+ filename = "." + File.separator + "mypic" + File.separator + newName + "VCA_TRAVERSE_PLANE" + ".jpg";
|
|
101
|
+ file = new File(filename);
|
|
102
|
+ file.createNewFile();
|
|
103
|
+ fout = new FileOutputStream(file);
|
|
104
|
+ //将字节写入文件
|
|
105
|
+ fout.write(bytes);
|
|
106
|
+ fout.close();
|
|
107
|
+ System.out.println("pic save ok");
|
|
108
|
+ } catch (FileNotFoundException e) {
|
|
109
|
+ // TODO Auto-generated catch block
|
|
110
|
+ e.printStackTrace();
|
|
111
|
+ } catch (IOException e) {
|
|
112
|
+ // TODO Auto-generated catch block
|
|
113
|
+ e.printStackTrace();
|
|
114
|
+ }finally {
|
|
115
|
+ try {
|
|
116
|
+ if (fout != null)
|
|
117
|
+ fout.close();
|
|
118
|
+ }catch (IOException ioe){
|
|
119
|
+ ioe.printStackTrace();
|
|
120
|
+ }
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+
|
85
|
124
|
|
86
|
125
|
intrusionModel.setDeviceIP(deviceIP);
|
87
|
126
|
intrusionModel.setAlarmType(sAlarmType);
|
88
|
127
|
intrusionModel.setAlarmNow(alarmNow);
|
89
|
128
|
intrusionModel.setOrgCode(orgCode);
|
|
129
|
+ //intrusionModel.setPicByte(picByte);
|
|
130
|
+ intrusionModel.setCameraIP(cameraIP);
|
90
|
131
|
// 添加通道号
|
91
|
132
|
intrusionModel.setChannelCode(this.getChannelCode(deviceIP));
|
92
|
133
|
// 设置异常闯入设备数据-hashCode
|
|
@@ -95,14 +136,26 @@ public interface IntrusionService {
|
95
|
136
|
}
|
96
|
137
|
|
97
|
138
|
private String getChannelCode(String deviceIP) {
|
98
|
|
- String channelCode = redisUtil.hget(MyConstant.ICC_CHANNEL_CODE, deviceIP).toString();
|
99
|
|
- if (StringUtils.isEmpty(channelCode))
|
100
|
|
- channelCode = this.staticChannelCode(deviceIP);
|
101
|
|
- return channelCode;
|
|
139
|
+
|
|
140
|
+ Object oIP = redisUtil.hget(MyConstant.ICC_CHANNEL_CODE, deviceIP);
|
|
141
|
+
|
|
142
|
+ if (oIP != null) {
|
|
143
|
+
|
|
144
|
+ String channelCode = redisUtil.hget(MyConstant.ICC_CHANNEL_CODE, deviceIP).toString();
|
|
145
|
+ if (StringUtils.isEmpty(channelCode))
|
|
146
|
+ channelCode = this.staticChannelCode(deviceIP);
|
|
147
|
+ return channelCode;
|
|
148
|
+ }else {
|
|
149
|
+ log.info("VALUE OF MyConstant.ICC_CHANNEL_CODE IS NULL");
|
|
150
|
+ return null;
|
|
151
|
+ }
|
102
|
152
|
}
|
103
|
153
|
|
104
|
154
|
private String staticChannelCode(String deviceIP) {
|
|
155
|
+ log.info("IntrusionServiceImpl.staticChannelCode");
|
105
|
156
|
switch (deviceIP) {
|
|
157
|
+ case "192.168.193.1":
|
|
158
|
+ return "1000384$1$0$1";
|
106
|
159
|
case "192.168.193.16":
|
107
|
160
|
return "1000384$1$0$10";
|
108
|
161
|
case "192.168.193.17":
|