From f05d9ea3c86cf235f59e3aa7e784495554682f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=96=AA=E5=90=8D?= <942005050@qq.com> Date: Wed, 29 Nov 2023 11:18:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=89=A9=E5=93=81=E4=B8=8Ebom=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=85=B3=E7=B3=BB=E6=A0=A1=E9=AA=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/win/module/wms/service/bom/BomService.java | 2 +- .../com/win/module/wms/service/bom/BomServiceImpl.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java index 6544411e..12d52d31 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java @@ -87,5 +87,5 @@ public interface BomService { * @param version * @return */ - public BomDO bomItemCodeAndVersionExist(String productItemCode, String version); + public List bomItemCodeAndVersionExist(String productItemCode, String version); } 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 676a728a..d2ae319c 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 @@ -172,14 +172,14 @@ public class BomServiceImpl implements BomService { } @Override - public BomDO bomItemCodeAndVersionExist(String productItemCode, String version) { + public List bomItemCodeAndVersionExist(String productItemCode, String version) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("product_item_code",productItemCode); queryWrapper.eq("version",version); queryWrapper.eq("available","TRUE"); - BomDO bomDO = bomMapper.selectOne(queryWrapper); - if( bomDO != null){ - return bomDO; + List bomDOList = bomMapper.selectList(queryWrapper); + if( bomDOList != null && bomDOList.size() > 0){ + return bomDOList; }else { throw exception(BOM_ITEM_VERSION_QTY_EXISTS, "父物料" + productItemCode + "与bom版本" + version + "关系无效"); } From 99c205eff3ece32dfc6a464ea83b2fe12ab6a697 Mon Sep 17 00:00:00 2001 From: "hongxi.lian" Date: Wed, 29 Nov 2023 11:38:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=89=A9=E6=96=99=E6=B8=85=E5=8D=95?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/service/bom/BomServiceImpl.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) 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; }