Browse Source

2026-10-10

优化产品和配方BOM,【Copy】和【粘贴】校验“不能将自己作为子物料”
master
fengyuan_yang 4 weeks ago
parent
commit
b39c3db587
  1. 38
      src/main/java/com/spring/modules/part/service/impl/BomManagementServiceImpl.java
  2. 32
      src/main/java/com/spring/modules/part/service/impl/RecipeManagementServiceImpl.java

38
src/main/java/com/spring/modules/part/service/impl/BomManagementServiceImpl.java

@ -667,9 +667,7 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
// throw new RuntimeException("子物料已存在,请检查!"); // throw new RuntimeException("子物料已存在,请检查!");
// } // }
// 校验不能选择自己为子件 // 校验不能选择自己为子件
if (StringUtils.equals(normalizePartNo(data.getPartNo()), normalizedComponentPart)) {
throw new RuntimeException("不能将自己作为子物料!");
}
assertNotSelfAsComponent(data.getPartNo(), normalizedComponentPart);
// 校验子物料是否合规 // 校验子物料是否合规
PartInformationEntity partInformationEntity = partInformationMapper.selectOne(new QueryWrapper<PartInformationEntity>().eq("site", data.getSite()).eq("part_no", data.getComponentPart())); PartInformationEntity partInformationEntity = partInformationMapper.selectOne(new QueryWrapper<PartInformationEntity>().eq("site", data.getSite()).eq("part_no", data.getComponentPart()));
if (partInformationEntity == null) { if (partInformationEntity == null) {
@ -813,7 +811,8 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
@Override @Override
@Transactional @Transactional
public Map<String, Object> updateBomComponent(BomComponentEntity data) { public Map<String, Object> updateBomComponent(BomComponentEntity data) {
normalizeAndValidateComponentPart(data);
String normalizedComponentPart = normalizeAndValidateComponentPart(data);
assertNotSelfAsComponent(data.getPartNo(), normalizedComponentPart);
BomComponentEntity oldData = bomManagementMapper.queryBomComponentByLineItemNo(data); BomComponentEntity oldData = bomManagementMapper.queryBomComponentByLineItemNo(data);
// 修改bom子明细物料 // 修改bom子明细物料
if ("byProduct".equals(data.getProductFlag())) { if ("byProduct".equals(data.getProductFlag())) {
@ -888,7 +887,8 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
} }
for (BomComponentEntity data : items) { for (BomComponentEntity data : items) {
normalizeAndValidateComponentPart(data);
String normalizedComponentPart = normalizeAndValidateComponentPart(data);
assertNotSelfAsComponent(data.getPartNo(), normalizedComponentPart);
if ("byProduct".equals(data.getProductFlag())) { if ("byProduct".equals(data.getProductFlag())) {
data.setQtyPerAssembly(data.getQtyPerAssembly().negate()); data.setQtyPerAssembly(data.getQtyPerAssembly().negate());
} }
@ -1125,6 +1125,7 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
for (BomDetailEntity detailEntity : detailDataList) { for (BomDetailEntity detailEntity : detailDataList) {
// 查询原BOM替代列表 // 查询原BOM替代列表
List<BomComponentVo> componentDataList = bomManagementMapper.queryBomComponentAll(detailEntity); List<BomComponentVo> componentDataList = bomManagementMapper.queryBomComponentAll(detailEntity);
assertNoSelfAsComponent(data.getPartNo(), componentDataList);
// 查询原BOM副产品成本分配数据列表 // 查询原BOM副产品成本分配数据列表
List<BomManufStructCostDistribVo> manufStructCostDistribList = bomManagementMapper.queryBomManufStructCostDistrib(detailEntity); List<BomManufStructCostDistribVo> manufStructCostDistribList = bomManagementMapper.queryBomManufStructCostDistrib(detailEntity);
detailEntity.setPartNo(data.getPartNo()); detailEntity.setPartNo(data.getPartNo());
@ -1228,6 +1229,7 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
// 创建替代中的子件 // 创建替代中的子件
List<BomComponentVo> componentList = bomManagementMapper.queryBomComponentAll(data.getPreviousVersion()); List<BomComponentVo> componentList = bomManagementMapper.queryBomComponentAll(data.getPreviousVersion());
assertNoSelfAsComponent(data.getPartNo(), componentList);
if (!componentList.isEmpty()) { if (!componentList.isEmpty()) {
List<BomComponentVo> collect = componentList.stream().map(a -> { List<BomComponentVo> collect = componentList.stream().map(a -> {
a.setPartNo(data.getPartNo()); a.setPartNo(data.getPartNo());
@ -1741,7 +1743,8 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
data.setBomType(inData.getBomType()); data.setBomType(inData.getBomType());
data.setAlternativeNo(inData.getAlternativeNo()); data.setAlternativeNo(inData.getAlternativeNo());
data.setCreateBy(inData.getUpdateBy()); data.setCreateBy(inData.getUpdateBy());
normalizeAndValidateComponentPart(data);
String normalizedComponentPart = normalizeAndValidateComponentPart(data);
assertNotSelfAsComponent(data.getPartNo(), normalizedComponentPart);
// 校验子物料是否合规 // 校验子物料是否合规
PartInformationEntity partInformationEntity = partInformationMapper.selectOne(new QueryWrapper<PartInformationEntity>().eq("site", data.getSite()).eq("part_no", data.getComponentPart())); PartInformationEntity partInformationEntity = partInformationMapper.selectOne(new QueryWrapper<PartInformationEntity>().eq("site", data.getSite()).eq("part_no", data.getComponentPart()));
if (partInformationEntity == null) { if (partInformationEntity == null) {
@ -1846,6 +1849,29 @@ public class BomManagementServiceImpl extends ServiceImpl<BomManagementMapper, B
return StringUtils.upperCase(StringUtils.trimToEmpty(partNo)); return StringUtils.upperCase(StringUtils.trimToEmpty(partNo));
} }
private void assertNotSelfAsComponent(String partNo, String componentPart) {
String parentPartNo = normalizePartNo(partNo);
String childPartNo = normalizePartNo(componentPart);
if (StringUtils.isBlank(parentPartNo) || StringUtils.isBlank(childPartNo)) {
return;
}
if (StringUtils.equals(parentPartNo, childPartNo)) {
throw new RuntimeException("不能将自己作为子物料!");
}
}
private void assertNoSelfAsComponent(String partNo, List<? extends BomComponentEntity> components) {
if (components == null || components.isEmpty()) {
return;
}
for (BomComponentEntity component : components) {
if (component == null) {
continue;
}
assertNotSelfAsComponent(partNo, component.getComponentPart());
}
}
private String normalizeAndValidateComponentPart(BomComponentEntity data) { private String normalizeAndValidateComponentPart(BomComponentEntity data) {
if (data == null) { if (data == null) {
throw new RuntimeException("子物料数据不能为空!"); throw new RuntimeException("子物料数据不能为空!");

32
src/main/java/com/spring/modules/part/service/impl/RecipeManagementServiceImpl.java

@ -727,9 +727,7 @@ public class RecipeManagementServiceImpl extends ServiceImpl<RecipeManagementMap
public Map<String, Object> saveRecipeComponent(RecipeComponentEntity data) { public Map<String, Object> saveRecipeComponent(RecipeComponentEntity data) {
String normalizedComponentPart = normalizeAndValidateComponentPart(data); String normalizedComponentPart = normalizeAndValidateComponentPart(data);
// 校验不能选择自己为子件 // 校验不能选择自己为子件
if (StringUtils.equals(normalizePartNo(data.getPartNo()), normalizedComponentPart)) {
throw new RuntimeException("不能将自己作为子物料!");
}
assertNotSelfAsComponent(data.getPartNo(), normalizedComponentPart);
// 校验子物料是否合规 // 校验子物料是否合规
PartInformationEntity partInformationEntity = partInformationMapper.selectOne(new QueryWrapper<PartInformationEntity>().eq("site", data.getSite()).eq("part_no", data.getComponentPart())); PartInformationEntity partInformationEntity = partInformationMapper.selectOne(new QueryWrapper<PartInformationEntity>().eq("site", data.getSite()).eq("part_no", data.getComponentPart()));
if (partInformationEntity == null) { if (partInformationEntity == null) {
@ -834,7 +832,8 @@ public class RecipeManagementServiceImpl extends ServiceImpl<RecipeManagementMap
@Override @Override
@Transactional @Transactional
public Map<String, Object> updateRecipeComponent(RecipeComponentEntity data) { public Map<String, Object> updateRecipeComponent(RecipeComponentEntity data) {
normalizeAndValidateComponentPart(data);
String normalizedComponentPart = normalizeAndValidateComponentPart(data);
assertNotSelfAsComponent(data.getPartNo(), normalizedComponentPart);
// 修改recipe子明细物料 // 修改recipe子明细物料
if ("byProduct".equals(data.getProductFlag())) { if ("byProduct".equals(data.getProductFlag())) {
data.setQtyPerAssembly(data.getQtyPerAssembly().negate()); data.setQtyPerAssembly(data.getQtyPerAssembly().negate());
@ -1056,6 +1055,7 @@ public class RecipeManagementServiceImpl extends ServiceImpl<RecipeManagementMap
for (RecipeDetailEntity detailEntity : detailDataList) { for (RecipeDetailEntity detailEntity : detailDataList) {
// 查询原Recipe替代列表 // 查询原Recipe替代列表
List<RecipeComponentVo> componentDataList = recipeManagementMapper.queryRecipeComponentAll(detailEntity); List<RecipeComponentVo> componentDataList = recipeManagementMapper.queryRecipeComponentAll(detailEntity);
assertNoSelfAsComponent(data.getPartNo(), componentDataList);
// 查询原Recipe副产品成本分配数据列表 // 查询原Recipe副产品成本分配数据列表
List<RecipeManufStructCostDistribVo> manufStructCostDistribList = recipeManagementMapper.queryRecipeManufStructCostDistrib(detailEntity); List<RecipeManufStructCostDistribVo> manufStructCostDistribList = recipeManagementMapper.queryRecipeManufStructCostDistrib(detailEntity);
detailEntity.setPartNo(data.getPartNo()); detailEntity.setPartNo(data.getPartNo());
@ -1151,6 +1151,7 @@ public class RecipeManagementServiceImpl extends ServiceImpl<RecipeManagementMap
recipeManagementMapper.recipeDetailSave(data); recipeManagementMapper.recipeDetailSave(data);
// 创建替代中的子件 // 创建替代中的子件
List<RecipeComponentVo> componentList = recipeManagementMapper.queryRecipeComponentAll(data.getPreviousVersion()); List<RecipeComponentVo> componentList = recipeManagementMapper.queryRecipeComponentAll(data.getPreviousVersion());
assertNoSelfAsComponent(data.getPartNo(), componentList);
if (!componentList.isEmpty()) { if (!componentList.isEmpty()) {
List<RecipeComponentVo> collect = componentList.stream().map(a -> { List<RecipeComponentVo> collect = componentList.stream().map(a -> {
a.setPartNo(data.getPartNo()); a.setPartNo(data.getPartNo());
@ -1504,6 +1505,29 @@ public class RecipeManagementServiceImpl extends ServiceImpl<RecipeManagementMap
return StringUtils.upperCase(StringUtils.trimToEmpty(partNo)); return StringUtils.upperCase(StringUtils.trimToEmpty(partNo));
} }
private void assertNotSelfAsComponent(String partNo, String componentPart) {
String parentPartNo = normalizePartNo(partNo);
String childPartNo = normalizePartNo(componentPart);
if (StringUtils.isBlank(parentPartNo) || StringUtils.isBlank(childPartNo)) {
return;
}
if (StringUtils.equals(parentPartNo, childPartNo)) {
throw new RuntimeException("不能将自己作为子物料!");
}
}
private void assertNoSelfAsComponent(String partNo, List<? extends RecipeComponentEntity> components) {
if (components == null || components.isEmpty()) {
return;
}
for (RecipeComponentEntity component : components) {
if (component == null) {
continue;
}
assertNotSelfAsComponent(partNo, component.getComponentPart());
}
}
private String normalizeAndValidateComponentPart(RecipeComponentEntity data) { private String normalizeAndValidateComponentPart(RecipeComponentEntity data) {
if (data == null) { if (data == null) {
throw new RuntimeException("子物料数据不能为空!"); throw new RuntimeException("子物料数据不能为空!");

Loading…
Cancel
Save