feat: 同步主数据管理平台数据

This commit is contained in:
Kelvin 2024-12-19 16:42:57 +08:00
parent 4f77b1921d
commit 93be09a4de
4 changed files with 280 additions and 0 deletions

View File

@ -53,10 +53,25 @@
<artifactId>swagger-models</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
<dependency>
<groupId>com.ktg</groupId>
<artifactId>ktg-generator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--CXF webservices-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.4.4</version>
</dependency>
</dependencies>
</project>

View File

@ -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;
}
}

View File

@ -0,0 +1,40 @@
package com.ktg.mes.md.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService(name = IMasterDataSyncService.SERVICE_NAME, targetNamespace = IMasterDataSyncService.TARGET_NAMESPACE)
public interface IMasterDataSyncService {
String SERVICE_NAME = "MasterDataSyncService";
String TARGET_NAMESPACE = "http://server.spring.zhang.pers/";
/**
* 同步物料数据
*
* @param materialListStr 物料列表
*/
@WebMethod(operationName = "syncMaterial")
@WebResult
String syncMaterial(@WebParam(name = "materialListStr") String materialListStr);
/**
* 同步物料分类数据
*
* @param materialCategoryListStr 物料分类列表
*/
@WebMethod(operationName = "syncMaterialCategory")
@WebResult
String syncMaterialCategory(@WebParam(name = "materialCategoryList") String materialCategoryListStr);
/**
* 同步计量单位数据
*
* @param unitListStr 计量单位列表
*/
@WebMethod(operationName = "syncUnit")
@WebResult
String syncUnit(@WebParam(name = "unitList") String unitListStr);
}

View File

@ -0,0 +1,189 @@
package com.ktg.mes.md.service.impl;
import com.ktg.common.core.domain.entity.ItemType;
import com.ktg.mes.md.domain.MdItem;
import com.ktg.mes.md.domain.MdUnitMeasure;
import com.ktg.mes.md.service.IMasterDataSyncService;
import com.ktg.mes.md.service.IMdItemService;
import com.ktg.mes.md.service.IMdUnitMeasureService;
import lombok.RequiredArgsConstructor;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Service;
import javax.jws.WebService;
import java.util.List;
@RequiredArgsConstructor
@Service
@WebService(name = IMasterDataSyncService.SERVICE_NAME, targetNamespace = IMasterDataSyncService.TARGET_NAMESPACE, endpointInterface = "com.ktg.mes.md.service.IMasterDataSyncService")
public class MasterDataSyncServiceImpl implements IMasterDataSyncService {
private final ItemTypeServiceImpl itemTypeService;
private final IMdItemService mdItemService;
private final IMdUnitMeasureService mdUnitMeasureService;
// 无参构造函数 CXF 使用
public MasterDataSyncServiceImpl() {
this.itemTypeService = null;
this.mdItemService = null;
this.mdUnitMeasureService = null;
}
/**
* 同步物料数据
*
* @param materialListStr 物料列表
*/
@Override
public String syncMaterial(String materialListStr) {
// 使用 ObjectMapper 来处理 JSON
ObjectMapper objectMapper = new ObjectMapper();
try {
// 解析传入的 JSON 字符串
String jsonList = objectMapper.readTree(materialListStr).get("LIST").asText();
JsonNode jsonNode = objectMapper.readTree(jsonList);
for (JsonNode node : jsonNode) {
JsonNode jsonNode1 = null;
// 通用工具工装
if (!node.get("T_TYGJGZ").asText().isEmpty()) {
jsonNode1 = objectMapper.readTree(node.get("T_TYGJGZ").asText());
// 专用工具工装
} else if (!node.get("T_ZYGJGZ").asText().isEmpty()) {
jsonNode1 = objectMapper.readTree(node.get("T_ZYGJGZ").asText());
}
if (jsonNode1 != null) {
MdItem mdItem = new MdItem();
mdItem.setItemName(jsonNode1.get("MC").asText());
mdItem.setItemCode(jsonNode1.get("WLBM").asText());
// 查询并设置计量单位数据
MdUnitMeasure unit = mdUnitMeasureService.selectMdUnitByCode(jsonNode1.get("UNIT").asText());
mdItem.setUnitName(unit.getMeasureName());
mdItem.setUnitOfMeasure(unit.getMeasureName());
// 四级分类数据
String categoryName = jsonNode1.get("SIJFL").asText();
if (categoryName.isEmpty()) {
// 为空则使用三级分类数据
categoryName = jsonNode1.get("SJFL").asText();
}
ItemType itemType = itemTypeService.selectItemTypeByName(categoryName);
mdItem.setItemOrProduct(itemType.getItemOrProduct());
mdItem.setItemTypeId(itemType.getItemTypeId());
mdItem.setItemTypeName(itemType.getItemTypeName());
mdItemService.insertMdItem(mdItem);
}
}
} catch (Exception e) {
e.printStackTrace();
return "同步失败,原因:" + e.getMessage();
}
return "1"; // 返回成功标识
}
/**
* 同步物料分类数据
*
* @param materialCategoryListStr 物料分类列表
*/
@Override
public String syncMaterialCategory(String materialCategoryListStr) {
// 使用 ObjectMapper 来处理 JSON
ObjectMapper objectMapper = new ObjectMapper();
try {
// 解析传入的 JSON 字符串
String jsonList = objectMapper.readTree(materialCategoryListStr).get("LIST").asText();
JsonNode jsonNode = objectMapper.readTree(jsonList);
for (JsonNode node : jsonNode) {
ItemType itemType = new ItemType();
itemType.setItemTypeName(node.get("NAME").asText());
itemType.setItemTypeCode(node.get("CODE").asText());
// 判断是否有父级分类
String parentCode = node.get("PCODE").asText();
if (!parentCode.isEmpty()) {
ItemType itemTypeQuery = new ItemType();
itemTypeQuery.setItemTypeCode(parentCode);
// 查询父级数据
List<ItemType> parentItemTypeList = itemTypeService.selectItemTypeList(itemTypeQuery);
if (!parentItemTypeList.isEmpty()) {
ItemType parentItemType = parentItemTypeList.get(0);
itemType.setParentTypeId(parentItemType.getItemTypeId());
// 提取父级分类ID
Long parentId = parentItemType.getParentTypeId();
// 循环直至查出最顶层分类
while (parentId != null && parentId != 0) {
parentItemType = itemTypeService.selectItemTypeById(parentId);
if (parentItemType != null) {
// 更新父级 ID
parentId = parentItemType.getParentTypeId();
// 判断分类名称设置对应的物料类型
if ("专用刀具".equals(parentItemType.getItemTypeName()) || "刀具".equals(parentItemType.getItemTypeName())) {
itemType.setItemOrProduct("BLAND");
break;
} else if (parentId == 0) {
itemType.setItemOrProduct("ITEM");
break;
}
} else {
break;
}
}
}
}
// 插入数据
itemTypeService.insertItemType(itemType);
}
} catch (Exception e) {
e.printStackTrace();
return "同步失败,原因:" + e.getMessage();
}
return "1"; // 返回成功标识
}
/**
* 同步计量单位数据
*
* @param unitListStr 计量单位列表
*/
@Override
public String syncUnit(String unitListStr) {
// 使用 ObjectMapper 来处理 JSON
ObjectMapper objectMapper = new ObjectMapper();
try {
// 解析传入的 JSON 字符串
String jsonList = objectMapper.readTree(unitListStr).get("LIST").asText();
JsonNode jsonNode = objectMapper.readTree(jsonList);
for (JsonNode node : jsonNode) {
JsonNode jsonNode1 = objectMapper.readTree(node.get("DIC_D_UNIT").asText());
if (jsonNode1 != null) {
MdUnitMeasure mdUnitMeasure = new MdUnitMeasure();
mdUnitMeasure.setMeasureCode(jsonNode1.get("CODE").asText());
mdUnitMeasure.setMeasureName(jsonNode1.get("NAME").asText());
mdUnitMeasureService.insertMdUnitMeasure(mdUnitMeasure);
}
}
} catch (Exception e) {
e.printStackTrace();
return "同步失败,原因:" + e.getMessage();
}
return "1"; // 返回成功标识
}
}