|
@@ -1921,10 +1921,116 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void archiveAutoMethod2_new(List<ArchiveTreeContract> list, List<ArchiveTreeContract> topList, Long projectId,
|
|
|
Map<String, List<ArchiveFile>> boxMap, Map<Long, String> boxFileMap, Long traceId) {
|
|
|
|
|
|
+ // 构建TOP节点ID集合(提前计算提高效率)
|
|
|
+ Set<Long> topIdSet = topList.stream()
|
|
|
+ .map(ArchiveTreeContract::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 分类并卷集合<groupId, List<文件>>
|
|
|
+ Map<Long, List<ArchiveFile>> archiveMap = new LinkedHashMap<>();
|
|
|
+ // 记录同个分组id对应的第一个节点ID(案卷归属节点)
|
|
|
+ Map<Long, Long> groupId2NodeIdMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 当前处理的顶层节点ID
|
|
|
+ Long curTopId = null;
|
|
|
+ // 当前顶层节点对应的分组ID
|
|
|
+ Long currArchiveAutoGroupId = null;
|
|
|
+
|
|
|
+ // 4. 构建节点层级关系
|
|
|
+ IArchiveNameService.NodeHierarchy nameInfo =
|
|
|
+ archiveNameService.buildNodeHierarchy(list);
|
|
|
+
|
|
|
+ // 步骤1:遍历节点集合
|
|
|
+ for (ArchiveTreeContract node : list) {
|
|
|
+ // 初始化当前节点的分组ID和顶层节点ID
|
|
|
+ Long archiveAutoGroupId = node.getArchiveAutoGroupId();
|
|
|
+ Long nodeTopId = 0L;
|
|
|
+
|
|
|
+ String ancestors = node.getAncestors();
|
|
|
+ if (ancestors != null && !ancestors.trim().isEmpty()) {
|
|
|
+ // 分割祖先字符串并转换为Long列表
|
|
|
+ List<Long> ancestorIds = Arrays.stream(ancestors.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(s -> {
|
|
|
+ try {
|
|
|
+ return Long.parseLong(s);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 从上到下遍历:根节点(开始) → 最近祖先(末尾)
|
|
|
+ // 查找最后一个匹配的TOP节点(离当前节点最近的)
|
|
|
+ for (int i = ancestorIds.size() - 1; i >= 0; i--) {
|
|
|
+ Long ancestorId = ancestorIds.get(i);
|
|
|
+ if (topIdSet.contains(ancestorId)) {
|
|
|
+ nodeTopId = ancestorId;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // =========== 关键修改结束 ===========
|
|
|
+
|
|
|
+ // 步骤3:确定当前节点的分组ID
|
|
|
+ if (curTopId != null && curTopId.equals(nodeTopId) && nodeTopId != 0) {
|
|
|
+ // 如果属于同一个非零顶层节点,使用之前的分组ID
|
|
|
+ archiveAutoGroupId = currArchiveAutoGroupId;
|
|
|
+ } else {
|
|
|
+ // 新顶层节点或没有顶层节点,更新当前分组信息
|
|
|
+ curTopId = nodeTopId;
|
|
|
+ currArchiveAutoGroupId = archiveAutoGroupId;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤4:查询节点下的未归档文件(保持原逻辑)
|
|
|
+ List<ArchiveFile> archiveFiles = archiveFileClient.getListByNodeID(node.getId().toString());
|
|
|
+
|
|
|
+ if (archiveFiles != null && !archiveFiles.isEmpty()) {
|
|
|
+ // 记录日志(每个节点只记录一次)
|
|
|
+ String completeMsg = "[自动组卷] 分类组卷:" + "-traceId:" + traceId + "节点:" + node.getNodeName() + " 文件数量:" + archiveFiles.size();
|
|
|
+ iTraceLogService.saveLog(traceId, completeMsg);
|
|
|
+
|
|
|
+ // 步骤5:遍历未归档文件
|
|
|
+ for (ArchiveFile file : archiveFiles) {
|
|
|
+ // 步骤6:判断文件是否存在分盒设置
|
|
|
+ if (file.getBoxNumber() != null && file.getBoxNumber() != -1) {
|
|
|
+ // 添加到分盒文件集合
|
|
|
+ addBoxMap(file, boxMap, boxFileMap);
|
|
|
+ } else {
|
|
|
+ // 分类并卷流程
|
|
|
+ // 步骤7:将文件按照<groupId,List<文件>>放入集合
|
|
|
+ if (archiveMap.containsKey(archiveAutoGroupId)) {
|
|
|
+ List<ArchiveFile> groupList = archiveMap.get(archiveAutoGroupId);
|
|
|
+ groupList.add(file);
|
|
|
+ } else {
|
|
|
+ List<ArchiveFile> groupList = new ArrayList<>();
|
|
|
+ groupList.add(file);
|
|
|
+ archiveMap.put(archiveAutoGroupId, groupList);
|
|
|
+ groupId2NodeIdMap.put(archiveAutoGroupId, node.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤8:按集合创建案卷(保持原逻辑)
|
|
|
+ for (Map.Entry<Long, List<ArchiveFile>> entry : archiveMap.entrySet()) {
|
|
|
+ Long archiveAutoGroupId = entry.getKey();
|
|
|
+ List<ArchiveFile> archiveFiles = entry.getValue();
|
|
|
+
|
|
|
+ // 同一个分组ID下的文件分组组卷
|
|
|
+ archiveAutoMethodGroup(archiveFiles, archiveAutoGroupId, projectId,nameInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void archiveAutoMethod2_new1(List<ArchiveTreeContract> list, List<ArchiveTreeContract> topList, Long projectId,
|
|
|
+ Map<String, List<ArchiveFile>> boxMap, Map<Long, String> boxFileMap, Long traceId) {
|
|
|
+
|
|
|
// 分类并卷集合<groupId, List<文件>>
|
|
|
Map<Long, List<ArchiveFile>> archiveMap = new LinkedHashMap<>();
|
|
|
// 记录同个分组id对应的第一个节点ID(案卷归属节点)
|