소스 검색

350组卷规则

laibulaizheli 1 주 전
부모
커밋
b7ba3fe631
1개의 변경된 파일98개의 추가작업 그리고 140개의 파일을 삭제
  1. 98 140
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

+ 98 - 140
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -1070,6 +1070,9 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 		//意思是如果A\B两个文件进行并卷组卷,总页数规格为300页,但是A+B的文件数为350页,已经超过固定规格,但是上浮区间在100以内,则允许这样组卷。
 		//超过300之后,则不在继续与其他文件进行并卷组卷了。
 		int SpecificationSizeMax = SpecificationSize + 100;
+		if (SpecificationSize == 350) {
+			SpecificationSizeMax = 350;
+		}
 
 		if (archivesSize < SpecificationSize) {
 			//小于规格的 返回true ,当前文件加入待组卷集合,还可以试加文件,未到组卷规格
@@ -1091,6 +1094,38 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 		return null;
 	}
 
+	public boolean hasSingleNodeId(List<ArchiveFile> archiveFiles) {
+		if (archiveFiles == null || archiveFiles.isEmpty()) {
+			return false;
+		}
+
+		String firstNonNullNodeId = null;
+
+		for (ArchiveFile file : archiveFiles) {
+			String currentNodeId = file.getNodeId();
+
+			// 跳过 null 值
+			if (currentNodeId == null) {
+				continue;
+			}
+
+			// 遇到第一个非空 nodeId
+			if (firstNonNullNodeId == null) {
+				firstNonNullNodeId = currentNodeId;
+			}
+			// 后续出现不同值时立即终止
+			else if (!firstNonNullNodeId.equals(currentNodeId)) {
+				return false;
+			}
+		}
+
+		// 检查是否至少存在一个有效 nodeId
+		return firstNonNullNodeId != null;
+	}
+
+
+
+
 	private ArchivesAuto builtArchives(ArchiveTreeContract node, int pageN, int fileN, String startDate, String endDate, String archiveName) {
 		ArchivesAuto archivesAuto = new ArchivesAuto();
 		archivesAuto.setProjectId(node.getProjectId());
@@ -2106,61 +2141,61 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	/**
 	 * 分类并卷组卷  设置分类的节点下只有一个案卷,节点下的所有文件都组成这个案卷。如果设置分类节点(select=1的)多个,案卷归属排序第一个节点。
 	 */
-	private void archiveAutoMethod2(List<ArchiveTreeContract> list, Long projectId,
-									Map<String, List<ArchiveFile>> boxMap, Map<Long, String> boxFileMap, Long traceId) {
-
-		//分类并卷集合<groupId,List<文件>>
-		Map<Long, List<ArchiveFile>> archiveMap = new HashMap<>();
-		//记录同个分组id的第一个节点ID 案卷归属于这个节点
-		Map<Long, Long> groupId2NodeIdMap = new HashMap<>();
-
-		//步骤1:遍历节点集合
-		for (ArchiveTreeContract node : list) {
-			//根据分组ID来创建唯一案卷
-			Long archiveAutoGroupId = node.getArchiveAutoGroupId();
-			//步骤2:查询节点下的未归档文件
-			List<ArchiveFile> archiveFiles = archiveFileClient.getListByNodeID(node.getId().toString());
-			//步骤3:遍历未归档文件
-			if (archiveFiles != null) {
-				for (ArchiveFile file : archiveFiles) {
-
-					if (archiveFiles.size() > 0) {
-						String completeMsg = "[自动组卷] 分类组卷:" + "-traceId:" + traceId + "节点:" + node.getNodeName() + " 文件数量:" + archiveFiles.size();
-						iTraceLogService.saveLog(traceId, completeMsg);
-					}
-					//步骤4:判断文件是否存在分盒设置
-					if (file.getBoxNumber() != null && file.getBoxNumber() != -1) {
-						//添加到分盒文件集合
-						addBoxMap(file, boxMap, boxFileMap);
-					} else {
-						//分类并卷流程
-						//步骤5:将文件按照<groupId,List<文件>>放入集合
-						if (archiveMap.containsKey(archiveAutoGroupId)) {
-							List<ArchiveFile> groupList = archiveMap.get(archiveAutoGroupId);
-							groupList.add(file);
-							archiveMap.put(archiveAutoGroupId, groupList);
-						} else {
-							List<ArchiveFile> groupList = new ArrayList<>();
-							groupList.add(file);
-							archiveMap.put(archiveAutoGroupId, groupList);
-							groupId2NodeIdMap.put(archiveAutoGroupId, node.getId());
-						}
-					}
-				}
-			}
-		}
-		//步骤6:按集合创建案卷,每个group类的案卷归属顺序排第一个节点
-		Set<Map.Entry<Long, List<ArchiveFile>>> entries = archiveMap.entrySet();
-		for (Map.Entry<Long, List<ArchiveFile>> entry : entries) {
-			Long archiveAutoGroupId = entry.getKey();
-			List<ArchiveFile> archiveFiles = entry.getValue();
-			//一个archiveAutoGroupId组成一个案卷  案卷归属同个key的归档树节点select=1的第一个groupId2NodeIdMap
-			//createArchive2(archiveFiles, archiveAutoGroupId, projectId);
-
-			archiveAutoMethodGroup(archiveFiles, archiveAutoGroupId, projectId, null);
-		}
-
-	}
+//	private void archiveAutoMethod2(List<ArchiveTreeContract> list, Long projectId,
+//									Map<String, List<ArchiveFile>> boxMap, Map<Long, String> boxFileMap, Long traceId) {
+//
+//		//分类并卷集合<groupId,List<文件>>
+//		Map<Long, List<ArchiveFile>> archiveMap = new HashMap<>();
+//		//记录同个分组id的第一个节点ID 案卷归属于这个节点
+//		Map<Long, Long> groupId2NodeIdMap = new HashMap<>();
+//
+//		//步骤1:遍历节点集合
+//		for (ArchiveTreeContract node : list) {
+//			//根据分组ID来创建唯一案卷
+//			Long archiveAutoGroupId = node.getArchiveAutoGroupId();
+//			//步骤2:查询节点下的未归档文件
+//			List<ArchiveFile> archiveFiles = archiveFileClient.getListByNodeID(node.getId().toString());
+//			//步骤3:遍历未归档文件
+//			if (archiveFiles != null) {
+//				for (ArchiveFile file : archiveFiles) {
+//
+//					if (archiveFiles.size() > 0) {
+//						String completeMsg = "[自动组卷] 分类组卷:" + "-traceId:" + traceId + "节点:" + node.getNodeName() + " 文件数量:" + archiveFiles.size();
+//						iTraceLogService.saveLog(traceId, completeMsg);
+//					}
+//					//步骤4:判断文件是否存在分盒设置
+//					if (file.getBoxNumber() != null && file.getBoxNumber() != -1) {
+//						//添加到分盒文件集合
+//						addBoxMap(file, boxMap, boxFileMap);
+//					} else {
+//						//分类并卷流程
+//						//步骤5:将文件按照<groupId,List<文件>>放入集合
+//						if (archiveMap.containsKey(archiveAutoGroupId)) {
+//							List<ArchiveFile> groupList = archiveMap.get(archiveAutoGroupId);
+//							groupList.add(file);
+//							archiveMap.put(archiveAutoGroupId, groupList);
+//						} else {
+//							List<ArchiveFile> groupList = new ArrayList<>();
+//							groupList.add(file);
+//							archiveMap.put(archiveAutoGroupId, groupList);
+//							groupId2NodeIdMap.put(archiveAutoGroupId, node.getId());
+//						}
+//					}
+//				}
+//			}
+//		}
+//		//步骤6:按集合创建案卷,每个group类的案卷归属顺序排第一个节点
+//		Set<Map.Entry<Long, List<ArchiveFile>>> entries = archiveMap.entrySet();
+//		for (Map.Entry<Long, List<ArchiveFile>> entry : entries) {
+//			Long archiveAutoGroupId = entry.getKey();
+//			List<ArchiveFile> archiveFiles = entry.getValue();
+//			//一个archiveAutoGroupId组成一个案卷  案卷归属同个key的归档树节点select=1的第一个groupId2NodeIdMap
+//			//createArchive2(archiveFiles, archiveAutoGroupId, projectId);
+//
+//			archiveAutoMethodGroup(archiveFiles, archiveAutoGroupId, projectId, null);
+//		}
+//
+//	}
 
 	private void archiveAutoMethod2_new(List<ArchiveTreeContract> list, List<ArchiveTreeContract> topList, Long projectId,
 										Map<String, List<ArchiveFile>> boxMap, Map<Long, String> boxFileMap, Long traceId) {
@@ -2267,94 +2302,10 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 			List<ArchiveFile> archiveFiles = entry.getValue();
 
 			// 同一个分组ID下的文件分组组卷
-			archiveAutoMethodGroup(archiveFiles, archiveAutoGroupId, projectId, nameInfo);
+			archiveAutoMethodGroupAdapt(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(案卷归属节点)
-		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;
-
-			// 步骤2:查找当前节点的顶层节点ID
-			for (ArchiveTreeContract topNode : topList) {
-				Long topId = topNode.getId();
-				// 检查当前节点是否属于此顶层节点
-				if (node.getAncestors() != null &&
-						node.getAncestors().contains(topId.toString())) {
-					nodeTopId = topId;
-					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 archiveAutoMethodGroup(List<ArchiveFile> archiveFiles, Long archiveAutoGroupId, Long projectId, IArchiveNameService.NodeHierarchy nameInfo) {
@@ -2364,6 +2315,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 
 		// 获取分组规格(取第一个文件的节点规格作为分组规格)
 		int specificationSize = 300; // 默认规格(300页)
+
 		if (archiveFiles.get(0).getNodeId() != null) {
 			// 查询文件所在节点的规格
 			Long nodeId = Long.parseLong(archiveFiles.get(0).getNodeId());
@@ -2379,6 +2331,12 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 			}
 		}
 
+		Boolean bSingleNodeId = hasSingleNodeId(archiveFiles);
+		if (bSingleNodeId == false) {
+			//跨界点,执行350策略
+			specificationSize = 350;
+		}
+
 		// 待组卷文件集合
 		List<ArchiveFile> waitArchiveFiles = new ArrayList<>();
 		// 待组卷文件总页数