optimize(ebom): 删除时更新last_version_is

This commit is contained in:
曹鹏飞 2024-05-29 10:17:40 +08:00
parent fd3c119ac5
commit 70faa04f00
3 changed files with 25 additions and 5 deletions

View File

@ -104,4 +104,6 @@ public interface BomNewEbomParentMapper extends BaseMapper<BomNewEbomParentEntit
void delEBomHistory(@Param("parentRowIds") List<Long> parentRowIds); void delEBomHistory(@Param("parentRowIds") List<Long> parentRowIds);
List<BomNewEbomParentEntity> getLatestByMaterialNo(Collection<String> materialNos); List<BomNewEbomParentEntity> getLatestByMaterialNo(Collection<String> materialNos);
void updateLastVersionIs();
} }

View File

@ -2572,10 +2572,15 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
VUtils.isTure(!StrUtil.equals(root.getCreatedBy(), SessionUtil.getUserCode())).throwMessage("不能删除他人的数据"); VUtils.isTure(!StrUtil.equals(root.getCreatedBy(), SessionUtil.getUserCode())).throwMessage("不能删除他人的数据");
delete(root.getRowId()); delete(root.getRowId());
CompletableFuture.runAsync(this::updateLastVersionIs);
return true; return true;
} }
private void delete(Long bomRowId) { private void delete(Long bomRowId) {
this.getBaseMapper().delete(Wrappers.lambdaQuery(BomNewEbomParentEntity.class)
.eq(BomNewEbomParentEntity::getRowId, bomRowId));
Set<String> materialNos = ebomChildService.lambdaQuery() Set<String> materialNos = ebomChildService.lambdaQuery()
.select(BomNewEbomChildEntity::getMaterialNo) .select(BomNewEbomChildEntity::getMaterialNo)
.eq(BomNewEbomChildEntity::getParentRowId, bomRowId) .eq(BomNewEbomChildEntity::getParentRowId, bomRowId)
@ -2583,6 +2588,10 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
.stream() .stream()
.map(BomNewEbomChildEntity::getMaterialNo) .map(BomNewEbomChildEntity::getMaterialNo)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
ebomChildService.getBaseMapper().delete(Wrappers.lambdaQuery(BomNewEbomChildEntity.class)
.eq(BomNewEbomChildEntity::getParentRowId, bomRowId));
if (CollUtil.isEmpty(materialNos)) return; if (CollUtil.isEmpty(materialNos)) return;
List<BomNewEbomParentEntity> parents = lambdaQuery() List<BomNewEbomParentEntity> parents = lambdaQuery()
@ -2599,11 +2608,6 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|| Objects.equals(p.getVirtualPackageIs(), 1)) || Objects.equals(p.getVirtualPackageIs(), 1))
.map(BomNewEbomParentEntity::getRowId) .map(BomNewEbomParentEntity::getRowId)
.collect(Collectors.toList()); .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));
//将自己手动创建的bom提为用户顶层 //将自己手动创建的bom提为用户顶层
List<Long> updateParents = parents.stream() List<Long> updateParents = parents.stream()
.filter(p -> StrUtil.equals(p.getCreatedBy(), SessionUtil.getUserCode())) .filter(p -> StrUtil.equals(p.getCreatedBy(), SessionUtil.getUserCode()))
@ -2619,4 +2623,8 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
deleteParents.forEach(this::delete); deleteParents.forEach(this::delete);
} }
private void updateLastVersionIs() {
this.getBaseMapper().updateLastVersionIs();
}
} }

View File

@ -314,6 +314,16 @@
#{item} #{item}
</foreach> </foreach>
</update> </update>
<update id="updateLastVersionIs">
UPDATE t_bom_new_ebom_parent
SET last_version_is=0;
UPDATE t_bom_new_ebom_parent p1
INNER JOIN (SELECT material_no, MAX(current_version) current_version
FROM t_bom_new_ebom_parent
GROUP BY material_no) p2 ON p1.material_no = p2.material_no AND
p1.current_version = p2.current_version
SET p1.last_version_is=1;
</update>
<!--检查是否已发布数据的跟节点--> <!--检查是否已发布数据的跟节点-->