From ef88d6829efedd632268fcab3c7f2790fd47fbc5 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Tue, 17 Dec 2024 10:30:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Ewebservice=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=AD=A5=E4=B8=BB=E6=95=B0=E6=8D=AE=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ktg-admin/pom.xml | 21 +++ .../md/service/IMasterDataSyncService.java | 30 +++ .../impl/MasterDataSyncServiceImpl.java | 177 ++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 ktg-mes/src/main/java/com/ktg/mes/md/service/IMasterDataSyncService.java create mode 100644 ktg-mes/src/main/java/com/ktg/mes/md/service/impl/MasterDataSyncServiceImpl.java diff --git a/ktg-admin/pom.xml b/ktg-admin/pom.xml index 246b229..93677f9 100644 --- a/ktg-admin/pom.xml +++ b/ktg-admin/pom.xml @@ -124,6 +124,27 @@ jtds 1.3.1 + + + org.springframework.boot + spring-boot-starter-web-services + + + + org.springframework + spring-oxm + + + + org.apache.cxf + cxf-spring-boot-starter-jaxws + 4.0.3 + + + jakarta.jws + jakarta.jws-api + 2.1.0 + diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/service/IMasterDataSyncService.java b/ktg-mes/src/main/java/com/ktg/mes/md/service/IMasterDataSyncService.java new file mode 100644 index 0000000..6cb6cd1 --- /dev/null +++ b/ktg-mes/src/main/java/com/ktg/mes/md/service/IMasterDataSyncService.java @@ -0,0 +1,30 @@ +package com.ktg.mes.md.service; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.swing.*; + +@WebService(name = "masterDataSyncService", targetNamespace = "http://server.spring.zhang.pers/") +public interface IMasterDataSyncService { + /** + * 同步物料数据 + * @param materialListStr 物料列表 + */ + @WebMethod(operationName = "syncMaterial") + String syncMaterial(@WebParam(name = "materialList") Spring materialListStr); + + /** + * 同步物料分类数据 + * @param materialCategoryListStr 物料分类列表 + */ + @WebMethod(operationName = "syncMaterialCategory") + String syncMaterialCategory(@WebParam(name = "materialCategoryList") Spring materialCategoryListStr); + + /** + * 同步计量单位数据 + * @param unitListStr 计量单位列表 + */ + @WebMethod(operationName = "syncUnit") + String syncUnit(@WebParam(name = "unitList") Spring unitListStr); +} diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/MasterDataSyncServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/MasterDataSyncServiceImpl.java new file mode 100644 index 0000000..ef3ad70 --- /dev/null +++ b/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/MasterDataSyncServiceImpl.java @@ -0,0 +1,177 @@ +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 javax.swing.*; +import java.util.List; +import java.util.Objects; + +@RequiredArgsConstructor +public class MasterDataSyncServiceImpl implements IMasterDataSyncService { + private final ItemTypeServiceImpl itemTypeService; + private final IMdItemService mdItemService; + private final IMdUnitMeasureService mdUnitMeasureService; + + /** + * 同步物料数据 + * @param materialListStr 物料列表 + */ + @Override + public String syncMaterial(Spring materialListStr) { + // 使用 ObjectMapper 来处理 JSON + ObjectMapper objectMapper = new ObjectMapper(); + + try { + // 解析传入的 JSON 字符串 + String jsonList = objectMapper.readTree(materialListStr.toString()).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(Spring materialCategoryListStr) { + // 使用 ObjectMapper 来处理 JSON + ObjectMapper objectMapper = new ObjectMapper(); + + try { + // 解析传入的 JSON 字符串 + String jsonList = objectMapper.readTree(materialCategoryListStr.toString()).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 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(Spring unitListStr) { + // 使用 ObjectMapper 来处理 JSON + ObjectMapper objectMapper = new ObjectMapper(); + + try { + // 解析传入的 JSON 字符串 + String jsonList = objectMapper.readTree(unitListStr.toString()).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"; // 返回成功标识 + } + + +}