소스 검색

剔除测温分机提交的带NULL的异常数据

zhangchun 1 개월 전
부모
커밋
0ae2b0e60a

+ 49 - 9
pom.xml

@@ -3,31 +3,42 @@
3 3
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4 4
     <modelVersion>4.0.0</modelVersion>
5 5
     <parent>
6
-        <groupId>com.unitssoft</groupId>
7
-        <artifactId>smart-grp-nof-pom</artifactId>
8
-        <version>0.0.1-SNAPSHOT</version>
9
-        <relativePath>../smart-grp-nof-pom/pom.xml</relativePath>
6
+        <groupId>org.springframework.boot</groupId>
7
+        <artifactId>spring-boot-starter-parent</artifactId>
8
+        <version>2.3.12.RELEASE</version>
9
+        <relativePath/> <!-- lookup parent from repository -->
10 10
     </parent>
11 11
 
12
+    <groupId>com.unissoft</groupId>
12 13
     <artifactId>smart-grp-nof-dev-test</artifactId>
13
-    <version>0.0.1-SNAPSHOT</version>
14
+    <version>1.0</version>
14 15
     <name>smart-grp-nof-dev-test</name>
15
-    <description>Demo project for Spring Boot</description>
16 16
     <properties>
17
+        <skipTests>true</skipTests>
17 18
         <java.version>1.8</java.version>
19
+        <nof.version>1.0</nof.version>
20
+        <fastjson.version>1.2.83</fastjson.version>
21
+        <lombok.version>1.18.20</lombok.version>
22
+        <spring-web.version>5.2.15.RELEASE</spring-web.version>
18 23
     </properties>
19 24
     <dependencies>
20 25
         <!-- 引入公共模块 -->
21 26
         <dependency>
22 27
             <groupId>com.unissoft</groupId>
23 28
             <artifactId>smart-grp-nof-common</artifactId>
24
-            <version>0.0.1-SNAPSHOT</version>
25
-            <exclusions>
29
+            <version>1.0</version>
30
+            <!--<exclusions>
26 31
                 <exclusion>
27 32
                     <groupId>org.springframework.boot</groupId>
28 33
                     <artifactId>spring-boot-starter-web</artifactId>
29 34
                 </exclusion>
30
-            </exclusions>
35
+            </exclusions>-->
36
+        </dependency>
37
+        <!-- SpringWeb模块-->
38
+        <dependency>
39
+            <groupId>org.springframework</groupId>
40
+            <artifactId>spring-web</artifactId>
41
+            <version>${spring-web.version}</version>
31 42
         </dependency>
32 43
         <dependency>
33 44
             <groupId>com.alibaba</groupId>
@@ -38,6 +49,27 @@
38 49
             <groupId>org.projectlombok</groupId>
39 50
             <artifactId>lombok</artifactId>
40 51
         </dependency>
52
+        <dependency>
53
+            <groupId>org.projectlombok</groupId>
54
+            <artifactId>lombok</artifactId>
55
+            <version>${lombok.version}</version>
56
+        </dependency>
57
+        <dependency>
58
+            <groupId>org.junit.jupiter</groupId>
59
+            <artifactId>junit-jupiter</artifactId>
60
+            <scope>test</scope>
61
+        </dependency>
62
+        <dependency>
63
+            <groupId>commons-codec</groupId>
64
+            <artifactId>commons-codec</artifactId>
65
+            <version>1.14</version>
66
+        </dependency>
67
+        <dependency>
68
+            <groupId>org.springframework.boot</groupId>
69
+            <artifactId>spring-boot-test</artifactId>
70
+            <version>2.3.12.RELEASE</version>
71
+            <scope>test</scope>
72
+        </dependency>
41 73
     </dependencies>
42 74
 
43 75
     <build>
@@ -47,6 +79,14 @@
47 79
                 <groupId>org.springframework.boot</groupId>
48 80
                 <artifactId>spring-boot-maven-plugin</artifactId>
49 81
             </plugin>
82
+            <!--打包时跳过测试-->
83
+            <plugin>
84
+                <groupId>org.apache.maven.plugins</groupId>
85
+                <artifactId>maven-surefire-plugin</artifactId>
86
+                <configuration>
87
+                    <skipTests>true</skipTests>
88
+                </configuration>
89
+            </plugin>
50 90
         </plugins>
51 91
     </build>
52 92
 

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

@@ -21,7 +21,8 @@ public class GetIntrusionController {
21 21
     // 底代码业务平台获取海康摄像头异常信息接口
22 22
     @GetMapping("/pullIntrusion")
23 23
     public Object pullIntrusion() {
24
-        return getIntrusionService.pullIntrusion();
24
+        Object val = getIntrusionService.pullIntrusion();
25
+        return val;
25 26
     }
26 27
 
27 28
 }

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

@@ -1,17 +1,22 @@
1 1
 package com.unissoft.intrusion;
2 2
 
3
+import cn.hutool.core.convert.Convert;
3 4
 import com.unissoft.common.MyConstant;
4 5
 import com.unissoft.utils.RedisUtil;
5 6
 import lombok.extern.slf4j.Slf4j;
6 7
 import org.redisson.transaction.HashKey;
7 8
 import org.springframework.stereotype.Service;
8 9
 import org.springframework.util.CollectionUtils;
10
+import org.springframework.util.MultiValueMap;
9 11
 
10 12
 import javax.annotation.Resource;
11
-import java.util.Collection;
12
-import java.util.Collections;
13
-import java.util.List;
14
-import java.util.Map;
13
+import java.io.File;
14
+import java.io.FileNotFoundException;
15
+import java.io.FileOutputStream;
16
+import java.io.IOException;
17
+import java.nio.ByteBuffer;
18
+import java.text.SimpleDateFormat;
19
+import java.util.*;
15 20
 import java.util.stream.Collectors;
16 21
 
17 22
 /**
@@ -36,9 +41,46 @@ public interface GetIntrusionService {
36 41
                 // 转list
37 42
                 if (!CollectionUtils.isEmpty(hmget)) {
38 43
                     Collection<Object> values = hmget.values();
39
-                    log.info("GetIntrusionService: {}", values);
44
+                    Iterator iterator = values.iterator();
45
+                    log.info("values:{}", values);
46
+                    while(iterator.hasNext()){
47
+                        log.info("next item:{}",iterator.next());
48
+                    }
49
+                    //MultiValueMap<String, Object> newVal = (MultiValueMap)values;
50
+                    //log.info("pullIntrusion, deviceIP:{}, cameraIP:{}", newVal.get("deviceIP"), newVal.get("cameraIP"));
51
+/*
52
+                    MultiValueMap<String, Object> newVal = (MultiValueMap)values;
53
+                    System.out.println("ip:" + newVal.get("cameraIP"));
54
+
55
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
56
+                    String newName = sf.format(new Date());
57
+                    FileOutputStream fout;
58
+                    try {
59
+                        File file = new File( ".//pic//");
60
+                        if(!file.exists())
61
+                            file.mkdir();
62
+                        String filename = ".//pic//" + newName + "VCA_TRAVERSE_PLANE" + ".jpg";
63
+                        fout = new FileOutputStream(filename);
64
+                        //将字节写入文件
65
+                        Byte[]  oBytes = Convert.toByteArray(newVal.get("pic"));
66
+                        byte[] bytes = new byte[oBytes.length];
67
+
68
+                        for(int i = 0; i < oBytes.length; i++) {
69
+                            bytes[i] = oBytes[i];
70
+                        }
71
+                        fout.write(bytes);
72
+                        fout.close();
73
+                    } catch (FileNotFoundException e) {
74
+                        // TODO Auto-generated catch block
75
+                        e.printStackTrace();
76
+                    } catch (IOException e) {
77
+                        // TODO Auto-generated catch block
78
+                        e.printStackTrace();
79
+                    }*/
40 80
                     // 成功返回数据,清除redis缓存
41 81
                     redisUtil.del(MyConstant.INTRUSION_ALARM_IP);
82
+
83
+
42 84
                     return values;
43 85
                 }
44 86
             }

+ 57 - 6
src/main/java/com/unissoft/intrusion/IntrusionController.java

@@ -1,12 +1,16 @@
1 1
 package com.unissoft.intrusion;
2 2
 
3 3
 import lombok.extern.slf4j.Slf4j;
4
-import org.springframework.web.bind.annotation.GetMapping;
5
-import org.springframework.web.bind.annotation.PostMapping;
6
-import org.springframework.web.bind.annotation.RequestParam;
7
-import org.springframework.web.bind.annotation.RestController;
4
+import org.apache.tomcat.util.codec.binary.Base64;
5
+import org.springframework.util.ClassUtils;
6
+import org.springframework.web.bind.annotation.*;
8 7
 
9 8
 import javax.annotation.Resource;
9
+import java.io.File;
10
+import java.io.FileOutputStream;
11
+import java.io.IOException;
12
+import java.text.SimpleDateFormat;
13
+import java.util.Date;
10 14
 import java.util.Map;
11 15
 
12 16
 /**
@@ -21,10 +25,57 @@ public class IntrusionController {
21 25
     private IntrusionService intrusionService;
22 26
 
23 27
     // 接收库点海康摄像头异常信息
28
+    /*
24 29
     @PostMapping("/pushIntrusion")
25
-    public void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode) {
26
-        intrusionService.pushIntrusion(sAlarmType, alarmNow, deviceIP, orgCode);
30
+    public void pushIntrusion(Integer sAlarmType, String alarmNow, String deviceIP, String orgCode,
31
+                              String cameraIP, String bytes, Integer size) {
32
+        intrusionService.pushIntrusion(sAlarmType, alarmNow, deviceIP, orgCode, cameraIP, bytes, size);
27 33
     }
34
+    */
35
+    @RequestMapping("/pushIntrusion")
36
+    @ResponseBody
37
+    public void pushIntrusion(@RequestParam Map<String,String> map){
38
+        Integer alarmType = Integer.parseInt(map.get("sAlarmType").toString());
39
+        String alarmNow = map.get("alarmNow").toString();
40
+        String deviceIP = map.get("deviceIP").toString();
41
+        String orgCode = map.get("orgCode").toString();
42
+        String cameraIP = "";
43
+        String picByte = "";
44
+        Integer size = 0;
45
+        if(map.containsKey("picByte")) {
46
+            cameraIP = map.get("cameraIP").toString();
47
+            picByte = map.get("picByte").toString();
48
+            size = Integer.parseInt(map.get("sAlarmType").toString());
49
+        }
50
+        intrusionService.pushIntrusion(alarmType, alarmNow, deviceIP, orgCode, cameraIP, picByte, size);
51
+
52
+        byte[] bytes = Base64.decodeBase64(picByte); // Base64解码
53
+        //将字节写入文件
54
+        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
55
+        String newName = sf.format(new Date());
56
+        FileOutputStream fout;
57
+        String path = "." + File.separator + "pic" + File.separator + newName + "_pSnapPicBuffer" + ".jpg";
58
+        System.out.println("path:"+ path);
59
+        FileOutputStream fis = null;
60
+        try {
61
+            File file =new File(path);
62
+            file.createNewFile();
63
+            fis = new FileOutputStream(file);
64
+            fis.write(bytes);
65
+        } catch (IOException e) {
66
+            e.printStackTrace();
67
+        } finally {
68
+            if (fis != null) {
69
+                try {
70
+                    fis.close();
71
+                } catch (IOException e) {
72
+                    e.printStackTrace();
73
+                }
74
+            }
75
+        }
76
+
77
+    }
78
+
28 79
 
29 80
     // 修改ICC通道号编码接口ICC_CHANNEL_CODE key:value(IP:channelCode)
30 81
     @GetMapping("/editChannelCode")

+ 76 - 23
src/main/java/com/unissoft/intrusion/IntrusionService.java

@@ -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":