From ed80b11007de69873433054e4df329ca0083766a Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Tue, 18 Nov 2025 10:00:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(wms):=20=E9=87=8D=E6=9E=84=E7=89=A9?= =?UTF-8?q?=E6=96=99=E5=8D=B7=E6=9C=8D=E5=8A=A1=E4=B8=AD=E7=9A=84VO?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提取重复代码到独立方法 setSubMaterialVo - 根据 itemType 动态设置原材料或产品信息 - 避免在多个地方重复设置相同的字段值 - 简化主逻辑,提高代码可读性和维护性 --- .../impl/WmsMaterialCoilServiceImpl.java | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java index 1c63e55e..81ccd7be 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java @@ -1480,14 +1480,8 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { vo.setCoilCount(map.get("coil_count") != null ? Long.valueOf(map.get("coil_count").toString()) : 0L); vo.setTotalGrossWeight(map.get("total_gross_weight") != null ? new BigDecimal(map.get("total_gross_weight").toString()) : BigDecimal.ZERO); vo.setTotalNetWeight(map.get("total_net_weight") != null ? new BigDecimal(map.get("total_net_weight").toString()) : BigDecimal.ZERO); - vo.setItemName(map.get("itemName") != null ? map.get("itemName").toString() : null); - vo.setItemCode(map.get("itemCode") != null ? map.get("itemCode").toString() : null); - vo.setSpecification(map.get("specification") != null ? map.get("specification").toString() : null); - vo.setMaterial(map.get("material") != null ? map.get("material").toString() : null); - vo.setSurfaceTreatmentDesc(map.get("surfaceTreatmentDesc") != null ? map.get("surfaceTreatmentDesc").toString() : null); - vo.setZincLayer(map.get("zincLayer") != null ? map.get("zincLayer").toString() : null); - vo.setManufacturer(map.get("manufacturer") != null ? map.get("manufacturer").toString() : null); - voList.add(vo); + + setSubMaterialVo(vo, map, voList); } return voList; } @@ -1519,18 +1513,39 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { vo.setCoilCount(map.get("coil_count") != null ? Long.valueOf(map.get("coil_count").toString()) : 0L); vo.setTotalGrossWeight(map.get("total_gross_weight") != null ? new BigDecimal(map.get("total_gross_weight").toString()) : BigDecimal.ZERO); vo.setTotalNetWeight(map.get("total_net_weight") != null ? new BigDecimal(map.get("total_net_weight").toString()) : BigDecimal.ZERO); - vo.setItemName(map.get("itemName") != null ? map.get("itemName").toString() : null); - vo.setItemCode(map.get("itemCode") != null ? map.get("itemCode").toString() : null); - vo.setSpecification(map.get("specification") != null ? map.get("specification").toString() : null); - vo.setMaterial(map.get("material") != null ? map.get("material").toString() : null); - vo.setSurfaceTreatmentDesc(map.get("surfaceTreatmentDesc") != null ? map.get("surfaceTreatmentDesc").toString() : null); - vo.setZincLayer(map.get("zincLayer") != null ? map.get("zincLayer").toString() : null); - vo.setManufacturer(map.get("manufacturer") != null ? map.get("manufacturer").toString() : null); - voList.add(vo); + setSubMaterialVo(vo, map, voList); } return voList; } - + private void setSubMaterialVo(WmsMaterialCoilVo vo, Map map, List voList) { + String itemType = vo.getItemType(); + if (itemType == null) { + voList.add(vo); + return; + } + if ("raw_material".equals(itemType)) { + WmsRawMaterialVo rawMaterial = new WmsRawMaterialVo(); + rawMaterial.setRawMaterialName(map.get("itemName") != null ? map.get("itemName").toString() : null); + rawMaterial.setRawMaterialCode(map.get("itemCode") != null ? map.get("itemCode").toString() : null); + rawMaterial.setSpecification(map.get("specification") != null ? map.get("specification").toString() : null); + rawMaterial.setMaterial(map.get("material") != null ? map.get("material").toString() : null); + rawMaterial.setSurfaceTreatmentDesc(map.get("surfaceTreatmentDesc") != null ? map.get("surfaceTreatmentDesc").toString() : null); + rawMaterial.setZincLayer(map.get("zincLayer") != null ? map.get("zincLayer").toString() : null); + rawMaterial.setManufacturer(map.get("manufacturer") != null ? map.get("manufacturer").toString() : null); + vo.setRawMaterial(rawMaterial); + } else if ("product".equals(itemType)) { + WmsProductVo product = new WmsProductVo(); + product.setProductName(map.get("itemName") != null ? map.get("itemName").toString() : null); + product.setProductCode(map.get("itemCode") != null ? map.get("itemCode").toString() : null); + product.setSpecification(map.get("specification") != null ? map.get("specification").toString() : null); + product.setMaterial(map.get("material") != null ? map.get("material").toString() : null); + product.setSurfaceTreatmentDesc(map.get("surfaceTreatmentDesc") != null ? map.get("surfaceTreatmentDesc").toString() : null); + product.setZincLayer(map.get("zincLayer") != null ? map.get("zincLayer").toString() : null); + product.setManufacturer(map.get("manufacturer") != null ? map.get("manufacturer").toString() : null); + vo.setProduct(product); + } + voList.add(vo); + } @Override public List getDistributionByActualItemType(String itemType, Long itemId) { List> mapList = baseMapper.getDistributionByActualItemType(itemType, itemId);