浏览代码

对接海康

wyb 1 年之前
父节点
当前提交
d724b2294a

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
1
+/target
2
+/.idea

二进制
lib/artemis-http-client-1.1.11.RELEASE.jar


+ 25 - 5
pom.xml

@@ -23,10 +23,35 @@
23 23
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24 24
         <java.version>1.8</java.version>
25 25
         <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
26
+        <commons-lang3.version>3.14.0</commons-lang3.version>
27
+        <httpclient.version>4.5.14</httpclient.version>
28
+        <artemis-http-client.version>1.1.11</artemis-http-client.version>
26 29
         <skipTests>true</skipTests>
27 30
     </properties>
28 31
 
29 32
     <dependencies>
33
+        <!--海康start-->
34
+        <dependency>
35
+            <groupId>com.hikvision.ga</groupId>
36
+            <artifactId>artemis-http-client</artifactId>
37
+            <version>${artemis-http-client.version}</version>
38
+            <scope>system</scope>
39
+            <systemPath>${pom.basedir}/lib/artemis-http-client-1.1.11.RELEASE.jar</systemPath>
40
+        </dependency>
41
+        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
42
+        <dependency>
43
+            <groupId>org.apache.commons</groupId>
44
+            <artifactId>commons-lang3</artifactId>
45
+            <version>${commons-lang3.version}</version>
46
+        </dependency>
47
+        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
48
+        <dependency>
49
+            <groupId>org.apache.httpcomponents</groupId>
50
+            <artifactId>httpclient</artifactId>
51
+            <version>${httpclient.version}</version>
52
+        </dependency>
53
+        <!--海康end-->
54
+
30 55
         <dependency>
31 56
             <groupId>org.springframework.boot</groupId>
32 57
             <artifactId>spring-boot-starter-web</artifactId>
@@ -51,11 +76,6 @@
51 76
             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
52 77
         </dependency>
53 78
 
54
-        <dependency>
55
-            <groupId>org.apache.commons</groupId>
56
-            <artifactId>commons-lang3</artifactId>
57
-            <version>3.7</version>
58
-        </dependency>
59 79
 
60 80
         <!-- <dependency>
61 81
             <groupId>org.activiti</groupId>

+ 28 - 0
src/main/java/com/chinaitop/depot/hk/config/ArtemisConfigInit.java

@@ -0,0 +1,28 @@
1
+package com.chinaitop.depot.hk.config;
2
+
3
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.context.annotation.Configuration;
6
+
7
+import javax.annotation.Resource;
8
+
9
+/**
10
+ * @author ybw
11
+ * @version V1.0
12
+ * @className ArtemisConfigInit
13
+ * @date 2024/6/18
14
+ **/
15
+@Configuration
16
+public class ArtemisConfigInit {
17
+    @Resource
18
+    private HkConfig hkConfig;
19
+
20
+    @Bean
21
+    public ArtemisConfig getArtemisConfig() {
22
+        ArtemisConfig artemisConfig = new ArtemisConfig();
23
+        artemisConfig.setHost(hkConfig.getHost());
24
+        artemisConfig.setAppKey(hkConfig.getAppKey());
25
+        artemisConfig.setAppSecret(hkConfig.getAppSecret());
26
+        return artemisConfig;
27
+    }
28
+}

+ 20 - 0
src/main/java/com/chinaitop/depot/hk/config/HkConfig.java

@@ -0,0 +1,20 @@
1
+package com.chinaitop.depot.hk.config;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.context.annotation.Configuration;
6
+
7
+/**
8
+ * @author ybw
9
+ * @version V1.0
10
+ * @className HkConfit
11
+ * @date 2024/6/18
12
+ **/
13
+@Configuration
14
+@ConfigurationProperties("hk")
15
+@Data
16
+public class HkConfig {
17
+    public String host;
18
+    public String appKey;
19
+    public String appSecret;
20
+}

+ 17 - 0
src/main/java/com/chinaitop/depot/hk/constant/ApiHkConstant.java

@@ -0,0 +1,17 @@
1
+package com.chinaitop.depot.hk.constant;
2
+
3
+/**
4
+ * @author ybw
5
+ * @version V1.0
6
+ * @className APICostant
7
+ * @date 2024/6/18
8
+ **/
9
+public interface ApiHkConstant {
10
+    /**
11
+     * 分页获取区域列表
12
+     *
13
+     * @author: ybw
14
+     * @date: 2024/6/18
15
+     **/
16
+    String API_HK_REGIONS = "/artemis/api/resource/v1/regions";
17
+}

+ 33 - 0
src/main/java/com/chinaitop/depot/hk/dto/req/PageReqDTO.java

@@ -0,0 +1,33 @@
1
+package com.chinaitop.depot.hk.dto.req;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Data;
5
+
6
+/**
7
+ * @author ybw
8
+ * @version V1.0
9
+ * @className PageDTO
10
+ * @date 2024/6/18
11
+ **/
12
+@Data
13
+@AllArgsConstructor
14
+public class PageReqDTO {
15
+    /**
16
+     * 当前页码
17
+     * 范围 ( 0 , ~ ),最大为整数最大值,若是范围内数字超过实际最大页码值,返回最后一页记录
18
+     * 注:0 < pageNo
19
+     *
20
+     * @author: ybw
21
+     * @date: 2024/6/18
22
+     **/
23
+    private Integer pageNo;
24
+    /**
25
+     * 分页大小
26
+     * 范围 ( 0 , 1000 ]
27
+     * 注:0 < pageSize≤1000
28
+     *
29
+     * @author: ybw
30
+     * @date: 2024/6/18
31
+     **/
32
+    private Integer pageSize;
33
+}

文件差异内容过多而无法显示
+ 29 - 0
src/main/java/com/chinaitop/depot/hk/dto/res/PageResDTO.java


+ 44 - 0
src/main/java/com/chinaitop/depot/hk/dto/res/RegionResDTO.java

@@ -0,0 +1,44 @@
1
+package com.chinaitop.depot.hk.dto.res;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 区域
7
+ *
8
+ * @author ybw
9
+ * @version V1.0
10
+ * @className Regions
11
+ * @date 2024/6/18
12
+ **/
13
+@Data
14
+public class RegionResDTO {
15
+    /**
16
+     * 区域唯一标识码
17
+     *
18
+     * @author: ybw
19
+     * @date: 2024/6/18
20
+     **/
21
+    private String indexCode;
22
+    /**
23
+     * 区域名称
24
+     *
25
+     * @author: ybw
26
+     * @date: 2024/6/18
27
+     **/
28
+    private String name;
29
+    /**
30
+     * 父区域唯一标识码
31
+     *
32
+     * @author: ybw
33
+     * @date: 2024/6/18
34
+     **/
35
+    private String parentIndexCode;
36
+    /**
37
+     * 树编号
38
+     *
39
+     * @author: ybw
40
+     * @date: 2024/6/18
41
+     **/
42
+    private String treeCode;
43
+
44
+}

+ 16 - 0
src/main/java/com/chinaitop/depot/hk/dto/res/ResultResDTO.java

@@ -0,0 +1,16 @@
1
+package com.chinaitop.depot.hk.dto.res;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * @author ybw
7
+ * @version V1.0
8
+ * @className HkResult
9
+ * @date 2024/6/18
10
+ **/
11
+@Data
12
+public class ResultResDTO<T> {
13
+    private String code;
14
+    private String msg;
15
+    private T data;
16
+}

+ 23 - 0
src/main/java/com/chinaitop/depot/hk/service/HkService.java

@@ -0,0 +1,23 @@
1
+package com.chinaitop.depot.hk.service;
2
+
3
+
4
+import com.chinaitop.depot.hk.dto.req.PageReqDTO;
5
+import com.chinaitop.depot.hk.dto.res.PageResDTO;
6
+import com.chinaitop.depot.hk.dto.res.RegionResDTO;
7
+import com.chinaitop.depot.hk.dto.res.ResultResDTO;
8
+
9
+/**
10
+ * 海康
11
+ *
12
+ * @author ybw
13
+ * @version V1.0
14
+ * @className HkService
15
+ * @date 2024/6/18
16
+ **/
17
+public interface HkService {
18
+    /**
19
+     * 分页获取区域列表
20
+     * /api/resource/v1/regions
21
+     */
22
+    ResultResDTO<PageResDTO<RegionResDTO>> getRegions(PageReqDTO pageReqDTO);
23
+}

+ 57 - 0
src/main/java/com/chinaitop/depot/hk/service/impl/HkServiceImpl.java

@@ -0,0 +1,57 @@
1
+package com.chinaitop.depot.hk.service.impl;
2
+
3
+
4
+import com.alibaba.fastjson.JSON;
5
+import com.alibaba.fastjson.JSONObject;
6
+import com.alibaba.fastjson.TypeReference;
7
+import com.chinaitop.depot.hk.constant.ApiHkConstant;
8
+import com.chinaitop.depot.hk.dto.req.PageReqDTO;
9
+import com.chinaitop.depot.hk.dto.res.PageResDTO;
10
+import com.chinaitop.depot.hk.dto.res.RegionResDTO;
11
+import com.chinaitop.depot.hk.dto.res.ResultResDTO;
12
+import com.chinaitop.depot.hk.service.HkService;
13
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
14
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
15
+import lombok.extern.slf4j.Slf4j;
16
+import org.springframework.stereotype.Service;
17
+
18
+import javax.annotation.Resource;
19
+import java.util.HashMap;
20
+import java.util.Map;
21
+
22
+/**
23
+ * @author ybw
24
+ * @version V1.0
25
+ * @className HkServiceImpl
26
+ * @date 2024/6/18
27
+ **/
28
+@Service
29
+@Slf4j
30
+public class HkServiceImpl implements HkService {
31
+
32
+    @Resource
33
+    private ArtemisConfig artemisConfig;
34
+
35
+    @Override
36
+    public ResultResDTO<PageResDTO<RegionResDTO>> getRegions(PageReqDTO pageReqDTO) {
37
+        ResultResDTO<PageResDTO<RegionResDTO>> resultResDTO = null;
38
+        // 接口地址
39
+        Map<String, String> path = new HashMap<String, String>(2) {
40
+            {
41
+                put("https://", ApiHkConstant.API_HK_REGIONS);
42
+            }
43
+        };
44
+        try {
45
+            String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, JSON.toJSONString(pageReqDTO), null, null, "application/json");
46
+            resultResDTO = JSONObject.parseObject(
47
+                    result,
48
+                    new TypeReference<ResultResDTO<PageResDTO<RegionResDTO>>>() {
49
+                    }
50
+            );
51
+            log.info("{}", JSON.toJSONString(resultResDTO));
52
+        } catch (Exception e) {
53
+            log.error("getRegions error:", e);
54
+        }
55
+        return resultResDTO;
56
+    }
57
+}

+ 5 - 0
src/main/resources/bootstrap-dev.yml

@@ -53,3 +53,8 @@ sendMessage:
53 53
 windows-path: /home/depot/monitorzd/
54 54
 
55 55
 jsgjjsjUrl: http://localhost:9022/recPublish/sendMessage
56
+# 海康
57
+hk:
58
+  host: 59.220.180.103:443 #平台(nginx)IP 和端口
59
+  app-key: 22161302 #合作方 key
60
+  app-secret: aSDjmmd5S4uSKkQSygiV #合作方 Secret

+ 5 - 1
src/main/resources/bootstrap-prod.yml

@@ -53,4 +53,8 @@ sendMessage:
53 53
 windows-path: /home/depot/monitorzd/
54 54
 
55 55
 jsgjjsjUrl: http://localhost:9022/recPublish/sendMessage
56
-
56
+# 海康
57
+hk:
58
+  host: 59.220.180.103:443 #平台(nginx)IP 和端口
59
+  app-key: 22161302 #合作方 key
60
+  app-secret: aSDjmmd5S4uSKkQSygiV #合作方 Secret

+ 23 - 0
src/test/java/com/chinaitop/depot/hk/service/HkServiceTest.java

@@ -0,0 +1,23 @@
1
+package com.chinaitop.depot.hk.service;
2
+
3
+import com.chinaitop.depot.DepotMonitorApplication;
4
+import com.chinaitop.depot.hk.dto.req.PageReqDTO;
5
+import org.junit.Test;
6
+import org.junit.runner.RunWith;
7
+import org.springframework.boot.test.context.SpringBootTest;
8
+import org.springframework.test.context.junit4.SpringRunner;
9
+
10
+import javax.annotation.Resource;
11
+
12
+@RunWith(SpringRunner.class)
13
+@SpringBootTest(classes = DepotMonitorApplication.class)
14
+public class HkServiceTest {
15
+
16
+    @Resource
17
+    private HkService hkService;
18
+
19
+    @Test
20
+    public void getRegions() {
21
+        hkService.getRegions(new PageReqDTO(1, 30));
22
+    }
23
+}