Selaa lähdekoodia

请求方法修改

hanqingsong 3 vuotta sitten
vanhempi
commit
78df93be7a

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

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

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

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