diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java index d2ae319c..946e4529 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java @@ -44,7 +44,7 @@ public class BomServiceImpl implements BomService { @Override public Long createBom(BomCreateReqVO createReqVO) { - validateBomForCreateOrUpdate(createReqVO.getId(),createReqVO.getProductItemCode(),createReqVO.getComponentItemCode(),createReqVO.getComponentUom(),createReqVO.getComponentQty(), + validateBomForCreateOrUpdate(createReqVO.getId(),createReqVO.getProductItemCode(),createReqVO.getComponentItemCode(),createReqVO.getVersion(),createReqVO.getComponentUom(),createReqVO.getComponentQty(), createReqVO.getProcessCode(),createReqVO.getAvailable()); // 插入 BomDO bom = BomConvert.INSTANCE.convert(createReqVO); @@ -53,12 +53,21 @@ public class BomServiceImpl implements BomService { return bom.getId(); } + + public BomDO existBom(String productItemCode,String componentItemCode,String version){ + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("product_item_code",productItemCode); + queryWrapper.eq("component_item_code",componentItemCode); + queryWrapper.eq("version",version); + BomDO bomDO = bomMapper.selectOne(queryWrapper); + return bomDO; + } + @Override public void updateBom(BomUpdateReqVO updateReqVO) { // 校验存在 - validateBomForCreateOrUpdate(updateReqVO.getId(),updateReqVO.getProductItemCode(),updateReqVO.getComponentItemCode(),updateReqVO.getComponentUom(), + validateBomForCreateOrUpdate(updateReqVO.getId(),updateReqVO.getProductItemCode(),updateReqVO.getComponentItemCode(),updateReqVO.getVersion(),updateReqVO.getComponentUom(), updateReqVO.getComponentQty(),updateReqVO.getProcessCode(),updateReqVO.getAvailable()); - // 更新 BomDO updateObj = BomConvert.INSTANCE.convert(updateReqVO); bomMapper.updateById(updateObj); @@ -105,7 +114,7 @@ public class BomServiceImpl implements BomService { message.append(ex.getMessage()).append(","); } try { - validateProductItemCodeExists(null,bomDo.getProductItemCode()); + validateProductItemCodeExists(null,bomDo.getProductItemCode(),bomDo.getComponentItemCode(),bomDo.getVersion()); } catch (ServiceException ex) { message.append(ex.getMessage()).append(","); } @@ -185,16 +194,16 @@ public class BomServiceImpl implements BomService { } } - private void validateBomForCreateOrUpdate(Long id,String productItemCode,String componentItemCode, + private void validateBomForCreateOrUpdate(Long id,String productItemCode,String componentItemCode,String version, String componentUom,BigDecimal componentQty,String processCode,String available) { // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 DataPermissionUtils.executeIgnore(() -> { validateBomExists(id); // 校验code唯一 - validateProductItemCodeExists(id,productItemCode); validateComponentUomExists(componentUom); validateAvailableExists(available); validateComponentItemCodeExists(componentItemCode); + validateProductItemCodeExists(id,productItemCode,componentItemCode,version); validateComponentQtyExists(componentQty); validateProcessCodeExists(processCode); }); @@ -209,15 +218,18 @@ public class BomServiceImpl implements BomService { throw exception(BOM_NOT_EXISTS); } } + + @VisibleForTesting - private void validateProductItemCodeExists(Long id,String productItemCode) { + private void validateProductItemCodeExists(Long id,String productItemCode,String componentItemCode,String version) { + if (productItemCode.isEmpty()) { throw exception(BOM_PRODUCT_ITEM_CODE_NOT_EXISTS); } if (StrUtil.isBlank(productItemCode)) { return; } - BomDO bom = bomMapper.selectByProductItemCode(productItemCode); + BomDO bom = existBom(productItemCode,componentItemCode,version); if (bom == null) { return; }