|
|
@ -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<BomDO> 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(","); |
|
|
|
} |
|
|
@ -172,29 +181,29 @@ public class BomServiceImpl implements BomService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public BomDO bomItemCodeAndVersionExist(String productItemCode, String version) { |
|
|
|
public List<BomDO> 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<BomDO> bomDOList = bomMapper.selectList(queryWrapper); |
|
|
|
if( bomDOList != null && bomDOList.size() > 0){ |
|
|
|
return bomDOList; |
|
|
|
}else { |
|
|
|
throw exception(BOM_ITEM_VERSION_QTY_EXISTS, "父物料" + productItemCode + "与bom版本" + version + "关系无效"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|