|
|
@@ -49,6 +49,7 @@ import org.springblade.manager.vo.*;
|
|
|
import org.springblade.manager.mapper.ArchiveTreeContractMapper;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -753,77 +754,21 @@ public class ArchiveTreeContractServiceImpl extends BaseServiceImpl<ArchiveTreeC
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
-// public boolean deleteTree(Long id) {
|
|
|
-// ArchiveTreeContract dstNode = this.getById(id);
|
|
|
-// if (dstNode == null ) {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-//
|
|
|
-// List<ArchiveTreeContractVO2> dstTrees = this.tree2Root(AuthUtil.getTenantId(),null,null,dstNode.getProjectId(),null);
|
|
|
-// if (dstTrees == null || dstTrees.size() == 0) {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-//
|
|
|
-// ArchiveTreeContractVO2 subTree = ForestNodeMergerEx.getSubTree(dstTrees.get(0),id);
|
|
|
-//
|
|
|
-// List<Long> ids = ForestNodeMergerEx.getChildrenIds(subTree);
|
|
|
-//
|
|
|
-// ids.add(id);
|
|
|
-// this.deleteLogic(ids);
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
- public boolean deleteTree(Long id) {
|
|
|
+ public Boolean deleteTree(Long id) {
|
|
|
ArchiveTreeContract dstNode = this.getById(id);
|
|
|
- if (dstNode == null) {
|
|
|
+ if (dstNode == null ) {
|
|
|
return false;
|
|
|
}
|
|
|
- String tenantId = AuthUtil.getTenantId();
|
|
|
- Long projectId = dstNode.getProjectId();
|
|
|
-
|
|
|
- // 调用纯Java递归方法,替代CTE/存储过程
|
|
|
- List<Long> ids = listAllChildIds(id, projectId, tenantId);
|
|
|
- if (CollectionUtils.isEmpty(ids)) {
|
|
|
+ List<ArchiveTreeContractVO2> dstTrees = this.tree2Root(AuthUtil.getTenantId(),null,null,dstNode.getProjectId(),null);
|
|
|
+ if (dstTrees == null || dstTrees.size() == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+ ArchiveTreeContractVO2 subTree = ForestNodeMergerEx.getSubTree(dstTrees.get(0),id);
|
|
|
+ List<Long> ids = ForestNodeMergerEx.getChildrenIds(subTree);
|
|
|
+ ids.add(id);
|
|
|
this.deleteLogic(ids);
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
- public List<Long> listAllChildIds(Long parentId, Long projectId, String tenantId) {
|
|
|
- // 1. 先校验节点是否存在,避免无效递归
|
|
|
- Integer exists = baseMapper.checkNodeExists(parentId, projectId, tenantId);
|
|
|
- if (exists == null || exists == 0) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 递归收集所有子节点ID(含自身)
|
|
|
- List<Long> allChildIds = new ArrayList<>();
|
|
|
- collectAllChildIds(parentId, projectId, tenantId, allChildIds);
|
|
|
- return allChildIds;
|
|
|
- }
|
|
|
-
|
|
|
- private void collectAllChildIds(Long currentId, Long projectId, String tenantId, List<Long> allChildIds) {
|
|
|
- // 防止循环引用(如父节点引用子节点)导致死循环
|
|
|
- if (allChildIds.contains(currentId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 添加当前节点ID
|
|
|
- allChildIds.add(currentId);
|
|
|
-
|
|
|
- // 查询当前节点的直接子节点
|
|
|
- List<Long> directChildIds = baseMapper.listDirectChildIds(currentId, projectId, tenantId);
|
|
|
- if (CollectionUtils.isEmpty(directChildIds)) {
|
|
|
- return; // 无直接子节点,递归终止
|
|
|
- }
|
|
|
-
|
|
|
- // 递归查询子节点的子节点
|
|
|
- for (Long childId : directChildIds) {
|
|
|
- collectAllChildIds(childId, projectId, tenantId, allChildIds);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 更轻量的删除节点树,同时删除节点下的案卷和文件
|
|
|
* @param id
|
|
|
@@ -857,6 +802,12 @@ public class ArchiveTreeContractServiceImpl extends BaseServiceImpl<ArchiveTreeC
|
|
|
return baseMapper.getArchiveTreeContractListByListOrderByTreeSort(nodeIds);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void deleteByAncestors(Long id, Long projectId) {
|
|
|
+ baseMapper.deleteByAncestors(id, projectId);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 批量更新
|