Browse Source

cxf webservice 测温接口

hanqingsong 2 years ago
parent
commit
1ef9ef071b

+ 7 - 0
pom.xml

@@ -87,6 +87,13 @@
87 87
             <groupId>org.springframework.boot</groupId>
88 88
             <artifactId>spring-boot-starter-integration</artifactId>
89 89
         </dependency>
90
+        <!-- webservice cxf -->
91
+        <dependency>
92
+            <groupId>org.apache.cxf</groupId>
93
+            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
94
+            <version>3.5.5</version>
95
+        </dependency>
96
+
90 97
         <!-- https://mvnrepository.com/artifact/de.schlichtherle.truelicense/truelicense-core -->
91 98
         <!--<dependency>
92 99
             <groupId>de.schlichtherle.truelicense</groupId>

+ 38 - 0
src/main/java/com/unissoft/webservice/cxf/CxfConfig.java

@@ -0,0 +1,38 @@
1
+package com.unissoft.webservice.cxf;
2
+
3
+import com.unissoft.webservice.service.GrainTemperatureService;
4
+import com.unissoft.webservice.service.impl.GrainTemperatureServiceImpl;
5
+import org.apache.cxf.Bus;
6
+import org.apache.cxf.bus.spring.SpringBus;
7
+import org.apache.cxf.jaxws.EndpointImpl;
8
+import org.springframework.context.annotation.Bean;
9
+import org.springframework.context.annotation.Configuration;
10
+
11
+import javax.xml.ws.Endpoint;
12
+
13
+/**
14
+ * @author qingsong.han
15
+ * @description: webservice cxf config
16
+ * @create 2023-03-14 16:01
17
+ */
18
+@Configuration
19
+public class CxfConfig {
20
+
21
+    @Bean(name = Bus.DEFAULT_BUS_ID)
22
+    public SpringBus springBus() {
23
+        return new SpringBus();
24
+    }
25
+
26
+    // 温度
27
+    @Bean
28
+    public GrainTemperatureService grainTemperatureService() {
29
+        return new GrainTemperatureServiceImpl();
30
+    }
31
+
32
+    @Bean
33
+    public Endpoint uploadGrainTemperatureData() {
34
+        EndpointImpl endpoint = new EndpointImpl(springBus(), grainTemperatureService());
35
+        endpoint.publish("/uploadGrainTemperatureData");
36
+        return endpoint;
37
+    }
38
+}

+ 59 - 0
src/main/java/com/unissoft/webservice/model/ResponseEntity.java

@@ -0,0 +1,59 @@
1
+package com.unissoft.webservice.model;
2
+
3
+import lombok.Data;
4
+
5
+import java.io.Serializable;
6
+
7
+// 返回基类
8
+@Data
9
+public class ResponseEntity<T> implements Serializable {
10
+
11
+    private static final long serialVersionUID = -2825436079063723409L;
12
+
13
+    //成功
14
+    private static final String OK = "200";
15
+    //失败
16
+    private static final String FAILED = "600";
17
+    private static final String BUSSINESS_FAILED = "550";
18
+    private static final String UNAUTHENTICATION = "401";
19
+
20
+    private String retCode;
21
+    private String message;
22
+    private T data;
23
+
24
+    private static <T> ResponseEntity<T> buildResponse(String retCode, String message, T data) {
25
+        ResponseEntity<T> responseEntity = new ResponseEntity<T>();
26
+        responseEntity.retCode = retCode;
27
+        responseEntity.message = message;
28
+        responseEntity.data = data;
29
+        return responseEntity;
30
+    }
31
+
32
+    public static <T> ResponseEntity<T> ok() {
33
+        return buildResponse(ResponseEntity.OK, "success", null);
34
+    }
35
+
36
+    public static <T> ResponseEntity<T> ok(T data) {
37
+        return buildResponse(ResponseEntity.OK, "success", data);
38
+
39
+    }
40
+
41
+    public static <T> ResponseEntity<T> ok(String message, T data) {
42
+        return buildResponse(ResponseEntity.OK, message, data);
43
+    }
44
+
45
+
46
+    public static <T> ResponseEntity<T> failed(String message) {
47
+        return buildResponse(ResponseEntity.FAILED, message, null);
48
+    }
49
+
50
+    public static <T> ResponseEntity<T> businessFailed(String message) {
51
+        return buildResponse(ResponseEntity.BUSSINESS_FAILED, message, null);
52
+    }
53
+
54
+    public static <T> ResponseEntity<T> unauthentication(String message) {
55
+        return buildResponse(ResponseEntity.UNAUTHENTICATION, message, null);
56
+    }
57
+
58
+}
59
+

+ 22 - 0
src/main/java/com/unissoft/webservice/service/GrainTemperatureService.java

@@ -0,0 +1,22 @@
1
+package com.unissoft.webservice.service;
2
+
3
+import com.unissoft.webservice.model.ResponseEntity;
4
+
5
+import javax.jws.WebParam;
6
+import javax.jws.WebService;
7
+
8
+/**
9
+ * @author qingsong.han
10
+ * @description: 测温数据
11
+ * @create 2023-03-14 16:32
12
+ */
13
+@WebService
14
+public interface GrainTemperatureService {
15
+    /**
16
+     * 测温webservice 接收数据接口
17
+     * @param dataSource 数据来源
18
+     * @param grainTemperatureData 数据
19
+     * @return
20
+     */
21
+    ResponseEntity uploadGrainTemperatureData(@WebParam(name = "dataSource") String dataSource, @WebParam(name = "grainTemperatureData") String grainTemperatureData);
22
+}

+ 35 - 0
src/main/java/com/unissoft/webservice/service/impl/GrainTemperatureServiceImpl.java

@@ -0,0 +1,35 @@
1
+package com.unissoft.webservice.service.impl;
2
+
3
+import com.alibaba.fastjson2.JSON;
4
+import com.unissoft.data.mapper.DataGrainTempMapper;
5
+import com.unissoft.data.model.DataGrainTemp;
6
+import com.unissoft.webservice.model.ResponseEntity;
7
+import com.unissoft.webservice.service.GrainTemperatureService;
8
+import lombok.extern.slf4j.Slf4j;
9
+import org.springframework.stereotype.Service;
10
+import org.springframework.transaction.annotation.Transactional;
11
+
12
+import javax.annotation.Resource;
13
+import java.util.List;
14
+
15
+/**
16
+ * @author qingsong.han
17
+ * @description: 测温数据实现
18
+ * @create 2023-03-14 16:33
19
+ */
20
+@Slf4j
21
+@Service
22
+public class GrainTemperatureServiceImpl implements GrainTemperatureService {
23
+//    @Resource
24
+//    private DataGrainTempMapper grainTempMapper;
25
+
26
+    @Override
27
+    @Transactional(rollbackFor = Exception.class)
28
+    public ResponseEntity uploadGrainTemperatureData(String dataSource, String grainTemperatureData) {
29
+        // 数据处理逻辑
30
+        log.info("接收到:{}测温数据:{}", dataSource, grainTemperatureData);
31
+        // 数据保存
32
+//        grainTempMapper.insert();
33
+        return ResponseEntity.ok();
34
+    }
35
+}

+ 3 - 1
src/main/resources/application.yml

@@ -62,4 +62,6 @@ mybatis-plus:
62 62
     # console show sql
63 63
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
64 64
 web:
65
-  upload-path: /home/files
65
+  upload-path: /home/files
66
+cxf:
67
+  path: /intelligent