|
@@ -2009,13 +2009,20 @@ public R<Boolean> copyContractTreeNode(@RequestBody CopyContractTreeNodeVO vo) {
|
|
|
}
|
|
|
|
|
|
//TODO 20250414-lhb-新增 添加祖级字段 ancestorsPId
|
|
|
- List<WbsTreeContract> contractWbsTreeByContractId = wbsTreeContractClient.getContractWbsTreeByContractId(Long.valueOf(needCopyNode.getContractId()));
|
|
|
- contractWbsTreeByContractId.addAll(saveList);
|
|
|
- Map<Long, WbsTreeContract> collect = contractWbsTreeByContractId.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, Function.identity()));
|
|
|
- saveList.forEach(node -> {
|
|
|
- String correctAncestors = createAncestorsPId(node,collect);;
|
|
|
- node.setAncestorsPId(correctAncestors);
|
|
|
- });
|
|
|
+ //因为复制选中节点,所以要查询出选中节点的父节点信息 来组装祖级节点
|
|
|
+ if(needCopyNode != null){
|
|
|
+ Long parentPKeyId = null;
|
|
|
+ String ancestorsPId = null;
|
|
|
+ if(needCopyNode.getPId() == 0L){
|
|
|
+ ancestorsPId = "0";
|
|
|
+ parentPKeyId = 0L;
|
|
|
+ }else{
|
|
|
+ WbsTreeContract parentNode = this.wbsTreeContractClient.getContractNodeByPrimaryKeyId(String.valueOf(needCopyNode.getPId()));
|
|
|
+ ancestorsPId = parentNode.getAncestorsPId();
|
|
|
+ parentPKeyId = parentNode.getPKeyId();
|
|
|
+ }
|
|
|
+ attachNodesToTarget(saveList,parentPKeyId,ancestorsPId);
|
|
|
+ }
|
|
|
}
|
|
|
needCopyNode.setNodeName(vo.getNeedCopyNodeName());
|
|
|
|
|
@@ -2183,6 +2190,26 @@ public R<Boolean> copyContractTreeNode(@RequestBody CopyContractTreeNodeVO vo) {
|
|
|
this.addCopyTabData(needCopyNode, toCopyNode, tabOwner, resultTablesData, addTabList, vo.getIsCopyData(), addNewFileTabs);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /*重构祖级id*/
|
|
|
+ List<WbsTreeContract> resultAll = new ArrayList<>();
|
|
|
+ resultAll.addAll(addNodeList);
|
|
|
+ resultAll.addAll(addTabList);
|
|
|
+ //因为复制选中节点,所以要查询出选中节点的父节点信息 来组装祖级节点
|
|
|
+ if(needCopyNode != null && CollectionUtil.isNotEmpty(resultAll)){
|
|
|
+ Long parentPKeyId = null;
|
|
|
+ String ancestorsPId = null;
|
|
|
+ if(needCopyNode.getPId() == 0L){
|
|
|
+ ancestorsPId = "0";
|
|
|
+ parentPKeyId = 0L;
|
|
|
+ }else{
|
|
|
+ WbsTreeContract parentNode = this.wbsTreeContractClient.getContractNodeByPrimaryKeyId(String.valueOf(toCopyVO.getPrimaryKeyId()));
|
|
|
+ ancestorsPId = parentNode.getAncestorsPId();
|
|
|
+ parentPKeyId = parentNode.getPKeyId();
|
|
|
+ }
|
|
|
+ attachNodesToTarget(resultAll,parentPKeyId,ancestorsPId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -2192,14 +2219,6 @@ public R<Boolean> copyContractTreeNode(@RequestBody CopyContractTreeNodeVO vo) {
|
|
|
resultAll.addAll(addNodeList);
|
|
|
resultAll.addAll(addTabList);
|
|
|
|
|
|
- //TODO 20250414-lhb-新增
|
|
|
- List<WbsTreeContract> contractWbsTreeByContractId = wbsTreeContractClient.getContractWbsTreeByContractId(Long.valueOf(contractId));
|
|
|
- contractWbsTreeByContractId.addAll(resultAll);
|
|
|
- Map<Long, WbsTreeContract> collect = contractWbsTreeByContractId.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, Function.identity()));
|
|
|
- resultAll.forEach(node -> {
|
|
|
- String correctAncestors = createAncestorsPId(node,collect);;
|
|
|
- node.setAncestorsPId(correctAncestors);
|
|
|
- });
|
|
|
|
|
|
List<WbsTreeContract> allData = this.reBuildAncestors(resultAll);
|
|
|
List<WbsTreeContract> nodes = allData.stream().filter(f -> f.getType().equals(1)).collect(Collectors.toList());
|
|
@@ -4958,7 +4977,7 @@ public R<Object> customAddContractNode(@RequestBody CustomAddContractNodeDTO dto
|
|
|
List<WbsTreeContract> list = childrenMap.get(f.getPKeyId());
|
|
|
if(CollectionUtil.isNotEmpty(list)){
|
|
|
//如果是多个根节点
|
|
|
- safeBfsTraversal(f, childrenMap, newRoot.size() > 1 ? list.size() : newNodes.size());
|
|
|
+ safeBfsTraversal(f, childrenMap, newNodes.size());
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -4983,13 +5002,13 @@ public R<Object> customAddContractNode(@RequestBody CustomAddContractNodeDTO dto
|
|
|
|
|
|
// 安全检测1:防止循环引用导致无限循环
|
|
|
if (processedCount > totalNodes * 2) {
|
|
|
- throw new IllegalStateException("处理节点数超过预期,可能存在循环引用。已处理: "
|
|
|
+ throw new ServiceException("处理节点数超过预期,可能存在循环引用。已处理: "
|
|
|
+ processedCount + ",总节点: " + totalNodes);
|
|
|
}
|
|
|
|
|
|
// 安全检测2:防止路径过长
|
|
|
if (parent.getAncestorsPId().split(",").length > MAX_DEPTH) {
|
|
|
- throw new IllegalStateException("祖级路径超过最大深度限制: " + MAX_DEPTH);
|
|
|
+ throw new ServiceException("祖级路径超过最大深度限制: " + MAX_DEPTH);
|
|
|
}
|
|
|
|
|
|
List<WbsTreeContract> children = childrenMap.get(parent.getPKeyId());
|
|
@@ -4998,7 +5017,7 @@ public R<Object> customAddContractNode(@RequestBody CustomAddContractNodeDTO dto
|
|
|
for (WbsTreeContract child : children) {
|
|
|
// 安全检测3:检查循环引用
|
|
|
if (visited.contains(child.getPKeyId())) {
|
|
|
- throw new IllegalStateException("检测到循环引用: 节点" + child.getPKeyId()
|
|
|
+ throw new ServiceException("检测到循环引用: 节点" + child.getPKeyId()
|
|
|
+ " -> 节点" + parent.getPKeyId());
|
|
|
}
|
|
|
|
|
@@ -5010,11 +5029,6 @@ public R<Object> customAddContractNode(@RequestBody CustomAddContractNodeDTO dto
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 验证是否处理了所有节点
|
|
|
- if (processedCount < totalNodes) {
|
|
|
- throw new IllegalStateException("存在未处理的节点,可能是不连通的子树。已处理: "
|
|
|
- + processedCount + ",总节点: " + totalNodes);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private String calculateAncestors(String parentAncestors, Long parentId) {
|