|
@@ -1536,283 +1536,6 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 多节点同步
|
|
|
- *
|
|
|
- * @param primaryKeyId
|
|
|
- * @param projectId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public boolean syncNodeTable(String primaryKeyId, String projectId) {
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(primaryKeyId)) {
|
|
|
- //获取当前节点对应节点信息
|
|
|
- WbsTreePrivate wbsTreePrivate = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, primaryKeyId));
|
|
|
-
|
|
|
- //获取项目信息
|
|
|
- ProjectInfo projectInfo = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery().eq(ProjectInfo::getId, wbsTreePrivate.getProjectId()));
|
|
|
-
|
|
|
- //当前项目模板对应的节点信息
|
|
|
-
|
|
|
- List<WbsTreePrivate> templateNodes = new ArrayList<>();
|
|
|
-
|
|
|
- //结果集
|
|
|
- List<WbsTreePrivate> addData = new ArrayList<>();
|
|
|
- List<WbsTreePrivate> editData = new ArrayList<>();
|
|
|
- //质检
|
|
|
- //当前节点引用的模板为公有模板
|
|
|
-
|
|
|
- if (("public").equals(projectInfo.getReferenceWbsTemplateType())) {
|
|
|
- //当前节点对应的模板节点信息
|
|
|
- WbsTree wbsTreeTemplate = wbsTreeMapper.selectOne(Wrappers.<WbsTree>lambdaQuery()
|
|
|
- .eq(WbsTree::getId, wbsTreePrivate.getTreePId()));
|
|
|
-
|
|
|
- //模板节点的所有子节点信息
|
|
|
- List<WbsTree> wbsTrees = null;
|
|
|
- //当前节点信息
|
|
|
-
|
|
|
- //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
- LambdaQueryWrapper<WbsTree> wrapperTree = Wrappers.lambdaQuery();
|
|
|
- wrapperTree.eq(WbsTree::getWbsId, wbsTreePrivate.getWbsId())
|
|
|
- .eq(WbsTree::getIsDeleted, 0);
|
|
|
- if (wbsTreeTemplate.getParentId() != 0) {
|
|
|
- wrapperTree.apply("FIND_IN_SET({0},ancestors)", wbsTreeTemplate.getId());
|
|
|
- }
|
|
|
- wbsTrees = wbsTreeMapper.selectList(wrapperTree);
|
|
|
- //3、获取需要新增的节点或者表单节点信息 以及他们对应的父级节点信息--------------------------------------------------------------------------------------------
|
|
|
- if (CollectionUtil.isEmpty(wbsTrees)) {
|
|
|
- throw new ServiceException("模板节点未找到");
|
|
|
- }
|
|
|
- wbsTrees.add(wbsTreeTemplate);
|
|
|
- templateNodes = BeanUtil.copyProperties(wbsTrees, WbsTreePrivate.class);
|
|
|
-
|
|
|
-
|
|
|
- } else if (("private").equals(projectInfo.getReferenceWbsTemplateType())) {
|
|
|
- //根据wbsTreePrivate的wbsId=私有引用的pKeyId来获取引用树根节点
|
|
|
- WbsTreePrivate wbsTreePrivateRoot = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
- .eq(WbsTreePrivate::getPKeyId, wbsTreePrivate.getWbsId()));
|
|
|
-
|
|
|
- //获取当前选中节点与私有模板对应的节点信息 父级模板项目的当前选中节点
|
|
|
- wbsTreePrivateRoot = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
- .eq(WbsTreePrivate::getProjectId, wbsTreePrivateRoot.getProjectId())
|
|
|
- .eq(WbsTreePrivate::getTreePId, wbsTreePrivate.getTreePId()));
|
|
|
-
|
|
|
- //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
- LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
|
|
|
- wrapperPrivate.eq(WbsTreePrivate::getProjectId, wbsTreePrivateRoot.getProjectId())
|
|
|
- .eq(WbsTreePrivate::getIsDeleted, 0);
|
|
|
- //判断如果为顶级顶级节点
|
|
|
- if (wbsTreePrivate.getTreePId() != 0) {
|
|
|
- wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivateRoot.getPKeyId());
|
|
|
- }
|
|
|
- templateNodes = baseMapper.selectList(wrapperPrivate);
|
|
|
- templateNodes.add(wbsTreePrivate);
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtil.isEmpty(templateNodes)) {
|
|
|
- throw new ServiceException("未找到模板对应节点");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //2、获取当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
- LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
|
|
|
- wrapperPrivate.eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId()).eq(WbsTreePrivate::getIsDeleted, 0);
|
|
|
- //判断如果为顶级顶级节点
|
|
|
- if (wbsTreePrivate.getTreePId() != 0) {
|
|
|
- wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPKeyId());
|
|
|
- }
|
|
|
- List<WbsTreePrivate> wbsTreePrivates = baseMapper.selectList(wrapperPrivate);
|
|
|
- wbsTreePrivates.add(wbsTreePrivate);
|
|
|
- if (wbsTreePrivates.isEmpty()) {
|
|
|
- throw new ServiceException("无法找到模板对应节点,请检查模板节点");
|
|
|
- }
|
|
|
- //获取id 和 tree_p_id 组成的集合
|
|
|
- Set<Long> ids = wbsTreePrivates.stream().map(WbsTreePrivate::getTreePId).collect(Collectors.toSet());
|
|
|
- //3.1筛选出需要新增的节点
|
|
|
- List<WbsTreePrivate> addPrivateNodes = templateNodes.stream()
|
|
|
- .filter(f -> !ids.contains(f.getId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- //3.2筛选出需要修改的节点
|
|
|
- List<WbsTreePrivate> editPrivateNodes = templateNodes.stream()
|
|
|
- .filter(f -> ids.contains(f.getId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
-
|
|
|
- //------------------------------------------------新增-------------------------------------------------------------------------
|
|
|
- if (CollectionUtil.isNotEmpty(addPrivateNodes)) {
|
|
|
- //将要新增的项目节点----------------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- //先给每个新增节点赋唯一id,项目id,父级id
|
|
|
- addPrivateNodes.forEach(f -> f.setPKeyId(SnowFlakeUtil.getId()));
|
|
|
-
|
|
|
- //给每一个节点的父级id
|
|
|
- for (WbsTreePrivate addPrivateNode : addPrivateNodes) {
|
|
|
- if (addPrivateNode.getParentId() == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //查询出当前模板节点的父节点 去获取对应项目节点 如果父节点为0就跳过
|
|
|
- List<WbsTreePrivate> addPrivateParentNodes = wbsTreePrivates.stream().filter(f -> f.getTreePId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
|
|
|
- //如果没有数据 就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
|
|
|
- if (addPrivateParentNodes.isEmpty()) {
|
|
|
- addPrivateParentNodes = addPrivateNodes.stream().filter(f -> f.getId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
|
|
|
- }
|
|
|
- //如果现在还找不到当前节点的父节点就表示数据有问题
|
|
|
- if (addPrivateParentNodes.isEmpty()) {
|
|
|
- //TODO
|
|
|
- continue;
|
|
|
- }
|
|
|
- //当前新增节点的父节点
|
|
|
- WbsTreePrivate parent = addPrivateParentNodes.get(0);
|
|
|
-
|
|
|
- addPrivateNode.setPId(parent.getPKeyId());
|
|
|
- addPrivateNode.setWbsType(wbsTreePrivate.getWbsType());
|
|
|
- addPrivateNode.setIsAddConceal(0);
|
|
|
- addPrivateNode.setProjectId(wbsTreePrivate.getProjectId());
|
|
|
- //TODO 后续如果把p_key_id改成了id做 唯一id
|
|
|
- addPrivateNode.setTreePId(addPrivateNode.getId());
|
|
|
- //后续如果使用id做当前表主键 则先在赋值treePid之后再去赋值id addPrivateNode.setId(SnowFlakeUtil.getId());
|
|
|
- }
|
|
|
- addData.addAll(addPrivateNodes);
|
|
|
- }
|
|
|
-
|
|
|
- //------------------------------------------------编辑-------------------------------------------------------------------------
|
|
|
- /**
|
|
|
- * 编辑情况下
|
|
|
- * type == 1 修改基础信息
|
|
|
- * type == 2
|
|
|
- */
|
|
|
- if (CollectionUtil.isNotEmpty(editPrivateNodes)) {
|
|
|
- Map<Long, WbsTreePrivate> editMap = wbsTreePrivates.stream().collect(Collectors.toMap(WbsTreePrivate::getId, Function.identity()));
|
|
|
- for (WbsTreePrivate editNode : editPrivateNodes) {
|
|
|
- //获取旧节点
|
|
|
- WbsTreePrivate oldNode = editMap.get(editNode.getId());
|
|
|
- //
|
|
|
- if (oldNode == null) {
|
|
|
- throw new ServiceException("数据问题");
|
|
|
- }
|
|
|
-
|
|
|
- oldNode.setNodeType(editNode.getNodeType());
|
|
|
- oldNode.setNodeName(editNode.getNodeName());
|
|
|
- oldNode.setSort(editNode.getSort());
|
|
|
- oldNode.setRemark(editNode.getRemark());
|
|
|
- oldNode.setInitTableId(editNode.getInitTableId());
|
|
|
- oldNode.setExcelId(editNode.getExcelId());
|
|
|
- oldNode.setIsExistForm(editNode.getIsExistForm());
|
|
|
- oldNode.setHtmlUrl(editNode.getHtmlUrl());
|
|
|
- oldNode.setFillRate(editNode.getFillRate());
|
|
|
-
|
|
|
-
|
|
|
- //普通节点
|
|
|
- if (editNode.getType() == 1) {
|
|
|
- //判断是否被修改过
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- //元素表单节点
|
|
|
- if (editNode.getType() == 2) {
|
|
|
- //判断是否关联过清表
|
|
|
- if(oldNode.getIsLinkTable() == 2){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- //是否需要编辑元素表单数据???
|
|
|
- editData.add(oldNode);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //设置html_url----------------------------------------------------------------------------------------------------------
|
|
|
- //如果有新增的数据 旧设置html_url
|
|
|
- if (CollectionUtil.isNotEmpty(addData)) {
|
|
|
- try {
|
|
|
- String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
- Set<String> urls = new HashSet<>();
|
|
|
- for (WbsTreePrivate tree : addData) {
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotBlank(tree.getHtmlUrl())) {
|
|
|
- String[] split = tree.getHtmlUrl().split("/");
|
|
|
- String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
|
|
|
- if (!urls.contains(tree.getHtmlUrl())) {
|
|
|
- urls.add(tree.getHtmlUrl());
|
|
|
- File file_in = ResourceUtil.getFile(tree.getHtmlUrl());
|
|
|
- if (!file_in.exists() || file_in.length() == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- File file_out = ResourceUtil.getFile(htmlUrl);
|
|
|
- FileUtil.copy(file_in, file_out);
|
|
|
- }
|
|
|
- tree.setHtmlUrl(htmlUrl);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("重置表单路径错误");
|
|
|
- }
|
|
|
- //查询出当前项目所有节点---------------------------------------------------------------------------------------------------
|
|
|
- List<WbsTreePrivate> addList = baseMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
- .eq(WbsTreePrivate::getIsDeleted, 0)
|
|
|
- .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId()));
|
|
|
-
|
|
|
- addList.addAll(addData);
|
|
|
- //组合祖级路径 根据当前选中节点为开始
|
|
|
- Map<Long, WbsTreePrivate> collect = addList.stream().collect(Collectors.toMap(WbsTreePrivate::getPKeyId, Function.identity()));
|
|
|
-
|
|
|
- addData.forEach(node -> {
|
|
|
- String correctAncestors = createAncestorsPId(node, collect);
|
|
|
- node.setAncestorsPId(correctAncestors);
|
|
|
- });
|
|
|
-
|
|
|
- //新增-----------------------------------------------------------------------------------------------------------------
|
|
|
- List<List<WbsTreePrivate>> partition = Lists.partition(addData, 1000);
|
|
|
- for (List<WbsTreePrivate> data : partition) {
|
|
|
- //单个批次一个事务,只会回滚当前批次数据
|
|
|
- boolean b = this.insertBatch(data, 1000);
|
|
|
- //如果失败 -- - - - - 继续执行 或者把当前节点的p_key_id 记录到某个地方 方便后续处理
|
|
|
- if (!b) {
|
|
|
- List<Long> collect1 = addData.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
|
|
|
- //这里可以保存到数据库指定错误日志表
|
|
|
-
|
|
|
- throw new ServiceException("新增节点失败,请联系后台人员");
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (CollectionUtil.isNotEmpty(editData)) {
|
|
|
-
|
|
|
- //修改-----------------------------------------------------------------------------------------------------------------
|
|
|
- List<List<WbsTreePrivate>> edits = Lists.partition(editData, 1000);
|
|
|
- for (List<WbsTreePrivate> data : edits) {
|
|
|
- //单个批次一个事务,只会回滚当前批次数据
|
|
|
- boolean b = this.saveOrUpdateBatch(data, 1000);
|
|
|
- //如果失败 -- - - - - 继续执行 或者把当前节点的p_key_id 记录到某个地方 方便后续处理
|
|
|
- if (!b) {
|
|
|
- //这里可以保存到数据库指定错误日志表
|
|
|
- throw new ServiceException("修改节点失败,请联系后台人员");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- throw new ServiceException("未传指定参数,请联系后台人员");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 同步指定节点数据到合同段
|
|
|
- */
|
|
|
- public void syncNodeTable(Long primaryKeyId) {
|
|
|
- //1、新增
|
|
|
- //2、修改排序、基础信息和地址
|
|
|
- if (primaryKeyId == null) {
|
|
|
- //获取当前节点对应节点信息
|
|
|
- WbsTreePrivate wbsTreePrivate = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, primaryKeyId));
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //获取当前节点下的数据
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public boolean syncNodeTable(String primaryKeyId) {
|
|
@@ -3730,55 +3453,4 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 20250414-lhb-新增
|
|
|
- * 创建祖级路径
|
|
|
- * <p>
|
|
|
- * 该方法用于构建给定节点的祖先路径标识符(PId)字符串
|
|
|
- * 它通过追溯节点的父节点,直到达到根节点或满足特定条件为止
|
|
|
- *
|
|
|
- * @param node WbsTreeContract类型的节点,表示需要构建路径的起始节点
|
|
|
- * @param nodeMap 一个映射,其键为节点ID,值为WbsTreeContract类型的节点对象,用于快速查找节点
|
|
|
- * @return 返回一个字符串,表示构建的祖先路径标识符序列,以逗号分隔
|
|
|
- */
|
|
|
- private String createAncestorsPId(WbsTreePrivate node, Map<Long, WbsTreePrivate> nodeMap) {
|
|
|
- // 初始化路径列表,用于存储祖先节点的ID
|
|
|
- List<Long> path = new ArrayList<>();
|
|
|
- // 从给定的节点开始
|
|
|
- WbsTreePrivate current = node;
|
|
|
- // 初始化访问集合,用于检测循环引用
|
|
|
- Set<Long> visited = new HashSet<>();
|
|
|
-
|
|
|
- while (true) {
|
|
|
- // 检查当前节点是否为根节点或无效节点
|
|
|
- if (current == null || current.getPId() == null ||
|
|
|
- current.getPId() == 0 || current.getPId().equals(current.getPKeyId())) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- // 检测循环引用
|
|
|
- if (visited.contains(current.getPId())) {
|
|
|
- break;
|
|
|
- }
|
|
|
- // 将当前节点的ID添加到已访问集合中
|
|
|
- visited.add(current.getPKeyId());
|
|
|
-
|
|
|
- // 从映射中获取当前节点的父节点
|
|
|
- current = nodeMap.get(current.getPId());
|
|
|
- // 如果父节点存在,则将其ID添加到路径列表的开头
|
|
|
- if (current != null) {
|
|
|
- path.add(0, current.getPKeyId());
|
|
|
- }
|
|
|
-
|
|
|
- // 安全限制,防止路径过长导致性能问题
|
|
|
- if (path.size() > 50) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- // 将根节点ID(0)添加到路径的最前面,表示路径的起点
|
|
|
- path.add(0, 0L);
|
|
|
- // 将路径列表转换为字符串并返回
|
|
|
- return String.join(",", path.stream().map(String::valueOf).toArray(String[]::new));
|
|
|
- }
|
|
|
}
|