Browse Source

Merge remote-tracking branch 'origin/dev0410' into dev1130

宋悦 7 years ago
parent
commit
26a85b76e6

+ 1 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/ExportPaperAbstractService.java

@@ -969,10 +969,10 @@ public abstract class ExportPaperAbstractService {
     	}
 		
 		//刷一遍number
+		int num = 0;
 		for(int i = 0;i<paperDetailExps.size();i++){
 			if(paperDetailExps.get(i).getSortNumber() == quesStructType.getId()){
 				List<PaperDetailUnitExp> exps = paperDetailExps.get(i).getPaperDetailUnits();
-				int num = 0;
 				for(int j = 0;j<exps.size();j++){
 					num++;
 					exps.get(j).setNumber(num);

+ 24 - 7
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigFileServiceImpl.java

@@ -2,6 +2,7 @@ package com.qmth.cqb.paper.service.impl;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -188,7 +189,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			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(exportStructure.getExamName(),paperIds,exportStructure);
+					makePaperStructure(downloadDir,exportStructure.getExamName(),paperIds,exportStructure);
 				}
 			}
 		}
@@ -362,7 +363,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	 * @param exportStructure
 	 * @throws Exception
 	 */
-	private void makePaperStructure(String examName,Map<String,String> paperIds,ExportStructure exportStructure) throws Exception{
+	private void makePaperStructure(String downloadDir,String examName,Map<String,String> paperIds,ExportStructure exportStructure) throws Exception{
 		logger.info("正在批量生成试卷结构...");
 		List<QuestionTypeNum> questionTypeNums = exportStructure.getQuestionTypeNums();
 		//客观题集合
@@ -411,14 +412,30 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 		}
 		
 		ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class); 
-    	FileOutputStream out1 = new FileOutputStream(downloadDirectory+File.separator+examName+"_客观题.xlsx");
-    	objectiveExcelExporter.write(examName+"_客观题.xlsx",objectiveQuestionStructureList,out1);
+		String keguanFileName = examName+"_客观题.xlsx";
+    	FileOutputStream out1 = getFileOutputStream(downloadDir,keguanFileName);
+    	objectiveExcelExporter.write(keguanFileName,objectiveQuestionStructureList,out1);
     	
     	ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class); 
-    	FileOutputStream out2 = new FileOutputStream(downloadDirectory+File.separator+examName+"_主观题.xlsx");
-    	subjectiveExcelExporter.write(examName+"_主观题.xlsx",subjectiveQuestionStructureList,out2);
+    	String zhuguanFileName = examName+"_主观题.xlsx";
+    	FileOutputStream out2 = getFileOutputStream(downloadDir,zhuguanFileName);
+    	subjectiveExcelExporter.write(zhuguanFileName,subjectiveQuestionStructureList,out2);
     	
+    	out1.close();
+    	out2.close();
     	logger.info("批量生成试卷结构完成");
 	}
-
+	
+	private FileOutputStream getFileOutputStream(String downloadDir,String fileName) throws IOException{
+		File directory = new File(downloadDir);
+		if(!directory.exists()){
+			directory.mkdirs();
+		}
+		File file = new File(downloadDir+File.separator+fileName);
+		if(!file.exists()){
+			file.createNewFile();
+		}
+		return new FileOutputStream(file);
+	}
+	
 }