Kaynağa Gözat

请求方法修改

hanqingsong 3 yıl önce
ebeveyn
işleme
78df93be7a

+ 15 - 3
src/main/java/com/unissoft/intrusion/IntrusionService.java

@@ -6,8 +6,13 @@ import com.unissoft.utils.RedisUtil;
6
 import lombok.Data;
6
 import lombok.Data;
7
 import lombok.extern.slf4j.Slf4j;
7
 import lombok.extern.slf4j.Slf4j;
8
 import org.springframework.beans.factory.annotation.Value;
8
 import org.springframework.beans.factory.annotation.Value;
9
+import org.springframework.http.HttpEntity;
10
+import org.springframework.http.HttpMethod;
9
 import org.springframework.stereotype.Component;
11
 import org.springframework.stereotype.Component;
10
 import org.springframework.stereotype.Service;
12
 import org.springframework.stereotype.Service;
13
+import org.springframework.util.LinkedMultiValueMap;
14
+import org.springframework.util.MultiValueMap;
15
+import org.springframework.web.client.RestTemplate;
11
 
16
 
12
 import javax.annotation.Resource;
17
 import javax.annotation.Resource;
13
 import java.util.Date;
18
 import java.util.Date;
@@ -26,7 +31,7 @@ public interface IntrusionService {
26
         // 报警类型
31
         // 报警类型
27
         private Integer sAlarmType;
32
         private Integer sAlarmType;
28
         // 报警时间
33
         // 报警时间
29
-        private Date alarmNow;
34
+        private String alarmNow;
30
         // 设备ip
35
         // 设备ip
31
         private String deviceIP;
36
         private String deviceIP;
32
         // 机构编码
37
         // 机构编码
@@ -39,8 +44,13 @@ public interface IntrusionService {
39
     class IntrusionServiceImpl implements IntrusionService {
44
     class IntrusionServiceImpl implements IntrusionService {
40
         @Resource
45
         @Resource
41
         private RedisUtil redisUtil;
46
         private RedisUtil redisUtil;
47
+        @Resource
48
+        private RestTemplate restTemplate;
42
         @Value("${spring.redis.ten-minutes}")
49
         @Value("${spring.redis.ten-minutes}")
43
         private long tenMinutes;
50
         private long tenMinutes;
51
+        // 推送地址
52
+        @Value("${address.pushToIntrusion}")
53
+        private String pushToIntrusion;
44
         @Resource
54
         @Resource
45
         private IntrusionModel intrusionModel;
55
         private IntrusionModel intrusionModel;
46
 
56
 
@@ -51,12 +61,14 @@ public interface IntrusionService {
51
                 // key 存在丢弃报警数据,不上报
61
                 // key 存在丢弃报警数据,不上报
52
                 log.info("Don't up!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
62
                 log.info("Don't up!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
53
             } else {
63
             } else {
54
-                // TODO 上报数据-接口
64
+                // 上报数据-接口
55
                 log.info("Up it!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
65
                 log.info("Up it!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
56
                 intrusionModel.setDeviceIP(deviceIP);
66
                 intrusionModel.setDeviceIP(deviceIP);
57
                 intrusionModel.setSAlarmType(sAlarmType);
67
                 intrusionModel.setSAlarmType(sAlarmType);
58
-                intrusionModel.setAlarmNow(DateUtils.stringToData(alarmNow));
68
+                intrusionModel.setAlarmNow(alarmNow);
59
                 intrusionModel.setOrgCode(orgCode);
69
                 intrusionModel.setOrgCode(orgCode);
70
+                HttpEntity<IntrusionModel> httpEntity = new HttpEntity<>(intrusionModel);
71
+                restTemplate.exchange(pushToIntrusion, HttpMethod.POST, httpEntity, Object.class);
60
                 // 设置缓存
72
                 // 设置缓存
61
                 redisUtil.set(deviceIP, JSON.toJSONString(intrusionModel), tenMinutes);
73
                 redisUtil.set(deviceIP, JSON.toJSONString(intrusionModel), tenMinutes);
62
             }
74
             }

+ 8 - 2
src/main/resources/application.yml

@@ -10,7 +10,7 @@ spring:
10
     time-zone: GMT+8
10
     time-zone: GMT+8
11
   # dev: 开发环境,prod: 生产环境(线上)
11
   # dev: 开发环境,prod: 生产环境(线上)
12
   profiles:
12
   profiles:
13
-    active: prod
13
+    active: dev
14
 ---
14
 ---
15
 spring:
15
 spring:
16
   profiles: dev
16
   profiles: dev
@@ -39,6 +39,9 @@ snowFlake:
39
   waitTime: 120
39
   waitTime: 120
40
   # 执行时长最大120秒(上锁后自动释放锁时间)
40
   # 执行时长最大120秒(上锁后自动释放锁时间)
41
   leaseTime: 120
41
   leaseTime: 120
42
+address:
43
+  # 推送异常闯入/入侵信息地址
44
+  pushToIntrusion: http://192.168.40.94:7026/alarm/saveWarning
42
 ---
45
 ---
43
 spring:
46
 spring:
44
   profiles: prod
47
   profiles: prod
@@ -66,4 +69,7 @@ snowFlake:
66
   # 分布式锁等待,最大等待时间120秒
69
   # 分布式锁等待,最大等待时间120秒
67
   waitTime: 120
70
   waitTime: 120
68
   # 执行时长最大120秒(上锁后自动释放锁时间)
71
   # 执行时长最大120秒(上锁后自动释放锁时间)
69
-  leaseTime: 120
72
+  leaseTime: 120
73
+address:
74
+  # 推送异常闯入/入侵信息地址
75
+  pushToIntrusion: http://23.99.21.201:59882/pushIntrusion