refactor: 完善webservice服务
This commit is contained in:
parent
43bb62dbdc
commit
a6ef663686
@ -124,27 +124,6 @@
|
|||||||
<artifactId>jtds</artifactId>
|
<artifactId>jtds</artifactId>
|
||||||
<version>1.3.1</version>
|
<version>1.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--WebService-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web-services</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--JAXB(用于处理XML和SOAP消息)-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-oxm</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--CXF webservices-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
|
|
||||||
<version>4.0.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.jws</groupId>
|
|
||||||
<artifactId>jakarta.jws-api</artifactId>
|
|
||||||
<version>2.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -66,6 +66,12 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--CXF webservices-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
|
||||||
|
<version>3.4.4</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.ktg.mes.md.config;
|
||||||
|
|
||||||
|
import com.ktg.mes.md.service.IMasterDataSyncService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.cxf.Bus;
|
||||||
|
import org.apache.cxf.bus.spring.SpringBus;
|
||||||
|
import org.apache.cxf.jaxws.EndpointImpl;
|
||||||
|
import org.apache.cxf.transport.servlet.CXFServlet;
|
||||||
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.xml.ws.Endpoint;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WebServiceConfig {
|
||||||
|
private final IMasterDataSyncService masterDataSyncService;
|
||||||
|
|
||||||
|
@Bean(name = Bus.DEFAULT_BUS_ID)
|
||||||
|
public SpringBus springBus() {
|
||||||
|
return new SpringBus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ServletRegistrationBean<CXFServlet> cxfServlet() {
|
||||||
|
return new ServletRegistrationBean<>(new CXFServlet(), "/WebServices/open/*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Endpoint endpoint() {
|
||||||
|
EndpointImpl endpoint = new EndpointImpl(springBus(), masterDataSyncService);
|
||||||
|
endpoint.publish("/MasterDataSyncService");
|
||||||
|
return endpoint;
|
||||||
|
}
|
||||||
|
}
|
@ -2,29 +2,40 @@ package com.ktg.mes.md.service;
|
|||||||
|
|
||||||
import javax.jws.WebMethod;
|
import javax.jws.WebMethod;
|
||||||
import javax.jws.WebParam;
|
import javax.jws.WebParam;
|
||||||
|
import javax.jws.WebResult;
|
||||||
import javax.jws.WebService;
|
import javax.jws.WebService;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
@WebService(name = "masterDataSyncService", targetNamespace = "http://server.spring.zhang.pers/")
|
@WebService(name = IMasterDataSyncService.SERVICE_NAME, targetNamespace = IMasterDataSyncService.TARGET_NAMESPACE)
|
||||||
public interface IMasterDataSyncService {
|
public interface IMasterDataSyncService {
|
||||||
|
String SERVICE_NAME = "MasterDataSyncService";
|
||||||
|
|
||||||
|
String TARGET_NAMESPACE = "http://server.spring.zhang.pers/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步物料数据
|
* 同步物料数据
|
||||||
|
*
|
||||||
* @param materialListStr 物料列表
|
* @param materialListStr 物料列表
|
||||||
*/
|
*/
|
||||||
@WebMethod(operationName = "syncMaterial")
|
@WebMethod(operationName = "syncMaterial")
|
||||||
String syncMaterial(@WebParam(name = "materialList") Spring materialListStr);
|
@WebResult
|
||||||
|
String syncMaterial(@WebParam(name = "materialListStr") String materialListStr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步物料分类数据
|
* 同步物料分类数据
|
||||||
|
*
|
||||||
* @param materialCategoryListStr 物料分类列表
|
* @param materialCategoryListStr 物料分类列表
|
||||||
*/
|
*/
|
||||||
@WebMethod(operationName = "syncMaterialCategory")
|
@WebMethod(operationName = "syncMaterialCategory")
|
||||||
String syncMaterialCategory(@WebParam(name = "materialCategoryList") Spring materialCategoryListStr);
|
@WebResult
|
||||||
|
String syncMaterialCategory(@WebParam(name = "materialCategoryList") String materialCategoryListStr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步计量单位数据
|
* 同步计量单位数据
|
||||||
|
*
|
||||||
* @param unitListStr 计量单位列表
|
* @param unitListStr 计量单位列表
|
||||||
*/
|
*/
|
||||||
@WebMethod(operationName = "syncUnit")
|
@WebMethod(operationName = "syncUnit")
|
||||||
String syncUnit(@WebParam(name = "unitList") Spring unitListStr);
|
@WebResult
|
||||||
|
String syncUnit(@WebParam(name = "unitList") String unitListStr);
|
||||||
}
|
}
|
||||||
|
@ -9,29 +9,40 @@ import com.ktg.mes.md.service.IMdUnitMeasureService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.codehaus.jackson.JsonNode;
|
import org.codehaus.jackson.JsonNode;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.jws.WebService;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
@WebService(name = IMasterDataSyncService.SERVICE_NAME, targetNamespace = IMasterDataSyncService.TARGET_NAMESPACE, endpointInterface = "com.ktg.mes.md.service.IMasterDataSyncService")
|
||||||
public class MasterDataSyncServiceImpl implements IMasterDataSyncService {
|
public class MasterDataSyncServiceImpl implements IMasterDataSyncService {
|
||||||
private final ItemTypeServiceImpl itemTypeService;
|
private final ItemTypeServiceImpl itemTypeService;
|
||||||
private final IMdItemService mdItemService;
|
private final IMdItemService mdItemService;
|
||||||
private final IMdUnitMeasureService mdUnitMeasureService;
|
private final IMdUnitMeasureService mdUnitMeasureService;
|
||||||
|
|
||||||
|
// 无参构造函数(供 CXF 使用)
|
||||||
|
public MasterDataSyncServiceImpl() {
|
||||||
|
this.itemTypeService = null;
|
||||||
|
this.mdItemService = null;
|
||||||
|
this.mdUnitMeasureService = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步物料数据
|
* 同步物料数据
|
||||||
|
*
|
||||||
* @param materialListStr 物料列表
|
* @param materialListStr 物料列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String syncMaterial(Spring materialListStr) {
|
public String syncMaterial(String materialListStr) {
|
||||||
// 使用 ObjectMapper 来处理 JSON
|
// 使用 ObjectMapper 来处理 JSON
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 解析传入的 JSON 字符串
|
// 解析传入的 JSON 字符串
|
||||||
String jsonList = objectMapper.readTree(materialListStr.toString()).get("LIST").asText();
|
String jsonList = objectMapper.readTree(materialListStr).get("LIST").asText();
|
||||||
JsonNode jsonNode = objectMapper.readTree(jsonList);
|
JsonNode jsonNode = objectMapper.readTree(jsonList);
|
||||||
|
|
||||||
for (JsonNode node : jsonNode) {
|
for (JsonNode node : jsonNode) {
|
||||||
@ -77,16 +88,17 @@ public class MasterDataSyncServiceImpl implements IMasterDataSyncService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步物料分类数据
|
* 同步物料分类数据
|
||||||
|
*
|
||||||
* @param materialCategoryListStr 物料分类列表
|
* @param materialCategoryListStr 物料分类列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String syncMaterialCategory(Spring materialCategoryListStr) {
|
public String syncMaterialCategory(String materialCategoryListStr) {
|
||||||
// 使用 ObjectMapper 来处理 JSON
|
// 使用 ObjectMapper 来处理 JSON
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 解析传入的 JSON 字符串
|
// 解析传入的 JSON 字符串
|
||||||
String jsonList = objectMapper.readTree(materialCategoryListStr.toString()).get("LIST").asText();
|
String jsonList = objectMapper.readTree(materialCategoryListStr).get("LIST").asText();
|
||||||
JsonNode jsonNode = objectMapper.readTree(jsonList);
|
JsonNode jsonNode = objectMapper.readTree(jsonList);
|
||||||
|
|
||||||
for (JsonNode node : jsonNode) {
|
for (JsonNode node : jsonNode) {
|
||||||
@ -144,16 +156,17 @@ public class MasterDataSyncServiceImpl implements IMasterDataSyncService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步计量单位数据
|
* 同步计量单位数据
|
||||||
|
*
|
||||||
* @param unitListStr 计量单位列表
|
* @param unitListStr 计量单位列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String syncUnit(Spring unitListStr) {
|
public String syncUnit(String unitListStr) {
|
||||||
// 使用 ObjectMapper 来处理 JSON
|
// 使用 ObjectMapper 来处理 JSON
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 解析传入的 JSON 字符串
|
// 解析传入的 JSON 字符串
|
||||||
String jsonList = objectMapper.readTree(unitListStr.toString()).get("LIST").asText();
|
String jsonList = objectMapper.readTree(unitListStr).get("LIST").asText();
|
||||||
JsonNode jsonNode = objectMapper.readTree(jsonList);
|
JsonNode jsonNode = objectMapper.readTree(jsonList);
|
||||||
|
|
||||||
for (JsonNode node : jsonNode) {
|
for (JsonNode node : jsonNode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user