|
@@ -3205,6 +3205,102 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
return baseMapper.getContractAllLogWbsNodeIds(contractId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean copyNode(List<String> leftIds, List<String> rightIds) {
|
|
|
+ List<WbsTreePrivate> leftLists = baseMapper.selectAllChildNode(leftIds);
|
|
|
+ for (String rightId : rightIds) {
|
|
|
+ WbsTreePrivate rightWbsTreePrivate = baseMapper.getByPKeyId(Long.parseLong(rightId));
|
|
|
+
|
|
|
+ // 找到leftLists中所有的根节点(没有在leftLists中作为子节点出现的节点)
|
|
|
+ Set<Long> allPIds = leftLists.stream()
|
|
|
+ .map(WbsTreePrivate::getPId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<WbsTreePrivate> rootNodes = leftLists.stream()
|
|
|
+ .filter(node -> !allPIds.contains(node.getPKeyId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 为每个根节点重新设置属性,并将其放到rightWbsTreePrivate节点下
|
|
|
+ for (WbsTreePrivate rootNode : rootNodes) {
|
|
|
+ // 重新分配节点值
|
|
|
+ reassignNodeValues(leftLists, rootNode, rightWbsTreePrivate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 添加一个辅助方法来重新分配节点值
|
|
|
+ private void reassignNodeValues(List<WbsTreePrivate> leftLists, WbsTreePrivate rootNode, WbsTreePrivate rightWbsTreePrivate) {
|
|
|
+ // 创建节点映射以便快速查找
|
|
|
+ Map<Long, WbsTreePrivate> nodeMap = leftLists.stream()
|
|
|
+ .collect(Collectors.toMap(WbsTreePrivate::getPKeyId, node -> node));
|
|
|
+
|
|
|
+ // 为根节点生成新的随机ID
|
|
|
+ Long newRootId = SnowFlakeUtil.getId();
|
|
|
+ Long newRootPKeyId = SnowFlakeUtil.getId();
|
|
|
+
|
|
|
+ // 设置根节点属性,使其成为rightWbsTreePrivate的子节点
|
|
|
+ rootNode.setId(newRootId);
|
|
|
+ rootNode.setPKeyId(newRootPKeyId);
|
|
|
+ rootNode.setParentId(rightWbsTreePrivate.getId());
|
|
|
+ rootNode.setPId(rightWbsTreePrivate.getPKeyId());
|
|
|
+
|
|
|
+ // ancestors设置为rightWbsTreePrivate的ancestors加上rightWbsTreePrivate的id
|
|
|
+ if (rightWbsTreePrivate.getAncestors() != null && !rightWbsTreePrivate.getAncestors().isEmpty()) {
|
|
|
+ rootNode.setAncestors(rightWbsTreePrivate.getAncestors() + "," + rightWbsTreePrivate.getId());
|
|
|
+ } else {
|
|
|
+ rootNode.setAncestors(String.valueOf(rightWbsTreePrivate.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ancestors_p_id设置为rightWbsTreePrivate的ancestors_p_id加上rightWbsTreePrivate的pKeyId
|
|
|
+ if (rightWbsTreePrivate.getAncestorsPId() != null && !rightWbsTreePrivate.getAncestorsPId().isEmpty()) {
|
|
|
+ rootNode.setAncestorsPId(rightWbsTreePrivate.getAncestorsPId() + "," + rightWbsTreePrivate.getPKeyId());
|
|
|
+ } else {
|
|
|
+ rootNode.setAncestorsPId(String.valueOf(rightWbsTreePrivate.getPKeyId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新所有子节点
|
|
|
+ updateChildNodes(nodeMap, rootNode, rootNode.getAncestors(), rootNode.getAncestorsPId(), newRootPKeyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 递归更新子节点属性
|
|
|
+ private void updateChildNodes(Map<Long, WbsTreePrivate> nodeMap, WbsTreePrivate parentNode, String parentAncestors, String parentAncestorsPId, Long parentPKeyId) {
|
|
|
+ // 查找当前节点的所有直接子节点(通过pId匹配父节点的pKeyId)
|
|
|
+ List<WbsTreePrivate> childNodes = nodeMap.values().stream()
|
|
|
+ .filter(node -> node.getPId() != null && node.getPId().equals(parentNode.getPKeyId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 更新每个子节点的属性
|
|
|
+ for (WbsTreePrivate childNode : childNodes) {
|
|
|
+ // 为子节点生成新的随机ID
|
|
|
+ Long newChildId = SnowFlakeUtil.getId();
|
|
|
+ Long newChildPKeyId = SnowFlakeUtil.getId();
|
|
|
+
|
|
|
+ // id设置为新的随机ID
|
|
|
+ childNode.setId(newChildId);
|
|
|
+
|
|
|
+ // pKeyId设置为新的随机ID
|
|
|
+ childNode.setPKeyId(newChildPKeyId);
|
|
|
+
|
|
|
+ // parentId设置为父节点的id
|
|
|
+ childNode.setParentId(parentNode.getId());
|
|
|
+
|
|
|
+ // pId设置为父节点的pKeyId
|
|
|
+ childNode.setPId(parentPKeyId);
|
|
|
+
|
|
|
+ // ancestors设置为父节点的ancestors加上父节点的id
|
|
|
+ childNode.setAncestors(parentAncestors + "," + parentNode.getId());
|
|
|
+
|
|
|
+ // ancestors_p_id设置为父节点的ancestors_p_id加上父节点的pKeyId
|
|
|
+ childNode.setAncestorsPId(parentAncestorsPId + "," + parentPKeyId);
|
|
|
+
|
|
|
+ // 递归更新孙子节点
|
|
|
+ updateChildNodes(nodeMap, childNode, childNode.getAncestors(), childNode.getAncestorsPId(), newChildPKeyId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public void diGuiWbs(int i) {
|
|
|
QueryWrapper<WbsTreePrivate> wbsTreePrivateQueryWrapper = new QueryWrapper<>();
|
|
|
wbsTreePrivateQueryWrapper.select("p_key_id", "id", "p_id", "wbs_id", "project_id", "parent_id", "ancestors");
|