Преглед изворни кода

调卷规则生成文件bug

xiatian пре 3 година
родитељ
комит
7e5004cb69

+ 1 - 0
.gitignore

@@ -44,6 +44,7 @@ yarn.lock
 !**/src/main/**/target/
 !**/src/test/**/target/
 target/
+tempDataDir/
 
 .flattened-pom.xml
 .DS_Store

+ 4 - 2
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/ExtractConfigController.java

@@ -310,8 +310,10 @@ public class ExtractConfigController extends ControllerSupport {
         exportModel.setExportContentList(list);
         try {
             extractConfigFileService.exportExamPaperInfo(exportModel, response, loginName, orgId, null);
-        } catch (Exception e) {
-            LOG.error(e.getMessage(), e);
+        }  catch (StatusException e) {
+            throw e;
+        }	catch (Exception e) {
+            throw new StatusException("500","系统错误",e);
         }
     }
 

+ 18 - 2
examcloud-core-questions-dao/src/main/java/cn/com/qmth/examcloud/core/questions/dao/entity/ExamFile.java

@@ -23,6 +23,11 @@ public class ExamFile extends MongoBaseEntity {
 	 * 
 	 */
 	private static final long serialVersionUID = -6244613661379455829L;
+	
+	/**
+	 * 试卷ID
+	 */
+	private String paperId;
 	/**
      * 机构ID
      */
@@ -95,7 +100,8 @@ public class ExamFile extends MongoBaseEntity {
      * @param fileSuffix
      */
     public ExamFile(String paperId, ExtractConfig extractConfig, String filePath, ExamFileType examFileType, String fileSuffix) {
-        this.orgId = extractConfig.getOrgId();
+    	this.paperId=paperId;
+    	this.orgId = extractConfig.getOrgId();
         this.orgName = extractConfig.getOrgName();
         this.examId = extractConfig.getExamId() + "";
         this.examName = extractConfig.getExamName();
@@ -118,7 +124,8 @@ public class ExamFile extends MongoBaseEntity {
      * @param fileSuffix
      */
     public ExamFile(ComputerTestPaper computerTestPaper, ExtractConfig extractConfig, String filePath, ExamFileType examFileType, String fileSuffix) {
-        this.orgId = extractConfig.getOrgId();
+        this.paperId=computerTestPaper.getId();
+    	this.orgId = extractConfig.getOrgId();
         this.orgName = extractConfig.getOrgName();
         this.examId = extractConfig.getExamId() + "";
         this.examName = extractConfig.getExamName();
@@ -262,5 +269,14 @@ public class ExamFile extends MongoBaseEntity {
         this.groupCode = groupCode;
     }
 
+	public String getPaperId() {
+		return paperId;
+	}
+
+	public void setPaperId(String paperId) {
+		this.paperId = paperId;
+	}
+
+    
 }
 

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/export/ExportPaperAbstractService.java

@@ -521,7 +521,7 @@ public class ExportPaperAbstractService {
     		YunPathInfo pi=FileStorageUtil.saveFile("paperOrAnswerFile", env, file,null);
             ExamFile examFile = new ExamFile(paperExp.getId(), extractConfig, pi.getRelativePath(), examFileType, DOCX_SUFFIX);
             examFile.setGroupCode(examPaper.getGroupCode());
-            examFile.setFileName(extractConfig.getCourseName() + "_" + extractConfig.getCourseCode() + "_"
+            examFile.setFileName(paperExp.getName()+"_"+extractConfig.getCourseName() + "_" + extractConfig.getCourseCode() + "_"
                     + examFileType.getName() + "_" + examFile.getGroupCode() + DOCX_SUFFIX);
             examFileService.saveExamFile(examFile, accessUser);
         } catch (Exception e) {

+ 59 - 78
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigFileServiceImpl.java

@@ -182,94 +182,75 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 		FileDisposeUtil.createDirectory(downloadDir);
 		// 创建压缩文件的文件夹
 		FileDisposeUtil.createDirectory(downZipDir);
-		ExportStructure exportStructure = exportStructureService.findStructureByExamId(exportModel.getExamId() + "");
-		if (exportStructure == null) {
-			exportStructure = new ExportStructure();
-			exportStructure.setExportType(ExportType.NORMAL);
-		}
-
-		// 导出分布式印刷的数据包
-		if (exportModel.getExportContentList().contains(ExamFileType.PRINT_EXAM_PACKAGE.name())) {
-			ExtractConfig condition = new ExtractConfig();
-			condition.setExamId(Long.valueOf(exportModel.getExamId()));
-			condition.setCourseCode(exportModel.getCourseId());
-			// 获取调卷规则
-			ExtractConfig extractConfig = extractConfigService.findConfig(condition);
-			if (extractConfig != null) {
-				List<Paper> papers = new ArrayList<>();
-				List<ExamPaper> examPapers = extractConfig.getExamPaperList();
-				if (examPapers != null && examPapers.size() > 0) {
-					for (ExamPaper examPaper : examPapers) {
-						papers.add(examPaper.getPaper());
+		try {
+			ExportStructure exportStructure = exportStructureService
+					.findStructureByExamId(exportModel.getExamId() + "");
+			if (exportStructure == null) {
+				exportStructure = new ExportStructure();
+				exportStructure.setExportType(ExportType.NORMAL);
+			}
+			// 导出分布式印刷的数据包
+			if (exportModel.getExportContentList().contains(ExamFileType.PRINT_EXAM_PACKAGE.name())) {
+				ExtractConfig condition = new ExtractConfig();
+				condition.setExamId(Long.valueOf(exportModel.getExamId()));
+				condition.setCourseCode(exportModel.getCourseId());
+				// 获取调卷规则
+				ExtractConfig extractConfig = extractConfigService.findConfig(condition);
+				if (extractConfig != null) {
+					List<Paper> papers = new ArrayList<>();
+					List<ExamPaper> examPapers = extractConfig.getExamPaperList();
+					if (examPapers != null && examPapers.size() > 0) {
+						for (ExamPaper examPaper : examPapers) {
+							papers.add(examPaper.getPaper());
+						}
 					}
+					printExamPaperService.downloadPaper(papers, downloadDir, psw);
+				} else {
+					LOG.info("exportPrintExamPaper fail, extractConfig is not exist!");
 				}
-				printExamPaperService.downloadPaper(papers, downloadDir, psw);
-			} else {
-				LOG.info("exportPrintExamPaper fail, extractConfig is not exist!");
 			}
-		}
-
-		// 如果是普通类型的批量导出 导出试卷结构
-		if (exportModel.getExportWay() == ExportWay.BATCH) {
-			Map<String, String> paperIds = checkAllCourseByExamId(exportModel.getExamId(),
-					exportStructure.getExportType());
-			if (exportStructure.getExportType() == ExportType.NORMAL) {
-				if (paperIds.size() > 0
-						&& exportModel.getExportContentList().contains(ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name())) {
-					makePaperStructure(downloadDir, exportStructure.getExamName(), paperIds, exportStructure);// for
-																												// export
-																												// test
+			// 如果是普通类型的批量导出 导出试卷结构
+			if (exportModel.getExportWay() == ExportWay.BATCH) {
+				Map<String, String> paperIds = checkAllCourseByExamId(exportModel.getExamId(),
+						exportStructure.getExportType());
+				if (exportStructure.getExportType() == ExportType.NORMAL) {
+					if (paperIds.size() > 0 && exportModel.getExportContentList()
+							.contains(ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name())) {
+						makePaperStructure(downloadDir, exportStructure.getExamName(), paperIds, exportStructure);// for
+																													// export
+																													// test
+					}
 				}
 			}
-		}
-		// 根据条件获取到文件下载路径,下载文件到服务器的downloadDirectory文件夹
-		List<ExamFile> examFiles = examFileService.findExamFileListByExportPaperInfoModel(exportModel);
-		if (examFiles != null && examFiles.size() > 0) {
-			for (int i = 0; i < examFiles.size(); i++) {
-				ExamFile examFile = examFiles.get(i);
-//                UpYun upyun = new UpYun(sysProperty.getBucketName(), sysProperty.getUserName(), sysProperty.getPassword());
-				File file = new File(downloadDir + File.separator + examFile.getFileName());
-//                upyun.readFile(examFile.getFilePath(), file);
-				// 通用存储
-				FileStorageUtil.saveUrlAs(FileStorageUtil.realPath(examFile.getFilePath()), file);
-
-				if (examFile.getExamFileType() == ExamFileType.PAPER) {
-					Long examId = Long.parseLong(exportModel.getExamId());
-					ExtractConfig extractConfig = extractConfigService
-							.findConfig(new ExtractConfig(examId, examFile.getCourseId()));
-					List<ExamPaper> list = extractConfig.getExamPaperList();
-					if (list != null && list.size() > 0) {
-						for (ExamPaper examPaper : list) {
-							String groupCode = examPaper.getGroupCode();
-							String paperId = examPaper.getPaper().getId();
-							if (groupCode.equals(examFile.getGroupCode())) {
-								downloadAudio(paperId, examFile, downloadDir, orgId);
-							}
-
+			// 根据条件获取到文件下载路径,下载文件到服务器的downloadDirectory文件夹
+			List<ExamFile> examFiles = examFileService.findExamFileListByExportPaperInfoModel(exportModel);
+			if (examFiles != null && examFiles.size() > 0) {
+				for (int i = 0; i < examFiles.size(); i++) {
+					ExamFile examFile = examFiles.get(i);
+					File file = new File(downloadDir + File.separator + examFile.getFileName());
+					// 通用存储
+					FileStorageUtil.saveUrlAs(FileStorageUtil.realPath(examFile.getFilePath()), file);
+
+					if (examFile.getExamFileType() == ExamFileType.PAPER) {
+						if(StringUtils.isBlank(examFile.getPaperId())) {
+							throw new StatusException("错误的旧数据,请重新生成一次文件");
 						}
+						downloadAudio(examFile.getPaperId(), examFile, downloadDir, orgId);
 					}
-					/*
-					 * Map<String, String> finishedPaperIdMap =
-					 * extractConfig.getFinishedPaperIdMap(); Set<Entry<String, String>> entrySet =
-					 * finishedPaperIdMap.entrySet(); Iterator<Entry<String, String>> iterator =
-					 * entrySet.iterator(); while (iterator.hasNext()) { Entry<String, String> entry
-					 * = iterator.next(); String groupCode = entry.getKey(); String paperId =
-					 * entry.getValue(); if (groupCode.equals(examFile.getGroupCode())) {
-					 * downloadAudio(paperId, examFile, downloadDir, orgName); } }
-					 */
 				}
 			}
+			// 创建压缩文件名称
+			String zipFileName = exportModel.getExamId();
+			// 将downloadDirectory文件夹压缩成zip文件,存放到zipDirectory文件夹中
+			FileDisposeUtil.fileToZip(downloadDir, downZipDir, zipFileName);
+			// 下载zip文件到客户端
+			FileDisposeUtil.downloadFile(zipFileName + ".zip", downZipDir + File.separator + zipFileName + ".zip",
+					response);
+		} finally {
+			// 删除文件夹
+			FileUtils.deleteQuietly(new File(downloadDir));
+			FileUtils.deleteQuietly(new File(downZipDir));
 		}
-		// 创建压缩文件名称
-		String zipFileName = exportModel.getExamId();
-		// 将downloadDirectory文件夹压缩成zip文件,存放到zipDirectory文件夹中
-		FileDisposeUtil.fileToZip(downloadDir, downZipDir, zipFileName);
-		// 下载zip文件到客户端
-		FileDisposeUtil.downloadFile(zipFileName + ".zip", downZipDir + File.separator + zipFileName + ".zip",
-				response);
-		// 删除文件夹
-		FileUtils.deleteQuietly(new File(downloadDir));
-		FileUtils.deleteQuietly(new File(downZipDir));
 	}
 
 	/**