|
@@ -29,6 +29,7 @@ import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.manager.utils.DiffListUtil;
|
|
|
import org.springblade.manager.utils.WbsElementUtil;
|
|
|
import org.springblade.manager.vo.*;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -598,6 +599,81 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean copyNode(List<String> leftIds, List<String> rightIds) {
|
|
|
+ List<WbsTree> leftLists = baseMapper.selectAllChildNode(leftIds);
|
|
|
+ for (String rightId : rightIds) {
|
|
|
+ // 每次循环都创建一个新的集合作为副本
|
|
|
+ List<WbsTree> workingList = leftLists.stream()
|
|
|
+ .map(node -> {
|
|
|
+ // 创建每个节点的副本
|
|
|
+ WbsTree copy = new WbsTree();
|
|
|
+ BeanUtils.copyProperties(copy, node);
|
|
|
+ return copy;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ WbsTree rightWbsTree = baseMapper.selectById(Long.parseLong(rightId));
|
|
|
+
|
|
|
+ // 找到leftLists中所有的根节点(没有在leftLists中作为子节点出现的节点)
|
|
|
+ Set<Long> allPIds = workingList.stream()
|
|
|
+ .map(WbsTree::getParentId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<WbsTree> rootNodes = workingList.stream()
|
|
|
+ .filter(node -> !allPIds.contains(node.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 为每个根节点重新设置属性,并将其放到rightWbsTreePrivate节点下
|
|
|
+ for (WbsTree rootNode : rootNodes) {
|
|
|
+ // 重新分配节点值
|
|
|
+ reassignNodeValues(workingList, rootNode, rightWbsTree);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 添加一个辅助方法来重新分配节点值
|
|
|
+ private void reassignNodeValues(List<WbsTree> leftLists, WbsTree rootNode, WbsTree rightWbsTree) {
|
|
|
+ // 创建节点映射以便快速查找
|
|
|
+ Map<Long, WbsTree> nodeMap = leftLists.stream()
|
|
|
+ .collect(Collectors.toMap(WbsTree::getId, node -> node));
|
|
|
+
|
|
|
+ // 为根节点生成新的随机ID
|
|
|
+ Long newRootId = SnowFlakeUtil.getId();
|
|
|
+ // 设置根节点属性,使其成为rightWbsTreePrivate的子节点
|
|
|
+ rootNode.setId(newRootId);
|
|
|
+ rootNode.setParentId(rightWbsTree.getId());
|
|
|
+ // ancestors设置为rightWbsTreePrivate的ancestors加上rightWbsTreePrivate的id
|
|
|
+ if (rightWbsTree.getAncestors() != null && !rightWbsTree.getAncestors().isEmpty()) {
|
|
|
+ rootNode.setAncestors(rightWbsTree.getAncestors() + "," + rightWbsTree.getId());
|
|
|
+ } else {
|
|
|
+ rootNode.setAncestors(String.valueOf(rightWbsTree.getId()));
|
|
|
+ }
|
|
|
+ // 更新所有子节点
|
|
|
+ updateChildNodes(nodeMap, rootNode, rootNode.getAncestors());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 递归更新子节点属性
|
|
|
+ private void updateChildNodes(Map<Long, WbsTree> nodeMap, WbsTree parentNode, String parentAncestors) {
|
|
|
+ // 查找当前节点的所有直接子节点(通过pId匹配父节点的pKeyId)
|
|
|
+ List<WbsTree> childNodes = nodeMap.values().stream()
|
|
|
+ .filter(node -> node.getParentId() != null && node.getParentId().equals(parentNode.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 更新每个子节点的属性
|
|
|
+ for (WbsTree childNode : childNodes) {
|
|
|
+ // 为子节点生成新的随机ID
|
|
|
+ Long newChildId = SnowFlakeUtil.getId();
|
|
|
+ // id设置为新的随机ID
|
|
|
+ childNode.setId(newChildId);
|
|
|
+ // parentId设置为父节点的id
|
|
|
+ childNode.setParentId(parentNode.getId());
|
|
|
+ // ancestors设置为父节点的ancestors加上父节点的id
|
|
|
+ childNode.setAncestors(parentAncestors + "," + parentNode.getId());
|
|
|
+ // 递归更新孙子节点
|
|
|
+ updateChildNodes(nodeMap, childNode, childNode.getAncestors());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 公有排序
|
|
|
*/
|