|
@@ -3898,13 +3898,15 @@ public R<Boolean> saveContractTreeNode(@RequestBody AddContractTreeNodeVO vo) {
|
|
|
saveList.addAll(customResult);
|
|
|
}
|
|
|
//找到最顶级节点设置parentId
|
|
|
- WbsTreeContract topLevelNode = findTopLevelNode(saveList);
|
|
|
- if (ObjectUtils.isNotEmpty(topLevelNode)) {
|
|
|
+ List<WbsTreeContract> topLevelNode = findTopLevelNode(saveList);
|
|
|
+ if (CollectionUtil.isNotEmpty(topLevelNode)) {
|
|
|
for (WbsTreeContract wbsTreeContract : saveList) {
|
|
|
- if (topLevelNode.getPKeyId().equals(wbsTreeContract.getPKeyId())) {
|
|
|
- wbsTreeContract.setParentId(treeContract.getId());
|
|
|
- //TODO 20250414-lhb-新增
|
|
|
- wbsTreeContract.setPId(treeContract.getPKeyId());
|
|
|
+ for (WbsTreeContract contract : topLevelNode) {
|
|
|
+ if (contract.getPKeyId().equals(wbsTreeContract.getPKeyId())) {
|
|
|
+ wbsTreeContract.setParentId(treeContract.getId());
|
|
|
+ //TODO 20250414-lhb-新增
|
|
|
+ wbsTreeContract.setPId(treeContract.getPKeyId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -3935,16 +3937,20 @@ public R<String> getDICengNodeName(@RequestParam Long pKeyId,@RequestParam Long
|
|
|
return R.data("");
|
|
|
}
|
|
|
|
|
|
-public static WbsTreeContract findTopLevelNode(List<WbsTreeContract> saveList) {
|
|
|
+public static List<WbsTreeContract> findTopLevelNode(List<WbsTreeContract> saveList) {
|
|
|
Set<Long> nodeIds = new HashSet<>();
|
|
|
for (WbsTreeContract node : saveList) {
|
|
|
nodeIds.add(node.getId());
|
|
|
}
|
|
|
+ List<WbsTreeContract> parentNodes = new ArrayList<>();
|
|
|
for (WbsTreeContract node : saveList) {
|
|
|
if (!nodeIds.contains(node.getParentId())) {
|
|
|
- return node;
|
|
|
+ parentNodes.add(node);
|
|
|
}
|
|
|
}
|
|
|
+ if(CollectionUtil.isNotEmpty(parentNodes)){
|
|
|
+ return parentNodes;
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -4821,23 +4827,29 @@ public R<Object> customAddContractNode(@RequestBody CustomAddContractNodeDTO dto
|
|
|
|
|
|
public void attachNodesToTarget(List<WbsTreeContract> newNodes, Long targetId, String targetAncestors) {
|
|
|
// 1. 找到新数据中的顶层节点(新树的根节点)
|
|
|
- WbsTreeContract newRoot = findRootNode(newNodes);
|
|
|
+ List<WbsTreeContract> newRoot = findRootNode(newNodes);
|
|
|
|
|
|
// 2. 将新树的根节点绑定到目标节点
|
|
|
- newRoot.setPId(targetId);
|
|
|
- newRoot.setAncestorsPId(calculateAncestors(targetAncestors, targetId));
|
|
|
+ newRoot.forEach(f -> {
|
|
|
+ f.setPId(targetId);
|
|
|
+ f.setAncestorsPId(calculateAncestors(targetAncestors, targetId));
|
|
|
+
|
|
|
+
|
|
|
+ // 3. 构建映射关系
|
|
|
+ Map<Long, WbsTreeContract> nodeMap = new HashMap<>();
|
|
|
+ Map<Long, List<WbsTreeContract>> childrenMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (WbsTreeContract node : newNodes) {
|
|
|
+ nodeMap.put(node.getPKeyId(), node);
|
|
|
+ childrenMap.computeIfAbsent(node.getPId(), k -> new ArrayList<>()).add(node);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 安全层序遍历(带循环检测)
|
|
|
+ safeBfsTraversal(f, childrenMap, childrenMap.get(f.getPKeyId()).size());
|
|
|
+ });
|
|
|
|
|
|
- // 3. 构建映射关系
|
|
|
- Map<Long, WbsTreeContract> nodeMap = new HashMap<>();
|
|
|
- Map<Long, List<WbsTreeContract>> childrenMap = new HashMap<>();
|
|
|
|
|
|
- for (WbsTreeContract node : newNodes) {
|
|
|
- nodeMap.put(node.getPKeyId(), node);
|
|
|
- childrenMap.computeIfAbsent(node.getPId(), k -> new ArrayList<>()).add(node);
|
|
|
- }
|
|
|
|
|
|
- // 4. 安全层序遍历(带循环检测)
|
|
|
- safeBfsTraversal(newRoot, childrenMap, newNodes.size());
|
|
|
}
|
|
|
|
|
|
private void safeBfsTraversal(WbsTreeContract root,
|
|
@@ -4898,19 +4910,22 @@ public R<Object> customAddContractNode(@RequestBody CustomAddContractNodeDTO dto
|
|
|
return parentAncestors + "," + parentId;
|
|
|
}
|
|
|
|
|
|
- private WbsTreeContract findRootNode(List<WbsTreeContract> nodes) {
|
|
|
+ private List<WbsTreeContract> findRootNode(List<WbsTreeContract> nodes) {
|
|
|
Set<Long> nodeIds = new HashSet<>();
|
|
|
for (WbsTreeContract node : nodes) {
|
|
|
nodeIds.add(node.getPKeyId());
|
|
|
}
|
|
|
-
|
|
|
+ List<WbsTreeContract> parentNodes = new ArrayList<>();
|
|
|
for (WbsTreeContract node : nodes) {
|
|
|
Long parentId = node.getPId();
|
|
|
// 父节点为空 或 父节点不在当前新数据列表中 → 视为根节点
|
|
|
if (parentId == null || !nodeIds.contains(parentId)) {
|
|
|
- return node;
|
|
|
+ parentNodes.add(node);
|
|
|
}
|
|
|
}
|
|
|
+ if (CollectionUtil.isNotEmpty(parentNodes)) {
|
|
|
+ return parentNodes;
|
|
|
+ }
|
|
|
throw new IllegalArgumentException("新数据中未找到根节点");
|
|
|
}
|
|
|
}
|