Преглед изворни кода

异常闯入修改为被动数据

hanqingsong пре 3 година
родитељ
комит
76d49aa456

+ 26 - 0
src/main/java/com/unissoft/intrusion/GetIntrusionController.java

@@ -0,0 +1,26 @@
1
+package com.unissoft.intrusion;
2
+
3
+import lombok.extern.slf4j.Slf4j;
4
+import org.springframework.web.bind.annotation.GetMapping;
5
+import org.springframework.web.bind.annotation.RestController;
6
+
7
+import javax.annotation.Resource;
8
+
9
+/**
10
+ * @author qingsong.han
11
+ * @description: 第三方平台获取异常闯入数据
12
+ * @create 2022-11-14 17:30
13
+ */
14
+@Slf4j
15
+@RestController
16
+public class GetIntrusionController {
17
+
18
+    @Resource
19
+    private GetIntrusionService getIntrusionService;
20
+
21
+    @GetMapping("/pullIntrusion")
22
+    public Object pullIntrusion() {
23
+        return getIntrusionService.pullIntrusion();
24
+    }
25
+
26
+}

+ 47 - 0
src/main/java/com/unissoft/intrusion/GetIntrusionService.java

@@ -0,0 +1,47 @@
1
+package com.unissoft.intrusion;
2
+
3
+import com.unissoft.common.MyConstant;
4
+import com.unissoft.utils.RedisUtil;
5
+import lombok.extern.slf4j.Slf4j;
6
+import org.redisson.transaction.HashKey;
7
+import org.springframework.stereotype.Service;
8
+import org.springframework.util.CollectionUtils;
9
+
10
+import javax.annotation.Resource;
11
+import java.util.Collection;
12
+import java.util.Collections;
13
+import java.util.List;
14
+import java.util.Map;
15
+import java.util.stream.Collectors;
16
+
17
+/**
18
+ * @author qingsong.han
19
+ * @description:
20
+ * @create 2022-11-14 17:32
21
+ */
22
+public interface GetIntrusionService {
23
+
24
+    Object pullIntrusion();
25
+    // 定义内部类
26
+    @Slf4j
27
+    @Service
28
+    class IntrusionServiceImpl implements GetIntrusionService {
29
+        @Resource
30
+        private RedisUtil redisUtil;
31
+
32
+        @Override
33
+        public Object pullIntrusion() {
34
+            if (redisUtil.hasKey(MyConstant.INTRUSION_ALARM_IP)) {
35
+                Map<String, Object> hmget = redisUtil.hmget(MyConstant.INTRUSION_ALARM_IP);
36
+                // 转list
37
+                if (!CollectionUtils.isEmpty(hmget)) {
38
+                    Collection<Object> values = hmget.values();
39
+                    log.info("GetIntrusionService: {}", values);
40
+                    return values;
41
+                }
42
+            }
43
+            return Collections.emptyList();
44
+        }
45
+    }
46
+
47
+}

+ 19 - 8
src/main/java/com/unissoft/intrusion/IntrusionService.java

@@ -2,6 +2,7 @@ package com.unissoft.intrusion;
2 2
 
3 3
 import com.alibaba.fastjson.JSON;
4 4
 import com.unissoft.common.DateUtils;
5
+import com.unissoft.common.MyConstant;
5 6
 import com.unissoft.utils.RedisUtil;
6 7
 import lombok.Data;
7 8
 import lombok.extern.slf4j.Slf4j;
@@ -29,7 +30,7 @@ public interface IntrusionService {
29 30
     @Component
30 31
     class IntrusionModel {
31 32
         // 报警类型
32
-        private Integer sAlarmType;
33
+        private Integer alarmType;
33 34
         // 报警时间
34 35
         private String alarmNow;
35 36
         // 设备ip
@@ -44,19 +45,19 @@ public interface IntrusionService {
44 45
     class IntrusionServiceImpl implements IntrusionService {
45 46
         @Resource
46 47
         private RedisUtil redisUtil;
47
-        @Resource
48
-        private RestTemplate restTemplate;
48
+        /*@Resource
49
+        private RestTemplate restTemplate;*/
50
+        // 推送地址
51
+        /*@Value("${address.pushToIntrusion}")
52
+        private String pushToIntrusion;*/
49 53
         @Value("${spring.redis.ten-minutes}")
50 54
         private long tenMinutes;
51
-        // 推送地址
52
-        @Value("${address.pushToIntrusion}")
53
-        private String pushToIntrusion;
54 55
         @Resource
55 56
         private IntrusionModel intrusionModel;
56 57
 
57 58
         @Override
58 59
         public void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode) {
59
-            // redis key
60
+            /*// redis key
60 61
             if (redisUtil.hasKey(deviceIP)) {
61 62
                 // key 存在丢弃报警数据,不上报
62 63
                 log.info("Don't up!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
@@ -71,7 +72,17 @@ public interface IntrusionService {
71 72
                 restTemplate.exchange(pushToIntrusion, HttpMethod.POST, httpEntity, Object.class);
72 73
                 // 设置缓存
73 74
                 redisUtil.set(deviceIP, JSON.toJSONString(intrusionModel), tenMinutes);
74
-            }
75
+            }*/
76
+            // TODO 物联网到业务平台推送数据网络不通,修改为业务平台主动获取数据
77
+            // 上报数据-接口
78
+
79
+            intrusionModel.setDeviceIP(deviceIP);
80
+            intrusionModel.setAlarmType(sAlarmType);
81
+            intrusionModel.setAlarmNow(alarmNow);
82
+            intrusionModel.setOrgCode(orgCode);
83
+            // 设置异常闯入设备数据-hashCode
84
+            redisUtil.hset(MyConstant.INTRUSION_ALARM_IP, deviceIP, intrusionModel, tenMinutes);
85
+            log.info("Up it!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
75 86
         }
76 87
     }
77 88
 }

+ 2 - 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: dev
13
+    active: prod
14 14
 ---
15 15
 spring:
16 16
   profiles: dev
@@ -72,4 +72,4 @@ snowFlake:
72 72
   leaseTime: 120
73 73
 address:
74 74
   # 推送异常闯入/入侵信息地址
75
-  pushToIntrusion: http://23.99.21.201:59882/pushIntrusion
75
+  pushToIntrusion: http://cpls.test.sys.cqjg.cn