hanqingsong лет назад: 6
Сommit
4ad06b921c

+ 104 - 0
pom.xml

@@ -0,0 +1,104 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5
+    <parent>
6
+        <groupId>org.springframework.boot</groupId>
7
+        <artifactId>spring-boot-starter-parent</artifactId>
8
+        <version>2.0.4.RELEASE</version>
9
+        <relativePath/> <!-- lookup parent from repository -->
10
+    </parent>
11
+    <groupId>com.chinaitop</groupId>
12
+    <artifactId>depot-api</artifactId>
13
+    <version>0.0.1</version>
14
+    <name>depot-api</name>
15
+    <packaging>jar</packaging>
16
+    <description>DepotApi project for Spring Boot for depot service</description>
17
+
18
+    <properties>
19
+        <java.version>1.8</java.version>
20
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
22
+        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
23
+    </properties>
24
+
25
+    <dependencies>
26
+        <dependency>
27
+            <groupId>org.springframework.boot</groupId>
28
+            <artifactId>spring-boot-starter-web</artifactId>
29
+        </dependency>
30
+        <dependency>
31
+            <groupId>org.springframework.cloud</groupId>
32
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
33
+        </dependency>
34
+        <dependency>
35
+            <groupId>org.springframework.cloud</groupId>
36
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
37
+        </dependency>
38
+
39
+        <dependency>
40
+            <groupId>org.springframework.boot</groupId>
41
+            <artifactId>spring-boot-starter-test</artifactId>
42
+            <scope>test</scope>
43
+            <exclusions>
44
+                <exclusion>
45
+                    <groupId>org.junit.vintage</groupId>
46
+                    <artifactId>junit-vintage-engine</artifactId>
47
+                </exclusion>
48
+            </exclusions>
49
+        </dependency>
50
+    </dependencies>
51
+
52
+    <!--deploy-->
53
+    <distributionManagement>
54
+        <repository>
55
+            <id>nexus</id>
56
+            <!--名称自己定义-->
57
+            <name>release</name>
58
+            <url>http://10.10.1.25:8760/repository/host_repository/</url>
59
+        </repository>
60
+    </distributionManagement>
61
+    <dependencyManagement>
62
+        <dependencies>
63
+            <dependency>
64
+                <groupId>org.springframework.cloud</groupId>
65
+                <artifactId>spring-cloud-dependencies</artifactId>
66
+                <version>${spring-cloud.version}</version>
67
+                <type>pom</type>
68
+                <scope>import</scope>
69
+            </dependency>
70
+        </dependencies>
71
+    </dependencyManagement>
72
+
73
+    <build>
74
+        <!--定义编译,打包,部署的项目名称-->
75
+        <finalName>${project.artifactId}</finalName>
76
+        <plugins>
77
+            <plugin>
78
+                <groupId>org.springframework.boot</groupId>
79
+                <artifactId>spring-boot-maven-plugin</artifactId>
80
+            </plugin>
81
+            <!--跳过测试代码的编译-->
82
+            <plugin>
83
+                <groupId>org.apache.maven.plugins</groupId>
84
+                <artifactId>maven-surefire-plugin</artifactId>
85
+                <configuration>
86
+                    <skip>true</skip>
87
+                </configuration>
88
+            </plugin>
89
+        </plugins>
90
+    </build>
91
+    <!--使用Spring稳定版本-->
92
+    <repositories>
93
+        <repository>
94
+            <id>spring-milestones</id>
95
+            <name>Spring Milestones</name>
96
+            <url>https://repo.spring.io/milestone</url>
97
+            <!--不下载snapshots快照版-->
98
+            <snapshots>
99
+                <enabled>false</enabled>
100
+            </snapshots>
101
+        </repository>
102
+    </repositories>
103
+
104
+</project>

+ 17 - 0
src/main/java/com/chinaitop/DepotApiApplication.java

@@ -0,0 +1,17 @@
1
+package com.chinaitop;
2
+
3
+import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6
+import org.springframework.cloud.openfeign.EnableFeignClients;
7
+
8
+@EnableDiscoveryClient
9
+@EnableFeignClients
10
+@SpringBootApplication
11
+public class DepotApiApplication {
12
+
13
+    public static void main(String[] args) {
14
+        SpringApplication.run(DepotApiApplication.class, args);
15
+    }
16
+
17
+}

+ 96 - 0
src/main/java/com/chinaitop/depot/common/ResponseEntity.java

@@ -0,0 +1,96 @@
1
+package com.chinaitop.depot.common;
2
+
3
+import java.io.Serializable;
4
+
5
+//返回基类
6
+public class ResponseEntity<T> implements Serializable {
7
+
8
+    private static final long serialVersionUID = -2825436079063723409L;
9
+
10
+    //成功
11
+    private static final String OK = "200";
12
+    //失败
13
+    private static final String FAILED = "600";
14
+    private static final String BUSSINESS_FAILED = "550";
15
+    private static final String UNAUTHENTICATION = "401";
16
+
17
+    private String retCode;
18
+    private String message;
19
+    private T data;
20
+
21
+    public String getRetCode() {
22
+        return retCode;
23
+    }
24
+
25
+    public void setRetCode(String retCode) {
26
+        this.retCode = retCode;
27
+    }
28
+
29
+    public String getMessage() {
30
+        return message;
31
+    }
32
+
33
+    public void setMessage(String message) {
34
+        this.message = message;
35
+    }
36
+
37
+    public T getData() {
38
+        return data;
39
+    }
40
+
41
+    public void setData(T data) {
42
+        this.data = data;
43
+    }
44
+
45
+    private static <T> ResponseEntity<T> buildResponse(String retCode, String message, T data){
46
+        ResponseEntity<T> responseEntity = new ResponseEntity<T>();
47
+        responseEntity.retCode = retCode;
48
+        responseEntity.message = message;
49
+        responseEntity.data = data;
50
+        return responseEntity;
51
+    }
52
+
53
+    public static <T> ResponseEntity<T> ok(){
54
+        return buildResponse(ResponseEntity.OK,"success",null);
55
+    }
56
+    public static <T> ResponseEntity<T> ok(T data){
57
+        return buildResponse(ResponseEntity.OK,"success",data);
58
+
59
+    }
60
+    public static <T> ResponseEntity<T> ok(String message, T data){
61
+        return buildResponse(ResponseEntity.OK,message,data);
62
+    }
63
+
64
+
65
+    public static <T> ResponseEntity<T> failed(String message){
66
+        return buildResponse(ResponseEntity.FAILED,message,null);
67
+    }
68
+
69
+    public static <T> ResponseEntity<T> businessFailed(String message){
70
+        return buildResponse(ResponseEntity.BUSSINESS_FAILED,message,null);
71
+    }
72
+
73
+    public static <T> ResponseEntity<T> unauthentication(String message){
74
+        return buildResponse(ResponseEntity.UNAUTHENTICATION,message,null);
75
+    }
76
+
77
+    private String state;
78
+    private String msg;
79
+
80
+    public String getState() {
81
+        return state;
82
+    }
83
+
84
+    public void setState(String state) {
85
+        this.state = state;
86
+    }
87
+
88
+    public String getMsg() {
89
+        return msg;
90
+    }
91
+
92
+    public void setMsg(String msg) {
93
+        this.msg = msg;
94
+    }
95
+}
96
+

+ 38 - 0
src/main/java/com/chinaitop/depot/grainAPI/controller/GrainAPIController.java

@@ -0,0 +1,38 @@
1
+package com.chinaitop.depot.grainAPI.controller;
2
+
3
+import com.chinaitop.depot.common.ResponseEntity;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.web.bind.annotation.GetMapping;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RequestParam;
8
+import org.springframework.web.bind.annotation.RestController;
9
+import org.springframework.web.client.RestTemplate;
10
+
11
+/**
12
+ * 文件描述
13
+ *
14
+ * @author tongxi.xia
15
+ * @date 2019年12月26日 14:48
16
+ */
17
+@RestController
18
+@RequestMapping(value = "/depotGrain")
19
+public class GrainAPIController {
20
+
21
+    /*@Autowired
22
+    private RestTemplate restTemplate;*/
23
+
24
+    /**
25
+    * @MethodName: sendTemperatureMeasurementInstruction
26
+    * @Description: TODO 市平台测温接口,根据库点编码检测测温
27
+    * @Param: [orgIds]
28
+    * @Return: java.lang.String
29
+    * @Author: tongxi.xia
30
+    * @Date: 2019/12/26
31
+    **/
32
+    @GetMapping("/sendTemperatureMeasurementInstruction")
33
+    public ResponseEntity sendTemperatureMeasurementInstruction(@RequestParam String orgIds) {
34
+//        String url = "http://localhost:9028/intelligents/temperatureRecord/getsent?orgids="+orgids;
35
+//        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
36
+        return ResponseEntity.ok();
37
+    }
38
+}

+ 41 - 0
src/main/resources/application.yml

@@ -0,0 +1,41 @@
1
+spring:
2
+  profiles:
3
+    active: local_dev
4
+server:
5
+  port: 8765
6
+  tomcat:
7
+    uri-encoding: utf-8
8
+---
9
+#本地开发环境
10
+spring:
11
+  profiles: local_dev
12
+  application:
13
+    name: depot-api
14
+# 注册中心配置
15
+eureka:
16
+  client:
17
+    service-url:
18
+      defaultZone: http://${spring.cloud.client.ip-address}:9001/eureka/
19
+  instance:
20
+    prefer-ip-address: true
21
+    # 每隔10s发送一次心跳(默认30s)
22
+    lease-renewal-interval-in-seconds: 10
23
+    # 告知服务端30秒还未收到心跳的话,就将该服务移除列表(默认90s)
24
+    lease-expiration-duration-in-seconds: 30
25
+---
26
+#测试环境
27
+spring:
28
+  profiles: testing
29
+  application:
30
+    name: depot-api
31
+# 注册中心配置
32
+eureka:
33
+  client:
34
+    service-url:
35
+      defaultZone: http://192.168.123.98:9001/eureka/
36
+  instance:
37
+    prefer-ip-address: true
38
+    # 每隔10s发送一次心跳(默认30s)
39
+    lease-renewal-interval-in-seconds: 10
40
+    # 告知服务端30秒还未收到心跳的话,就将该服务移除列表(默认90s)
41
+    lease-expiration-duration-in-seconds: 30

+ 16 - 0
src/test/java/com/chinaitop/DepotApiApplicationTests.java

@@ -0,0 +1,16 @@
1
+package com.chinaitop;
2
+
3
+import org.junit.Test;
4
+import org.junit.runner.RunWith;
5
+import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7
+
8
+@RunWith(SpringJUnit4ClassRunner.class)
9
+@SpringBootTest
10
+public class DepotApiApplicationTests {
11
+
12
+    @Test
13
+    void contextLoads() {
14
+    }
15
+
16
+}