feat(ebom): 删除bom逻辑重写
This commit is contained in:
parent
481491c950
commit
64b4adcb9f
|
|
@ -349,7 +349,7 @@ public class EbomApi extends BaseApi {
|
|||
@ApiOperation("删除物料")
|
||||
@LogRecord(success = "Ebom-删除物料,物料编码:{{#bom.materialNo}}-版本:{{#bom.currentVersion}},操作结果:{{#_ret}}", bizNo = "{{#bomRowId}}", type = "Ebom-删除物料")
|
||||
public ResultVO<Boolean> deleteBom(@RequestParam("bomRowId") Long bomRowId) throws ExecutionException, InterruptedException {
|
||||
return ResultVO.success(bomNewEbomParentService.deleteBom(bomRowId));
|
||||
return ResultVO.success(bomNewEbomParentService.deleteBomV2(bomRowId));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2396,6 +2396,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
vo.setMaterialTexture(d.getMaterialTexture());
|
||||
vo.setMaterialUnit(d.getMaterialUnit());
|
||||
vo.setCategoryName(d.getCategoryName());
|
||||
vo.setRelCategoryCode(d.getRelCategoryCode());
|
||||
QueryMaterialsQuery q = query.stream()
|
||||
.filter(f -> StrUtil.equals(f.getMaterialNo(), vo.getMaterialNo()) || StrUtil.equals(f.getDrawingNo(), vo.getDrawingNo()))
|
||||
.findFirst()
|
||||
|
|
@ -2530,4 +2531,45 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteBomV2(Long bomRowId) {
|
||||
BomNewEbomParentEntity root = getById(bomRowId);
|
||||
VUtils.isTure(Objects.isNull(root)).throwMessage("bom不存在");
|
||||
VUtils.isTure(root.getRootIs() != 1 && root.getUserRootIs() != 0).throwMessage("请选择根节点");
|
||||
VUtils.isTure(StrUtil.equals(root.getCreatedBy(), SessionUtil.getUserCode())).throwMessage("不能删除他人的数据");
|
||||
|
||||
delete(root.getRowId());
|
||||
return true;
|
||||
}
|
||||
|
||||
private void delete(Long bomRowId) {
|
||||
Set<String> materialNos = ebomChildService.lambdaQuery()
|
||||
.select(BomNewEbomChildEntity::getMaterialNo)
|
||||
.eq(BomNewEbomChildEntity::getParentRowId, bomRowId)
|
||||
.list()
|
||||
.stream()
|
||||
.map(BomNewEbomChildEntity::getMaterialNo)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<BomNewEbomParentEntity> parents = lambdaQuery()
|
||||
.select(BomNewEbomParentEntity::getRowId, BomNewEbomParentEntity::getCreatedBy
|
||||
, BomNewEbomParentEntity::getSource, BomNewEbomParentEntity::getVirtualPackageIs)
|
||||
.lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
|
||||
.in(BomNewEbomParentEntity::getMaterialNo, materialNos)
|
||||
.list();
|
||||
List<Long> deleteParents = parents.stream()
|
||||
.filter(p -> (StrUtil.equals(p.getCreatedBy(), SessionUtil.getUserCode())
|
||||
&& (Objects.equals(p.getSource(), EBomSourceEnum.FROM_BOM.getValue()) || Objects.equals(p.getSource(), EBomSourceEnum.FROM_EXCE.getValue())))
|
||||
|| Objects.equals(p.getVirtualPackageIs(), 1))
|
||||
.map(BomNewEbomParentEntity::getRowId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
ebomChildService.getBaseMapper().delete(Wrappers.lambdaQuery(BomNewEbomChildEntity.class)
|
||||
.eq(BomNewEbomChildEntity::getParentRowId, bomRowId));
|
||||
this.getBaseMapper().delete(Wrappers.lambdaQuery(BomNewEbomParentEntity.class)
|
||||
.eq(BomNewEbomParentEntity::getRowId, bomRowId));
|
||||
|
||||
deleteParents.forEach(this::delete);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue