From ccfa5a9f4b5687a9c33fd43fb3a2fbabe0cd9a47 Mon Sep 17 00:00:00 2001 From: zhouz <> Date: Fri, 11 Sep 2026 11:36:45 +0800 Subject: [PATCH] feat: expose ERP master data synchronization --- .../controller/erp/ErpInboundController.java | 34 +++ .../controller/erp/vo/ErpBoxSyncReqVO.java | 40 +++ .../erp/vo/ErpCoreTubeSyncReqVO.java | 57 ++++ .../erp/vo/ErpCustomerSyncReqVO.java | 33 ++ .../erp/vo/ErpMaterialSyncReqVO.java | 42 +++ .../wms/dal/dataobject/boxtype/BoxTypeDO.java | 3 + .../coretubetype/CoreTubeTypeDO.java | 38 +++ .../dal/dataobject/customer/CustomerDO.java | 27 ++ .../wms/dal/mysql/boxtype/BoxTypeMapper.java | 6 + .../coretubetype/CoreTubeTypeMapper.java | 17 ++ .../dal/mysql/customer/CustomerMapper.java | 17 ++ .../service/erp/ErpMasterDataSyncService.java | 22 ++ .../erp/ErpMasterDataSyncServiceImpl.java | 119 ++++++++ .../mapper/boxtype/BoxTypeMapper.xml | 22 +- .../coretubetype/CoreTubeTypeMapper.xml | 25 ++ .../mapper/customer/CustomerMapper.xml | 21 ++ .../erp/ErpMasterDataValidationTest.java | 105 +++++++ .../erp/ErpMasterDataSyncLocalSpringTest.java | 287 ++++++++++++++++++ sql/mysql/erp_wms_master_data.sql | 31 ++ 19 files changed, 945 insertions(+), 1 deletion(-) create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpBoxSyncReqVO.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCoreTubeSyncReqVO.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCustomerSyncReqVO.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpMaterialSyncReqVO.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/coretubetype/CoreTubeTypeDO.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/customer/CustomerDO.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/coretubetype/CoreTubeTypeMapper.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/customer/CustomerMapper.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncService.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncServiceImpl.java create mode 100644 nl-module-wms/nl-module-wms-server/src/main/resources/mapper/coretubetype/CoreTubeTypeMapper.xml create mode 100644 nl-module-wms/nl-module-wms-server/src/main/resources/mapper/customer/CustomerMapper.xml create mode 100644 nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/controller/erp/ErpMasterDataValidationTest.java create mode 100644 nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncLocalSpringTest.java diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/ErpInboundController.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/ErpInboundController.java index 09ae3926..f01291e3 100644 --- a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/ErpInboundController.java +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/ErpInboundController.java @@ -2,7 +2,12 @@ package cn.code.nl.module.wms.controller.erp; import cn.code.nl.framework.tenant.core.aop.TenantIgnore; import cn.code.nl.module.wms.controller.erp.vo.ErpFinishedBoxOutboundReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpBoxSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCoreTubeSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCustomerSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpMaterialSyncReqVO; import cn.code.nl.module.wms.service.erp.ErpInboundService; +import cn.code.nl.module.wms.service.erp.ErpMasterDataSyncService; import jakarta.annotation.Resource; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.PostMapping; @@ -18,10 +23,39 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/admin-api/wms/erp") public class ErpInboundController { @Resource private ErpInboundService erpInboundService; + @Resource private ErpMasterDataSyncService erpMasterDataSyncService; /** 接收成品木箱出库申请。 */ @PostMapping("/finished-box/outbound") public ErpResult outboundFinishedBox(@Valid @RequestBody ErpFinishedBoxOutboundReqVO reqVO) { return ErpResult.success(erpInboundService.outboundFinishedBox(reqVO)); } + + /** 接收ERP物料基础信息。 */ + @PostMapping("/master-data/material/push") + public ErpResult syncMaterial(@Valid @RequestBody ErpMaterialSyncReqVO reqVO) { + erpMasterDataSyncService.syncMaterial(reqVO); + return ErpResult.success(Boolean.TRUE); + } + + /** 接收ERP木箱基础信息。 */ + @PostMapping("/master-data/box/push") + public ErpResult syncBox(@Valid @RequestBody ErpBoxSyncReqVO reqVO) { + erpMasterDataSyncService.syncBox(reqVO); + return ErpResult.success(Boolean.TRUE); + } + + /** 接收ERP管芯基础信息。 */ + @PostMapping("/master-data/core-tube/push") + public ErpResult syncCoreTube(@Valid @RequestBody ErpCoreTubeSyncReqVO reqVO) { + erpMasterDataSyncService.syncCoreTube(reqVO); + return ErpResult.success(Boolean.TRUE); + } + + /** 接收ERP客户基础信息。 */ + @PostMapping("/master-data/customer/push") + public ErpResult syncCustomer(@Valid @RequestBody ErpCustomerSyncReqVO reqVO) { + erpMasterDataSyncService.syncCustomer(reqVO); + return ErpResult.success(Boolean.TRUE); + } } diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpBoxSyncReqVO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpBoxSyncReqVO.java new file mode 100644 index 00000000..17a4cee8 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpBoxSyncReqVO.java @@ -0,0 +1,40 @@ +package cn.code.nl.module.wms.controller.erp.vo; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.Size; +import lombok.Data; + +/** ERP木箱基础信息同步请求。 */ +@Data +public class ErpBoxSyncReqVO { + + /** 木箱类型。 */ + @NotBlank(message = "木箱类型不能为空") + @Size(max = 20, message = "木箱类型长度不能超过20") + private String boxType; + + /** 木箱长度。 */ + @NotNull(message = "木箱长度不能为空") + @Positive(message = "木箱长度必须大于0") + private Integer boxLength; + + /** 木箱宽度。 */ + @NotNull(message = "木箱宽度不能为空") + @Positive(message = "木箱宽度必须大于0") + private Integer boxWidth; + + /** 木箱高度。 */ + @NotNull(message = "木箱高度不能为空") + @Positive(message = "木箱高度必须大于0") + private Integer boxHeight; + + /** 是否删除:0正常、1删除。 */ + @NotNull(message = "是否删除不能为空") + @Min(value = 0, message = "是否删除只能为0或1") + @Max(value = 1, message = "是否删除只能为0或1") + private Integer deleted; +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCoreTubeSyncReqVO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCoreTubeSyncReqVO.java new file mode 100644 index 00000000..c9d6d696 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCoreTubeSyncReqVO.java @@ -0,0 +1,57 @@ +package cn.code.nl.module.wms.controller.erp.vo; + +import jakarta.validation.constraints.Digits; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.PositiveOrZero; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.math.BigDecimal; + +/** ERP管芯基础信息同步请求。 */ +@Data +public class ErpCoreTubeSyncReqVO { + + /** 管芯类型。 */ + @NotBlank(message = "管芯类型不能为空") + @Size(max = 64, message = "管芯类型长度不能超过64") + private String coreTubeType; + + /** 管芯长度。 */ + @NotNull(message = "管芯长度不能为空") + @Positive(message = "管芯长度必须大于0") + @Digits(integer = 14, fraction = 6, message = "管芯长度最多14位整数和6位小数") + private BigDecimal coreTubeLength; + + /** 阶梯长度。 */ + @PositiveOrZero(message = "阶梯长度不能小于0") + @Digits(integer = 14, fraction = 6, message = "阶梯长度最多14位整数和6位小数") + private BigDecimal stepLength; + + /** 管芯壁厚。 */ + @NotNull(message = "管芯壁厚不能为空") + @Positive(message = "管芯壁厚必须大于0") + @Digits(integer = 14, fraction = 6, message = "管芯壁厚最多14位整数和6位小数") + private BigDecimal coreTubeWallThickness; + + /** 阶梯壁厚。 */ + @PositiveOrZero(message = "阶梯壁厚不能小于0") + @Digits(integer = 14, fraction = 6, message = "阶梯壁厚最多14位整数和6位小数") + private BigDecimal stepWallThickness; + + /** 尺寸:3或6。 */ + @NotBlank(message = "尺寸不能为空") + @Pattern(regexp = "^(3|6)$", message = "尺寸只能为3或6") + private String size; + + /** 是否删除:0正常、1删除。 */ + @NotNull(message = "是否删除不能为空") + @Min(value = 0, message = "是否删除只能为0或1") + @Max(value = 1, message = "是否删除只能为0或1") + private Integer deleted; +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCustomerSyncReqVO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCustomerSyncReqVO.java new file mode 100644 index 00000000..718f81b7 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpCustomerSyncReqVO.java @@ -0,0 +1,33 @@ +package cn.code.nl.module.wms.controller.erp.vo; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +/** ERP客户基础信息同步请求。 */ +@Data +public class ErpCustomerSyncReqVO { + + /** 客户编码。 */ + @NotBlank(message = "客户编码不能为空") + @Size(max = 64, message = "客户编码长度不能超过64") + private String customerCode; + + /** 客户名称。 */ + @NotBlank(message = "客户名称不能为空") + @Size(max = 255, message = "客户名称长度不能超过255") + private String customerName; + + /** 客户地址。 */ + @Size(max = 500, message = "客户地址长度不能超过500") + private String address; + + /** 是否删除:0正常、1删除。 */ + @NotNull(message = "是否删除不能为空") + @Min(value = 0, message = "是否删除只能为0或1") + @Max(value = 1, message = "是否删除只能为0或1") + private Integer deleted; +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpMaterialSyncReqVO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpMaterialSyncReqVO.java new file mode 100644 index 00000000..e8480734 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/controller/erp/vo/ErpMaterialSyncReqVO.java @@ -0,0 +1,42 @@ +package cn.code.nl.module.wms.controller.erp.vo; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +/** ERP物料基础信息同步请求。 */ +@Data +public class ErpMaterialSyncReqVO { + + /** 物料类型。 */ + @NotBlank(message = "物料类型不能为空") + @Size(max = 64, message = "物料类型长度不能超过64") + private String materialType; + + /** 物料编码。 */ + @NotBlank(message = "物料编码不能为空") + @Size(max = 100, message = "物料编码长度不能超过100") + private String materialCode; + + /** 物料名称。 */ + @NotBlank(message = "物料名称不能为空") + @Size(max = 100, message = "物料名称长度不能超过100") + private String materialName; + + /** 物料描述。 */ + @Size(max = 255, message = "物料描述长度不能超过255") + private String materialDescription; + + /** 规格型号。 */ + @Size(max = 255, message = "规格型号长度不能超过255") + private String specificationModel; + + /** 是否删除:0正常、1删除。 */ + @NotNull(message = "是否删除不能为空") + @Min(value = 0, message = "是否删除只能为0或1") + @Max(value = 1, message = "是否删除只能为0或1") + private Integer deleted; +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/boxtype/BoxTypeDO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/boxtype/BoxTypeDO.java index 446d1f8d..1c43c1b2 100644 --- a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/boxtype/BoxTypeDO.java +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/boxtype/BoxTypeDO.java @@ -2,6 +2,7 @@ package cn.code.nl.module.wms.dal.dataobject.boxtype; import cn.code.nl.framework.tenant.core.aop.TenantIgnore; import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -31,4 +32,6 @@ public class BoxTypeDO { private Integer boxWidth; private Integer boxHigh; private Integer maxNum; + @TableLogic + private Boolean deleted; } diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/coretubetype/CoreTubeTypeDO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/coretubetype/CoreTubeTypeDO.java new file mode 100644 index 00000000..4cc64d04 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/coretubetype/CoreTubeTypeDO.java @@ -0,0 +1,38 @@ +package cn.code.nl.module.wms.dal.dataobject.coretubetype; + +import cn.code.nl.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; + +/** 管芯类型基础信息数据对象。 */ +@TableName("wms_core_tube_type") +@Data +@EqualsAndHashCode(callSuper = true) +public class CoreTubeTypeDO extends BaseDO { + + /** 主键。 */ + @TableId + private Long id; + + /** 管芯类型。 */ + private String coreTubeType; + + /** 管芯长度。 */ + private BigDecimal coreTubeLength; + + /** 阶梯长度。 */ + private BigDecimal stepLength; + + /** 管芯壁厚。 */ + private BigDecimal coreTubeWallThickness; + + /** 阶梯壁厚。 */ + private BigDecimal stepWallThickness; + + /** 尺寸:3或6。 */ + private String size; +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/customer/CustomerDO.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/customer/CustomerDO.java new file mode 100644 index 00000000..67d11058 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/dataobject/customer/CustomerDO.java @@ -0,0 +1,27 @@ +package cn.code.nl.module.wms.dal.dataobject.customer; + +import cn.code.nl.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** 客户基础信息数据对象。 */ +@TableName("wms_customer") +@Data +@EqualsAndHashCode(callSuper = true) +public class CustomerDO extends BaseDO { + + /** 主键。 */ + @TableId + private Long id; + + /** 客户编码。 */ + private String customerCode; + + /** 客户名称。 */ + private String customerName; + + /** 客户地址。 */ + private String address; +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/boxtype/BoxTypeMapper.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/boxtype/BoxTypeMapper.java index 545cf8ac..a8c6b342 100644 --- a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/boxtype/BoxTypeMapper.java +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/boxtype/BoxTypeMapper.java @@ -18,6 +18,12 @@ import java.util.List; @Mapper public interface BoxTypeMapper extends BaseMapperX { + /** 根据木箱类型查询,包含已逻辑删除的数据。 */ + BoxTypeDO selectByBoxTypeIncludingDeleted(@Param("boxType") String boxType); + + /** 更新ERP负责的木箱字段和逻辑删除状态。 */ + int updateErpBox(BoxTypeDO boxType); + /** * 分页查询木箱类型。 */ diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/coretubetype/CoreTubeTypeMapper.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/coretubetype/CoreTubeTypeMapper.java new file mode 100644 index 00000000..adb1ddd4 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/coretubetype/CoreTubeTypeMapper.java @@ -0,0 +1,17 @@ +package cn.code.nl.module.wms.dal.mysql.coretubetype; + +import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX; +import cn.code.nl.module.wms.dal.dataobject.coretubetype.CoreTubeTypeDO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** 管芯类型基础信息Mapper。 */ +@Mapper +public interface CoreTubeTypeMapper extends BaseMapperX { + + /** 按管芯类型查询,包含已逻辑删除的数据。 */ + CoreTubeTypeDO selectByCoreTubeTypeIncludingDeleted(@Param("coreTubeType") String coreTubeType); + + /** 更新ERP负责的管芯类型字段和逻辑删除状态。 */ + int updateErpCoreTube(CoreTubeTypeDO coreTubeType); +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/customer/CustomerMapper.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/customer/CustomerMapper.java new file mode 100644 index 00000000..77c39372 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/dal/mysql/customer/CustomerMapper.java @@ -0,0 +1,17 @@ +package cn.code.nl.module.wms.dal.mysql.customer; + +import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX; +import cn.code.nl.module.wms.dal.dataobject.customer.CustomerDO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** 客户基础信息Mapper。 */ +@Mapper +public interface CustomerMapper extends BaseMapperX { + + /** 按客户编码查询,包含已逻辑删除的数据。 */ + CustomerDO selectByCustomerCodeIncludingDeleted(@Param("customerCode") String customerCode); + + /** 更新ERP负责的客户字段和逻辑删除状态。 */ + int updateErpCustomer(CustomerDO customer); +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncService.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncService.java new file mode 100644 index 00000000..43d0e8f7 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncService.java @@ -0,0 +1,22 @@ +package cn.code.nl.module.wms.service.erp; + +import cn.code.nl.module.wms.controller.erp.vo.ErpBoxSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCoreTubeSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCustomerSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpMaterialSyncReqVO; + +/** ERP基础信息同步服务。 */ +public interface ErpMasterDataSyncService { + + /** 同步物料基础信息。 */ + void syncMaterial(ErpMaterialSyncReqVO reqVO); + + /** 同步木箱基础信息。 */ + void syncBox(ErpBoxSyncReqVO reqVO); + + /** 同步管芯基础信息。 */ + void syncCoreTube(ErpCoreTubeSyncReqVO reqVO); + + /** 同步客户基础信息。 */ + void syncCustomer(ErpCustomerSyncReqVO reqVO); +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncServiceImpl.java b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncServiceImpl.java new file mode 100644 index 00000000..8edd2a47 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncServiceImpl.java @@ -0,0 +1,119 @@ +package cn.code.nl.module.wms.service.erp; + +import cn.code.nl.framework.common.exception.ServiceException; +import cn.code.nl.framework.common.pojo.CommonResult; +import cn.code.nl.module.base.api.materialbase.MaterialBaseApi; +import cn.code.nl.module.base.api.materialbase.dto.MaterialBaseSyncReq; +import cn.code.nl.module.wms.controller.erp.vo.ErpBoxSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCoreTubeSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCustomerSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpMaterialSyncReqVO; +import cn.code.nl.module.wms.dal.dataobject.boxtype.BoxTypeDO; +import cn.code.nl.module.wms.dal.dataobject.coretubetype.CoreTubeTypeDO; +import cn.code.nl.module.wms.dal.dataobject.customer.CustomerDO; +import cn.code.nl.module.wms.dal.mysql.boxtype.BoxTypeMapper; +import cn.code.nl.module.wms.dal.mysql.coretubetype.CoreTubeTypeMapper; +import cn.code.nl.module.wms.dal.mysql.customer.CustomerMapper; +import cn.hutool.core.util.IdUtil; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** ERP基础信息同步服务实现。 */ +@Service +public class ErpMasterDataSyncServiceImpl implements ErpMasterDataSyncService { + + /** Base物料内部接口。 */ + @Resource + private MaterialBaseApi materialBaseApi; + + /** 木箱类型Mapper。 */ + @Resource + private BoxTypeMapper boxTypeMapper; + + /** 管芯类型Mapper。 */ + @Resource + private CoreTubeTypeMapper coreTubeTypeMapper; + + /** 客户Mapper。 */ + @Resource + private CustomerMapper customerMapper; + + /** 将ERP物料请求转发到Base模块。 */ + @Override + public void syncMaterial(ErpMaterialSyncReqVO reqVO) { + MaterialBaseSyncReq req = new MaterialBaseSyncReq(); + req.setMaterialType(reqVO.getMaterialType()); + req.setMaterialCode(reqVO.getMaterialCode()); + req.setMaterialName(reqVO.getMaterialName()); + req.setMaterialDescription(reqVO.getMaterialDescription()); + req.setSpecificationModel(reqVO.getSpecificationModel()); + req.setDeleted(reqVO.getDeleted()); + CommonResult result = materialBaseApi.syncMaterialBase(req); + if (result == null || !result.isSuccess()) { + throw new ServiceException(500, "同步物料基础信息失败"); + } + } + + /** 按木箱类型新增或更新ERP负责字段。 */ + @Override + @Transactional(rollbackFor = Exception.class) + public void syncBox(ErpBoxSyncReqVO reqVO) { + BoxTypeDO existing = boxTypeMapper.selectByBoxTypeIncludingDeleted(reqVO.getBoxType()); + BoxTypeDO boxType = new BoxTypeDO(); + boxType.setBoxType(reqVO.getBoxType()); + boxType.setBoxLength(reqVO.getBoxLength()); + boxType.setBoxWidth(reqVO.getBoxWidth()); + boxType.setBoxHigh(reqVO.getBoxHeight()); + boxType.setDeleted(reqVO.getDeleted() == 1); + if (existing == null) { + boxType.setId(IdUtil.getSnowflakeNextId()); + boxTypeMapper.insert(boxType); + return; + } + boxType.setId(existing.getId()); + boxTypeMapper.updateErpBox(boxType); + } + + /** 按管芯类型新增或更新管芯基础信息。 */ + @Override + @Transactional(rollbackFor = Exception.class) + public void syncCoreTube(ErpCoreTubeSyncReqVO reqVO) { + CoreTubeTypeDO existing = coreTubeTypeMapper + .selectByCoreTubeTypeIncludingDeleted(reqVO.getCoreTubeType()); + CoreTubeTypeDO coreTubeType = new CoreTubeTypeDO(); + coreTubeType.setCoreTubeType(reqVO.getCoreTubeType()); + coreTubeType.setCoreTubeLength(reqVO.getCoreTubeLength()); + coreTubeType.setStepLength(reqVO.getStepLength()); + coreTubeType.setCoreTubeWallThickness(reqVO.getCoreTubeWallThickness()); + coreTubeType.setStepWallThickness(reqVO.getStepWallThickness()); + coreTubeType.setSize(reqVO.getSize()); + coreTubeType.setDeleted(reqVO.getDeleted() == 1); + if (existing == null) { + coreTubeType.setId(IdUtil.getSnowflakeNextId()); + coreTubeTypeMapper.insert(coreTubeType); + return; + } + coreTubeType.setId(existing.getId()); + coreTubeTypeMapper.updateErpCoreTube(coreTubeType); + } + + /** 按客户编码新增或更新客户基础信息。 */ + @Override + @Transactional(rollbackFor = Exception.class) + public void syncCustomer(ErpCustomerSyncReqVO reqVO) { + CustomerDO existing = customerMapper.selectByCustomerCodeIncludingDeleted(reqVO.getCustomerCode()); + CustomerDO customer = new CustomerDO(); + customer.setCustomerCode(reqVO.getCustomerCode()); + customer.setCustomerName(reqVO.getCustomerName()); + customer.setAddress(reqVO.getAddress()); + customer.setDeleted(reqVO.getDeleted() == 1); + if (existing == null) { + customer.setId(IdUtil.getSnowflakeNextId()); + customerMapper.insert(customer); + return; + } + customer.setId(existing.getId()); + customerMapper.updateErpCustomer(customer); + } +} diff --git a/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/boxtype/BoxTypeMapper.xml b/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/boxtype/BoxTypeMapper.xml index 638efcaf..ac9e5a76 100644 --- a/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/boxtype/BoxTypeMapper.xml +++ b/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/boxtype/BoxTypeMapper.xml @@ -6,21 +6,39 @@ id, box_type, box_name, lash_num, lash_num_one, lash_num_two, need_lash_one, need_lash_two, expend_width, box_structure, - desiccant_num, box_length, box_width, box_high, max_num + desiccant_num, box_length, box_width, box_high, max_num, deleted + + + + UPDATE wms_box_type + SET box_length = #{boxLength}, + box_width = #{boxWidth}, + box_high = #{boxHigh}, + deleted = #{deleted} + WHERE box_type = #{boxType} + + @@ -55,6 +74,7 @@ #{id} + AND deleted = b'0' diff --git a/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/coretubetype/CoreTubeTypeMapper.xml b/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/coretubetype/CoreTubeTypeMapper.xml new file mode 100644 index 00000000..4c654a32 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/coretubetype/CoreTubeTypeMapper.xml @@ -0,0 +1,25 @@ + + + + + + + + UPDATE wms_core_tube_type + SET core_tube_length = #{coreTubeLength}, + step_length = #{stepLength}, + core_tube_wall_thickness = #{coreTubeWallThickness}, + step_wall_thickness = #{stepWallThickness}, + size = #{size}, + deleted = #{deleted} + WHERE core_tube_type = #{coreTubeType} + + + diff --git a/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/customer/CustomerMapper.xml b/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/customer/CustomerMapper.xml new file mode 100644 index 00000000..17b1b360 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/main/resources/mapper/customer/CustomerMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + UPDATE wms_customer + SET customer_name = #{customerName}, + address = #{address}, + deleted = #{deleted} + WHERE customer_code = #{customerCode} + + + diff --git a/nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/controller/erp/ErpMasterDataValidationTest.java b/nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/controller/erp/ErpMasterDataValidationTest.java new file mode 100644 index 00000000..51d5c390 --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/controller/erp/ErpMasterDataValidationTest.java @@ -0,0 +1,105 @@ +package cn.code.nl.module.wms.controller.erp; + +import cn.code.nl.module.wms.controller.erp.vo.ErpBoxSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCoreTubeSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCustomerSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpMaterialSyncReqVO; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** ERP基础信息请求参数校验测试。 */ +class ErpMasterDataValidationTest { + + /** Jakarta参数校验器。 */ + private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + + /** 删除标志只能为0或1。 */ + @Test + void shouldRejectInvalidDeletedFlag() { + ErpMaterialSyncReqVO reqVO = new ErpMaterialSyncReqVO(); + reqVO.setMaterialType("FINISHED"); + reqVO.setMaterialCode("MAT-001"); + reqVO.setMaterialName("成品卷"); + reqVO.setDeleted(2); + + assertFalse(validator.validate(reqVO).isEmpty()); + } + + /** 木箱长宽高必须为正数。 */ + @Test + void shouldRejectNonPositiveBoxDimension() { + ErpBoxSyncReqVO reqVO = new ErpBoxSyncReqVO(); + reqVO.setBoxType("BOX-A"); + reqVO.setBoxLength(0); + reqVO.setBoxWidth(1200); + reqVO.setBoxHeight(900); + reqVO.setDeleted(0); + + assertFalse(validator.validate(reqVO).isEmpty()); + } + + /** 管芯尺寸只能为3或6。 */ + @Test + void shouldRejectUnsupportedCoreTubeSize() { + ErpCoreTubeSyncReqVO reqVO = new ErpCoreTubeSyncReqVO(); + reqVO.setCoreTubeType("CORE-4"); + reqVO.setCoreTubeLength(BigDecimal.ONE); + reqVO.setCoreTubeWallThickness(BigDecimal.ONE); + reqVO.setSize("4"); + reqVO.setDeleted(0); + + assertFalse(validator.validate(reqVO).isEmpty()); + } + + /** 客户编码不能为空。 */ + @Test + void shouldRejectBlankCustomerCode() { + ErpCustomerSyncReqVO reqVO = new ErpCustomerSyncReqVO(); + reqVO.setCustomerName("测试客户"); + reqVO.setDeleted(0); + + assertFalse(validator.validate(reqVO).isEmpty()); + } + + /** 合法的四类请求均应通过校验。 */ + @Test + void shouldAcceptValidRequests() { + ErpMaterialSyncReqVO material = new ErpMaterialSyncReqVO(); + material.setMaterialType("FINISHED"); + material.setMaterialCode("MAT-001"); + material.setMaterialName("成品卷"); + material.setDeleted(0); + + ErpBoxSyncReqVO box = new ErpBoxSyncReqVO(); + box.setBoxType("BOX-A"); + box.setBoxLength(2100); + box.setBoxWidth(1200); + box.setBoxHeight(900); + box.setDeleted(0); + + ErpCoreTubeSyncReqVO coreTube = new ErpCoreTubeSyncReqVO(); + coreTube.setCoreTubeType("CORE-3"); + coreTube.setCoreTubeLength(new BigDecimal("1500")); + coreTube.setStepLength(BigDecimal.ZERO); + coreTube.setCoreTubeWallThickness(new BigDecimal("8")); + coreTube.setStepWallThickness(BigDecimal.ZERO); + coreTube.setSize("3"); + coreTube.setDeleted(0); + + ErpCustomerSyncReqVO customer = new ErpCustomerSyncReqVO(); + customer.setCustomerCode("CUS-001"); + customer.setCustomerName("测试客户"); + customer.setDeleted(0); + + assertTrue(validator.validate(material).isEmpty()); + assertTrue(validator.validate(box).isEmpty()); + assertTrue(validator.validate(coreTube).isEmpty()); + assertTrue(validator.validate(customer).isEmpty()); + } +} diff --git a/nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncLocalSpringTest.java b/nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncLocalSpringTest.java new file mode 100644 index 00000000..8225769d --- /dev/null +++ b/nl-module-wms/nl-module-wms-server/src/test/java/cn/code/nl/module/wms/service/erp/ErpMasterDataSyncLocalSpringTest.java @@ -0,0 +1,287 @@ +package cn.code.nl.module.wms.service.erp; + +import cn.code.nl.framework.common.pojo.CommonResult; +import cn.code.nl.module.base.api.materialbase.MaterialBaseApi; +import cn.code.nl.module.base.api.materialbase.dto.MaterialBaseSyncReq; +import cn.code.nl.module.wms.controller.erp.vo.ErpBoxSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCoreTubeSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpCustomerSyncReqVO; +import cn.code.nl.module.wms.controller.erp.vo.ErpMaterialSyncReqVO; +import cn.code.nl.module.wms.dal.dataobject.boxtype.BoxTypeDO; +import cn.code.nl.module.wms.dal.dataobject.coretubetype.CoreTubeTypeDO; +import cn.code.nl.module.wms.dal.dataobject.customer.CustomerDO; +import cn.code.nl.module.wms.dal.mysql.boxtype.BoxTypeMapper; +import cn.code.nl.module.wms.dal.mysql.coretubetype.CoreTubeTypeMapper; +import cn.code.nl.module.wms.dal.mysql.customer.CustomerMapper; +import jakarta.annotation.Resource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import java.lang.reflect.Proxy; +import java.math.BigDecimal; +import java.util.LinkedHashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** ERP基础信息同步本地Spring测试。 */ +@SpringJUnitConfig(ErpMasterDataSyncLocalSpringTest.Config.class) +class ErpMasterDataSyncLocalSpringTest { + + /** 待测同步服务。 */ + @Resource + private ErpMasterDataSyncService service; + + /** 内存数据库状态。 */ + @Resource + private State state; + + /** 每个测试前重置状态。 */ + @BeforeEach + void setUp() { + state.reset(); + } + + /** 物料请求应完整转发到Base模块。 */ + @Test + void shouldForwardMaterialToBaseModule() { + ErpMaterialSyncReqVO reqVO = new ErpMaterialSyncReqVO(); + reqVO.setMaterialType("FINISHED"); + reqVO.setMaterialCode("MAT-001"); + reqVO.setMaterialName("成品卷"); + reqVO.setMaterialDescription("测试物料"); + reqVO.setSpecificationModel("1000*0.5"); + reqVO.setDeleted(0); + + service.syncMaterial(reqVO); + + assertEquals("MAT-001", state.materialReq.getMaterialCode()); + assertEquals("测试物料", state.materialReq.getMaterialDescription()); + assertEquals("1000*0.5", state.materialReq.getSpecificationModel()); + } + + /** 木箱同步应更新ERP字段并保留WMS本地参数。 */ + @Test + void shouldUpdateBoxWithoutOverwritingLocalFields() { + BoxTypeDO existing = new BoxTypeDO(); + existing.setId(1L); + existing.setBoxType("BOX-A"); + existing.setLashNum("2"); + existing.setDesiccantNum(8); + existing.setMaxNum(3); + state.boxes.put("BOX-A", existing); + + service.syncBox(boxRequest(2100, 1)); + + BoxTypeDO saved = state.boxes.get("BOX-A"); + assertEquals(2100, saved.getBoxLength()); + assertEquals(1200, saved.getBoxWidth()); + assertEquals(900, saved.getBoxHigh()); + assertEquals("2", saved.getLashNum()); + assertEquals(8, saved.getDesiccantNum()); + assertEquals(3, saved.getMaxNum()); + assertTrue(saved.getDeleted()); + + service.syncBox(boxRequest(2200, 0)); + assertEquals(2200, state.boxes.get("BOX-A").getBoxLength()); + assertFalse(state.boxes.get("BOX-A").getDeleted()); + } + + /** 管芯类型同步应按类型新增、更新、删除并恢复。 */ + @Test + void shouldSynchronizeCoreTubeByType() { + service.syncCoreTube(coreTubeRequest(new BigDecimal("1500"), 0)); + service.syncCoreTube(coreTubeRequest(new BigDecimal("1600"), 1)); + + assertEquals(1, state.coreTubes.size()); + assertEquals(new BigDecimal("1600"), state.coreTubes.get("CORE-3").getCoreTubeLength()); + assertEquals("3", state.coreTubes.get("CORE-3").getSize()); + assertTrue(state.coreTubes.get("CORE-3").getDeleted()); + + service.syncCoreTube(coreTubeRequest(new BigDecimal("1700"), 0)); + assertFalse(state.coreTubes.get("CORE-3").getDeleted()); + } + + /** 客户同步应按客户编码新增、更新、删除并恢复。 */ + @Test + void shouldSynchronizeCustomerByCode() { + service.syncCustomer(customerRequest("四川客户", 0)); + service.syncCustomer(customerRequest("成都客户", 1)); + + assertEquals(1, state.customers.size()); + assertEquals("成都客户", state.customers.get("CUS-001").getCustomerName()); + assertTrue(state.customers.get("CUS-001").getDeleted()); + + service.syncCustomer(customerRequest("恢复客户", 0)); + assertFalse(state.customers.get("CUS-001").getDeleted()); + } + + /** 构造木箱请求。 */ + private ErpBoxSyncReqVO boxRequest(int boxLength, int deleted) { + ErpBoxSyncReqVO reqVO = new ErpBoxSyncReqVO(); + reqVO.setBoxType("BOX-A"); + reqVO.setBoxLength(boxLength); + reqVO.setBoxWidth(1200); + reqVO.setBoxHeight(900); + reqVO.setDeleted(deleted); + return reqVO; + } + + /** 构造管芯请求。 */ + private ErpCoreTubeSyncReqVO coreTubeRequest(BigDecimal length, int deleted) { + ErpCoreTubeSyncReqVO reqVO = new ErpCoreTubeSyncReqVO(); + reqVO.setCoreTubeType("CORE-3"); + reqVO.setCoreTubeLength(length); + reqVO.setStepLength(new BigDecimal("50")); + reqVO.setCoreTubeWallThickness(new BigDecimal("8")); + reqVO.setStepWallThickness(new BigDecimal("6")); + reqVO.setSize("3"); + reqVO.setDeleted(deleted); + return reqVO; + } + + /** 构造客户请求。 */ + private ErpCustomerSyncReqVO customerRequest(String customerName, int deleted) { + ErpCustomerSyncReqVO reqVO = new ErpCustomerSyncReqVO(); + reqVO.setCustomerCode("CUS-001"); + reqVO.setCustomerName(customerName); + reqVO.setAddress("四川省成都市"); + reqVO.setDeleted(deleted); + return reqVO; + } + + /** 测试Spring配置。 */ + @Configuration(proxyBeanMethods = false) + static class Config { + + /** 注册内存状态。 */ + @Bean + State state() { + return new State(); + } + + /** 注册真实同步服务。 */ + @Bean + ErpMasterDataSyncService service() { + return new ErpMasterDataSyncServiceImpl(); + } + + /** 注册物料API代理。 */ + @Bean + MaterialBaseApi materialBaseApi(State state) { + return state.proxy(MaterialBaseApi.class); + } + + /** 注册木箱Mapper代理。 */ + @Bean + BoxTypeMapper boxTypeMapper(State state) { + return state.proxy(BoxTypeMapper.class); + } + + /** 注册管芯Mapper代理。 */ + @Bean + CoreTubeTypeMapper coreTubeTypeMapper(State state) { + return state.proxy(CoreTubeTypeMapper.class); + } + + /** 注册客户Mapper代理。 */ + @Bean + CustomerMapper customerMapper(State state) { + return state.proxy(CustomerMapper.class); + } + } + + /** 模拟远程接口和三张WMS业务表。 */ + static class State { + private final Map boxes = new LinkedHashMap<>(); + private final Map coreTubes = new LinkedHashMap<>(); + private final Map customers = new LinkedHashMap<>(); + private MaterialBaseSyncReq materialReq; + + /** 清理全部状态。 */ + void reset() { + boxes.clear(); + coreTubes.clear(); + customers.clear(); + materialReq = null; + } + + /** 创建接口代理。 */ + @SuppressWarnings("unchecked") + T proxy(Class type) { + return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, + (proxy, method, args) -> invoke(type, method.getName(), args)); + } + + /** 执行接口模拟逻辑。 */ + private Object invoke(Class type, String methodName, Object[] args) { + if (type == MaterialBaseApi.class && "syncMaterialBase".equals(methodName)) { + materialReq = (MaterialBaseSyncReq) args[0]; + return CommonResult.success(Boolean.TRUE); + } + if (type == BoxTypeMapper.class) { + return invokeBox(methodName, args); + } + if (type == CoreTubeTypeMapper.class) { + return invokeCoreTube(methodName, args); + } + if (type == CustomerMapper.class) { + return invokeCustomer(methodName, args); + } + return null; + } + + /** 执行木箱Mapper模拟逻辑。 */ + private Object invokeBox(String methodName, Object[] args) { + if ("selectByBoxTypeIncludingDeleted".equals(methodName)) { + return boxes.get(args[0]); + } + if ("insert".equals(methodName)) { + BoxTypeDO row = (BoxTypeDO) args[0]; + boxes.put(row.getBoxType(), row); + return 1; + } + if ("updateErpBox".equals(methodName)) { + BoxTypeDO update = (BoxTypeDO) args[0]; + BoxTypeDO row = boxes.get(update.getBoxType()); + row.setBoxLength(update.getBoxLength()); + row.setBoxWidth(update.getBoxWidth()); + row.setBoxHigh(update.getBoxHigh()); + row.setDeleted(update.getDeleted()); + return 1; + } + return null; + } + + /** 执行管芯Mapper模拟逻辑。 */ + private Object invokeCoreTube(String methodName, Object[] args) { + if ("selectByCoreTubeTypeIncludingDeleted".equals(methodName)) { + return coreTubes.get(args[0]); + } + if ("insert".equals(methodName) || "updateErpCoreTube".equals(methodName)) { + CoreTubeTypeDO row = (CoreTubeTypeDO) args[0]; + coreTubes.put(row.getCoreTubeType(), row); + return 1; + } + return null; + } + + /** 执行客户Mapper模拟逻辑。 */ + private Object invokeCustomer(String methodName, Object[] args) { + if ("selectByCustomerCodeIncludingDeleted".equals(methodName)) { + return customers.get(args[0]); + } + if ("insert".equals(methodName) || "updateErpCustomer".equals(methodName)) { + CustomerDO row = (CustomerDO) args[0]; + customers.put(row.getCustomerCode(), row); + return 1; + } + return null; + } + } +} diff --git a/sql/mysql/erp_wms_master_data.sql b/sql/mysql/erp_wms_master_data.sql index abad430d..2db4ef2d 100644 --- a/sql/mysql/erp_wms_master_data.sql +++ b/sql/mysql/erp_wms_master_data.sql @@ -49,6 +49,37 @@ CALL add_column_if_missing( DROP PROCEDURE IF EXISTS add_column_if_missing; +DROP PROCEDURE IF EXISTS add_index_if_missing; +DELIMITER $$ +CREATE PROCEDURE add_index_if_missing( + IN table_name_value varchar(64), + IN index_name_value varchar(64), + IN index_definition_value varchar(1000) +) +BEGIN + IF NOT EXISTS ( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = DATABASE() + AND table_name = table_name_value + AND index_name = index_name_value + ) THEN + SET @alter_index_sql = CONCAT('ALTER TABLE `', table_name_value, '` ADD ', index_definition_value); + PREPARE alter_index_statement FROM @alter_index_sql; + EXECUTE alter_index_statement; + DEALLOCATE PREPARE alter_index_statement; + END IF; +END$$ +DELIMITER ; + +CALL add_index_if_missing( + 'base_materialbase', + 'uk_material_code', + 'UNIQUE KEY `uk_material_code` (`material_code`) USING BTREE' +); + +DROP PROCEDURE IF EXISTS add_index_if_missing; + CREATE TABLE IF NOT EXISTS `wms_core_tube_type` ( `id` bigint NOT NULL COMMENT '主键', `core_tube_type` varchar(64) NOT NULL COMMENT '管芯类型',