|
|
@@ -781,8 +781,8 @@ public class ArchiveTreeContractServiceImpl extends BaseServiceImpl<ArchiveTreeC
|
|
|
String tenantId = AuthUtil.getTenantId();
|
|
|
Long projectId = dstNode.getProjectId();
|
|
|
|
|
|
- // 调用优化后的listAllChildIds(CTE/存储过程均可)
|
|
|
- List<Long> ids = this.listAllChildIds(id, projectId, tenantId);
|
|
|
+ // 调用纯Java递归方法,替代CTE/存储过程
|
|
|
+ List<Long> ids = listAllChildIds(id, projectId, tenantId);
|
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -792,24 +792,36 @@ public class ArchiveTreeContractServiceImpl extends BaseServiceImpl<ArchiveTreeC
|
|
|
}
|
|
|
|
|
|
public List<Long> listAllChildIds(Long parentId, Long projectId, String tenantId) {
|
|
|
- // 1. 构建存储过程入参
|
|
|
- Map<String, Object> params = new HashMap<>(4);
|
|
|
- params.put("parentId", parentId);
|
|
|
- params.put("projectId", projectId);
|
|
|
- params.put("tenantId", tenantId);
|
|
|
- params.put("outIds", ""); // 初始化出参
|
|
|
-
|
|
|
- // 2. 调用存储过程
|
|
|
- baseMapper.callGetChildIds(params);
|
|
|
-
|
|
|
- // 3. 解析出参(逗号分隔的ID字符串转Long列表)
|
|
|
- String outIds = (String) params.get("outIds");
|
|
|
- if (StringUtils.isEmpty(outIds)) {
|
|
|
+ // 1. 先校验节点是否存在,避免无效递归
|
|
|
+ Integer exists = baseMapper.checkNodeExists(parentId, projectId, tenantId);
|
|
|
+ if (exists == null || exists == 0) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- return Arrays.stream(outIds.split(","))
|
|
|
- .map(Long::valueOf)
|
|
|
- .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 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);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|