Browse Source

ICC 动态缓存+静态数据

hanqingsong 1 year ago
parent
commit
fb4fc0673a

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

@@ -18,6 +18,7 @@ public class GetIntrusionController {
18 18
     @Resource
19 19
     private GetIntrusionService getIntrusionService;
20 20
 
21
+    // 底代码业务平台获取海康摄像头异常信息接口
21 22
     @GetMapping("/pullIntrusion")
22 23
     public Object pullIntrusion() {
23 24
         return getIntrusionService.pullIntrusion();

+ 10 - 2
src/main/java/com/unissoft/intrusion/IntrusionController.java

@@ -1,15 +1,17 @@
1 1
 package com.unissoft.intrusion;
2 2
 
3 3
 import lombok.extern.slf4j.Slf4j;
4
+import org.springframework.web.bind.annotation.GetMapping;
4 5
 import org.springframework.web.bind.annotation.PostMapping;
6
+import org.springframework.web.bind.annotation.RequestParam;
5 7
 import org.springframework.web.bind.annotation.RestController;
6 8
 
7 9
 import javax.annotation.Resource;
8
-import java.util.Date;
10
+import java.util.Map;
9 11
 
10 12
 /**
11 13
  * @author qingsong.han
12
- * @description: 接收库点摄像头信息并推送到业务平台
14
+ * @description: 接收库点摄像头信息
13 15
  * @create 2022-11-07 10:19
14 16
  */
15 17
 @Slf4j
@@ -18,9 +20,15 @@ public class IntrusionController {
18 20
     @Resource
19 21
     private IntrusionService intrusionService;
20 22
 
23
+    // 接收库点海康摄像头异常信息
21 24
     @PostMapping("/pushIntrusion")
22 25
     public void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode) {
23 26
         intrusionService.pushIntrusion(sAlarmType, alarmNow, deviceIP, orgCode);
24 27
     }
25 28
 
29
+    // 修改ICC通道号编码接口ICC_CHANNEL_CODE key:value(IP:channelCode)
30
+    @GetMapping("/editChannelCode")
31
+    public void editChannelCode(@RequestParam Map<String, String> channelCodes) {
32
+        intrusionService.editChannelCode(channelCodes);
33
+    }
26 34
 }

+ 22 - 2
src/main/java/com/unissoft/intrusion/IntrusionService.java

@@ -13,10 +13,13 @@ import org.springframework.stereotype.Component;
13 13
 import org.springframework.stereotype.Service;
14 14
 import org.springframework.util.LinkedMultiValueMap;
15 15
 import org.springframework.util.MultiValueMap;
16
+import org.springframework.util.StringUtils;
16 17
 import org.springframework.web.client.RestTemplate;
17 18
 
18 19
 import javax.annotation.Resource;
19 20
 import java.util.Date;
21
+import java.util.HashMap;
22
+import java.util.Map;
20 23
 
21 24
 /**
22 25
  * @author qingsong.han
@@ -26,6 +29,8 @@ import java.util.Date;
26 29
 public interface IntrusionService {
27 30
     void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode);
28 31
 
32
+    void editChannelCode(Map<String, String> channelCodes);
33
+
29 34
     @Data
30 35
     @Component
31 36
     class IntrusionModel {
@@ -37,7 +42,7 @@ public interface IntrusionService {
37 42
         private String deviceIP;
38 43
         // 机构编码
39 44
         private String orgCode;
40
-        // 通道号
45
+        // ICC通道号
41 46
         private String channelCode;
42 47
     }
43 48
 
@@ -83,13 +88,20 @@ public interface IntrusionService {
83 88
             intrusionModel.setAlarmNow(alarmNow);
84 89
             intrusionModel.setOrgCode(orgCode);
85 90
             // 添加通道号
86
-            intrusionModel.setChannelCode(getChannelCode(deviceIP));
91
+            intrusionModel.setChannelCode(this.getChannelCode(deviceIP));
87 92
             // 设置异常闯入设备数据-hashCode
88 93
             redisUtil.hset(MyConstant.INTRUSION_ALARM_IP, deviceIP, intrusionModel, tenMinutes);
89 94
             log.info("Up it!-> sAlarmType: {} alarmNow: {} deviceIP: {} orgCode: {}", sAlarmType, alarmNow, deviceIP, orgCode);
90 95
         }
91 96
 
92 97
         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;
102
+        }
103
+
104
+        private String staticChannelCode(String deviceIP) {
93 105
             switch (deviceIP) {
94 106
                 case "192.168.193.16":
95 107
                     return "1000377$1$0$0";
@@ -123,6 +135,14 @@ public interface IntrusionService {
123 135
                     return "";
124 136
             }
125 137
         }
138
+
139
+        @Override
140
+        public void editChannelCode(Map<String, String> channelCodes) {
141
+            channelCodes.forEach((ip, code) ->
142
+                    redisUtil.hset(MyConstant.ICC_CHANNEL_CODE, ip, code)
143
+            );
144
+        }
145
+
126 146
     }
127 147
 
128 148
 

+ 1 - 1
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