|
@@ -3209,25 +3209,35 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
public boolean copyNode(List<String> leftIds, List<String> rightIds) {
|
|
|
List<WbsTreePrivate> leftLists = baseMapper.selectAllChildNode(leftIds);
|
|
|
for (String rightId : rightIds) {
|
|
|
+ // 每次循环都创建一个新的集合作为副本
|
|
|
+ List<WbsTreePrivate> workingList = leftLists.stream()
|
|
|
+ .map(node -> {
|
|
|
+ // 创建每个节点的副本
|
|
|
+ WbsTreePrivate copy = new WbsTreePrivate();
|
|
|
+ BeanUtils.copyProperties(copy, node);
|
|
|
+ return copy;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
WbsTreePrivate rightWbsTreePrivate = baseMapper.getByPKeyId(Long.parseLong(rightId));
|
|
|
|
|
|
// 找到leftLists中所有的根节点(没有在leftLists中作为子节点出现的节点)
|
|
|
- Set<Long> allPIds = leftLists.stream()
|
|
|
+ Set<Long> allPIds = workingList.stream()
|
|
|
.map(WbsTreePrivate::getPId)
|
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
- List<WbsTreePrivate> rootNodes = leftLists.stream()
|
|
|
+ List<WbsTreePrivate> rootNodes = workingList.stream()
|
|
|
.filter(node -> !allPIds.contains(node.getPKeyId()))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
// 为每个根节点重新设置属性,并将其放到rightWbsTreePrivate节点下
|
|
|
for (WbsTreePrivate rootNode : rootNodes) {
|
|
|
// 重新分配节点值
|
|
|
- reassignNodeValues(leftLists, rootNode, rightWbsTreePrivate);
|
|
|
+ reassignNodeValues(workingList, rootNode, rightWbsTreePrivate);
|
|
|
}
|
|
|
+ this.insertBatch(workingList,500);
|
|
|
}
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
// 添加一个辅助方法来重新分配节点值
|
|
|
private void reassignNodeValues(List<WbsTreePrivate> leftLists, WbsTreePrivate rootNode, WbsTreePrivate rightWbsTreePrivate) {
|