|
@@ -208,6 +208,150 @@ public class ArchiveNameServiceImpl implements IArchiveNameService {
|
|
|
// 1. 获取输入节点
|
|
|
Map<Long, ArchiveTreeContract> allNodeMap = hierarchy.getAllNodeMap();
|
|
|
List<ArchiveTreeContract> nodes = new ArrayList<>();
|
|
|
+ for (Long nodeId : nodeIds) {
|
|
|
+ ArchiveTreeContract node = allNodeMap.get(nodeId);
|
|
|
+ if (node != null) {
|
|
|
+ nodes.add(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nodes.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 按父节点分组 (一级分组)
|
|
|
+ Map<Long, List<ArchiveTreeContract>> parentGroups = new LinkedHashMap<>();
|
|
|
+ for (ArchiveTreeContract node : nodes) {
|
|
|
+ Long parentId = node.getParentId();
|
|
|
+ if (parentId == null) {
|
|
|
+ parentGroups.put(node.getId(), Collections.singletonList(node));
|
|
|
+ } else {
|
|
|
+ parentGroups.computeIfAbsent(parentId, k -> new ArrayList<>()).add(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 按祖父节点分组 (二级分组)
|
|
|
+ Map<Long, List<Map.Entry<Long, List<ArchiveTreeContract>>>> grandParentGroups = new LinkedHashMap<>();
|
|
|
+ for (Map.Entry<Long, List<ArchiveTreeContract>> entry : parentGroups.entrySet()) {
|
|
|
+ Long parentId = entry.getKey();
|
|
|
+ ArchiveTreeContract parentNode = allNodeMap.get(parentId);
|
|
|
+ Long grandParentId = (parentNode != null) ? parentNode.getParentId() : null;
|
|
|
+ grandParentGroups.computeIfAbsent(grandParentId, k -> new ArrayList<>()).add(entry);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 处理分组
|
|
|
+ List<String> nameParts = new ArrayList<>();
|
|
|
+ for (Map.Entry<Long, List<Map.Entry<Long, List<ArchiveTreeContract>>>> grandEntry : grandParentGroups.entrySet()) {
|
|
|
+ Long grandParentId = grandEntry.getKey();
|
|
|
+ List<Map.Entry<Long, List<ArchiveTreeContract>>> directParentGroups = grandEntry.getValue();
|
|
|
+
|
|
|
+ // 尝试在祖父节点级别合并
|
|
|
+ boolean canUseGrandParentName = false;
|
|
|
+ if (grandParentId != null) {
|
|
|
+ ArchiveTreeContract grandParentNode = allNodeMap.get(grandParentId);
|
|
|
+ if (grandParentNode != null) {
|
|
|
+ // 获取祖父节点的所有直接子节点
|
|
|
+ List<ArchiveTreeContract> grandChildren = hierarchy.getChildren(grandParentId);
|
|
|
+ if (grandChildren != null && !grandChildren.isEmpty()) {
|
|
|
+ // 检查是否覆盖所有直接子节点
|
|
|
+ boolean allChildrenCovered = true;
|
|
|
+ Set<Long> coveredParentIds = new HashSet<>();
|
|
|
+ for (Map.Entry<Long, List<ArchiveTreeContract>> directEntry : directParentGroups) {
|
|
|
+ coveredParentIds.add(directEntry.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证所有子节点都被覆盖
|
|
|
+ for (ArchiveTreeContract child : grandChildren) {
|
|
|
+ if (!coveredParentIds.contains(child.getId())) {
|
|
|
+ allChildrenCovered = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证每个被覆盖的子节点组是否都是全覆盖状态
|
|
|
+ if (allChildrenCovered) {
|
|
|
+ boolean allGroupsFullyCovered = true;
|
|
|
+ for (Map.Entry<Long, List<ArchiveTreeContract>> directEntry : directParentGroups) {
|
|
|
+ List<ArchiveTreeContract> groupNodes = directEntry.getValue();
|
|
|
+ // 获取该父节点的所有子节点
|
|
|
+ List<ArchiveTreeContract> childrenOfParent = hierarchy.getChildren(directEntry.getKey());
|
|
|
+ int childrenCount = (childrenOfParent != null) ? childrenOfParent.size() : 0;
|
|
|
+
|
|
|
+ // 检查是否全覆盖
|
|
|
+ if (childrenCount == 0 || groupNodes.size() != childrenCount) {
|
|
|
+ allGroupsFullyCovered = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (allGroupsFullyCovered) {
|
|
|
+ nameParts.add(getLevelName(hierarchy, grandParentId));
|
|
|
+ canUseGrandParentName = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (canUseGrandParentName) {
|
|
|
+ continue; // 已使用祖父节点名称,跳过直接父节点处理
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理直接父节点组
|
|
|
+ boolean firstParentInGroup = true;
|
|
|
+ for (Map.Entry<Long, List<ArchiveTreeContract>> directEntry : directParentGroups) {
|
|
|
+ Long groupId = directEntry.getKey();
|
|
|
+ List<ArchiveTreeContract> groupNodes = directEntry.getValue();
|
|
|
+ ArchiveTreeContract parent = allNodeMap.get(groupId);
|
|
|
+
|
|
|
+ if (parent == null) {
|
|
|
+ // 无父节点的情况:添加所有节点名称(用顿号分隔)
|
|
|
+ String nodeNames = groupNodes.stream()
|
|
|
+ .map(ArchiveTreeContract::getNodeName)
|
|
|
+ .collect(Collectors.joining("、"));
|
|
|
+ nameParts.add(nodeNames);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取直接子节点
|
|
|
+ List<ArchiveTreeContract> allChildren = hierarchy.getChildren(groupId);
|
|
|
+ int childrenCount = (allChildren != null) ? allChildren.size() : 0;
|
|
|
+
|
|
|
+ // 检查是否全覆盖所有子节点
|
|
|
+ if (childrenCount > 0 && groupNodes.size() == childrenCount) {
|
|
|
+ // 只有组内第一个父节点使用完整层级名称
|
|
|
+ String parentName = firstParentInGroup ?
|
|
|
+ getLevelName(hierarchy, groupId) :
|
|
|
+ parent.getNodeName();
|
|
|
+
|
|
|
+ nameParts.add(parentName);
|
|
|
+ } else {
|
|
|
+ // 获取父节点名称
|
|
|
+ String parentName = firstParentInGroup ?
|
|
|
+ getLevelName(hierarchy, groupId) :
|
|
|
+ parent.getNodeName();
|
|
|
+
|
|
|
+ // 部分覆盖:添加父节点名称+子节点名称(用顿号分隔)
|
|
|
+ String childNames = groupNodes.stream()
|
|
|
+ .map(ArchiveTreeContract::getNodeName)
|
|
|
+ .collect(Collectors.joining("、"));
|
|
|
+ nameParts.add(parentName + childNames);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 后续节点不再是第一个
|
|
|
+ firstParentInGroup = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 拼接最终结果
|
|
|
+ return String.join("、", nameParts);
|
|
|
+ }
|
|
|
+ public String generateFullLevelName1(
|
|
|
+ List<Long> nodeIds,
|
|
|
+ NodeHierarchy hierarchy
|
|
|
+ ) {
|
|
|
+ // 1. 获取输入节点
|
|
|
+ Map<Long, ArchiveTreeContract> allNodeMap = hierarchy.getAllNodeMap();
|
|
|
+ List<ArchiveTreeContract> nodes = new ArrayList<>();
|
|
|
|
|
|
for (Long nodeId : nodeIds) {
|
|
|
ArchiveTreeContract node = allNodeMap.get(nodeId);
|