ソースを参照

提交导出试卷文件代码

chenken 8 年 前
コミット
0e0fb11527

+ 9 - 0
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/FileDisposeUtil.java

@@ -21,6 +21,7 @@ import java.util.zip.ZipOutputStream;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
 
+import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
@@ -175,5 +176,13 @@ public class FileDisposeUtil {
 		}
 		}
 		return flag;
 		return flag;
 	}
 	}
+	
+	public static void createDirectory(String downloadDirectory) {
+		File directory = new File(downloadDirectory);
+		if(directory.exists()){
+			FileUtils.deleteQuietly(directory);
+		}
+		directory.mkdir();
+	}
 
 
 }
 }

+ 2 - 2
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/ExamFileType.java

@@ -19,13 +19,13 @@ public enum ExamFileType {
 	 * 试卷结构
 	 * 试卷结构
 	 * 主观题
 	 * 主观题
 	 */
 	 */
-	PAPER_STRUCTURE_SUBJECTIVE("试卷结构-主观题"),
+	PAPER_STRUCTURE_SUBJECTIVE("主观题"),
 	/**
 	/**
 	 * ZIP文件
 	 * ZIP文件
 	 * 试卷结构
 	 * 试卷结构
 	 * 客观题
 	 * 客观题
 	 */
 	 */
-	PAPER_STRUCTURE_OBJECTIVE("试卷结构-客观题"),
+	PAPER_STRUCTURE_OBJECTIVE("客观题"),
 	/**
 	/**
 	 * 音频文件
 	 * 音频文件
 	 */
 	 */

+ 4 - 27
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -659,52 +659,29 @@ public final class DocxProcessUtil {
      * 导出word
      * 导出word
      *
      *
      * @param dataMap
      * @param dataMap
-     * @param fileName
+     * @param fileName   fileName需要带后缀
      */
      */
     public static void exportWord(Map dataMap, String fileName,Template template)throws Exception {
     public static void exportWord(Map dataMap, String fileName,Template template)throws Exception {
         Writer out = null;
         Writer out = null;
         // 输出文件
         // 输出文件
-        File outFile = new File(TEMP_FILE_EXP + fileName + DOCX_SUFFIX);
+        File outFile = new File(TEMP_FILE_EXP+fileName);
         // 将模板和数据模型合并生成文件
         // 将模板和数据模型合并生成文件
         out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), ENCODING));
         out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), ENCODING));
         // 生成文件
         // 生成文件
         template.process(dataMap, out);
         template.process(dataMap, out);
         out.flush();
         out.flush();
         IOUtils.closeQuietly(out);
         IOUtils.closeQuietly(out);
-        
-        
-    }
-
-    /**
-     * 导出试卷
-     *
-     * @param dataMap
-     * @param fileName
-     */
-    public static void exportPaper(Map dataMap, String fileName,Template template) throws Exception {
-        exportWord(dataMap, fileName, template);
-    }
-
-    /**
-     * 导出答案
-     *
-     * @param dataMap
-     * @param fileName
-     */
-    public static void exportAnswer(Map dataMap, String fileName,Template template) throws Exception {
-        exportWord(dataMap, fileName, template);
     }
     }
 
 
     /**
     /**
      * 处理导出word中的图片
      * 处理导出word中的图片
-     *
-     * @param fileName
+     * @param fileName	需要带文件后缀
      * @param wordMLPackages
      * @param wordMLPackages
      * @throws Exception
      * @throws Exception
      */
      */
     public static void processImage(String fileName, List<WordprocessingMLPackage> wordMLPackages) throws Exception {
     public static void processImage(String fileName, List<WordprocessingMLPackage> wordMLPackages) throws Exception {
     	logger.info("试卷:“"+fileName+"”导出处理图片开始...");
     	logger.info("试卷:“"+fileName+"”导出处理图片开始...");
-        String filePath = TEMP_FILE_EXP + fileName + DOCX_SUFFIX;
+        String filePath = TEMP_FILE_EXP + fileName;
         InputStream mainFile = new FileInputStream(filePath);
         InputStream mainFile = new FileInputStream(filePath);
         // 以单个wordXml方式解析freemarker导出的文件
         // 以单个wordXml方式解析freemarker导出的文件
         FlatOpcXmlImporter flatOpcXmlImporter = new FlatOpcXmlImporter(mainFile);
         FlatOpcXmlImporter flatOpcXmlImporter = new FlatOpcXmlImporter(mainFile);

+ 7 - 6
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/DzkdExportPaperService.java

@@ -23,6 +23,7 @@ import com.qmth.cqb.paper.model.PaperDetailUnit;
 import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.utils.BeanCopierUtil;
 import com.qmth.cqb.utils.BeanCopierUtil;
 import com.qmth.cqb.utils.CommonUtils;
 import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.enums.ExamFileType;
 import com.qmth.cqb.utils.exception.PaperException;
 import com.qmth.cqb.utils.exception.PaperException;
 import com.qmth.cqb.utils.word.DocxProcessUtil;
 import com.qmth.cqb.utils.word.DocxProcessUtil;
 
 
@@ -37,10 +38,10 @@ public class DzkdExportPaperService extends ExportPaperAbstractService{
         Map<String,Object> dataMap = initExportPaper(id);
         Map<String,Object> dataMap = initExportPaper(id);
         List<String> fileList = new ArrayList<String>();
         List<String> fileList = new ArrayList<String>();
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
-            String paperfileName = (String) dataMap.get("fileName");
-            String answerFileName = paperfileName+"__答案";
-            DocxProcessUtil.exportPaper(dataMap, paperfileName,DZKD_TEMPLATE_PAPER);
-            DocxProcessUtil.exportAnswer(dataMap,answerFileName,DZKD_TEMPLATE_ANSWER);
+        	String paperfileName = (String) dataMap.get("fileName")+DOCX_SUFFIX;
+            String answerFileName = (String) dataMap.get("fileName")+"_"+ExamFileType.ANSWER.getName()+DOCX_SUFFIX;
+            DocxProcessUtil.exportWord(dataMap, paperfileName,DZKD_TEMPLATE_PAPER);
+            DocxProcessUtil.exportWord(dataMap,answerFileName,DZKD_TEMPLATE_ANSWER);
             DocxProcessUtil.processImage(paperfileName,getPkgList(id));
             DocxProcessUtil.processImage(paperfileName,getPkgList(id));
             DocxProcessUtil.processImage(answerFileName,getPkgList(id));
             DocxProcessUtil.processImage(answerFileName,getPkgList(id));
             fileList.add(paperfileName);
             fileList.add(paperfileName);
@@ -116,7 +117,7 @@ public class DzkdExportPaperService extends ExportPaperAbstractService{
 		paperExp.setSubjectiveScore(subjectiveScore);
 		paperExp.setSubjectiveScore(subjectiveScore);
 		if (objectiveDetails.size() > 0) {
 		if (objectiveDetails.size() > 0) {
 			setUnitExpNumber(objectiveDetails, 0);
 			setUnitExpNumber(objectiveDetails, 0);
-			setScore(objectiveDetails);
+			appendScoreToQuestionBody(objectiveDetails);
 		}
 		}
 		if (subjectiveDetails.size() > 0) {
 		if (subjectiveDetails.size() > 0) {
 			for (PaperDetailExp subDetail : subjectiveDetails) {
 			for (PaperDetailExp subDetail : subjectiveDetails) {
@@ -125,7 +126,7 @@ public class DzkdExportPaperService extends ExportPaperAbstractService{
 				objectNumber++;
 				objectNumber++;
 			}
 			}
 			setUnitExpNumber(subjectiveDetails, objetcUnitSum);
 			setUnitExpNumber(subjectiveDetails, objetcUnitSum);
-			setScore(subjectiveDetails);
+			appendScoreToQuestionBody(subjectiveDetails);
 		}
 		}
 		returnMap.put("paper", paperExp);
 		returnMap.put("paper", paperExp);
 		returnMap.put("fileName", paperExp.getName());
 		returnMap.put("fileName", paperExp.getName());

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

@@ -164,7 +164,7 @@ public abstract class ExportPaperAbstractService {
 	}
 	}
 	
 	
 	/**
 	/**
-	 * 下载试卷
+	 * 下载试卷相关文件
 	 * @param id
 	 * @param id
 	 * @param response
 	 * @param response
 	 * @throws Exception
 	 * @throws Exception
@@ -173,7 +173,6 @@ public abstract class ExportPaperAbstractService {
 	
 	
 	/**
 	/**
 	 * 上传试卷相关文件
 	 * 上传试卷相关文件
-     * 文件路径为:UPLOADURL/机构名称/考试名称/文件类型/文件名称
 	 * @param orgName
 	 * @param orgName
 	 * @param examName
 	 * @param examName
 	 * @param paperId
 	 * @param paperId
@@ -217,22 +216,22 @@ public abstract class ExportPaperAbstractService {
 			// 选择题,套题下选择题 选项顺序重新排列
 			// 选择题,套题下选择题 选项顺序重新排列
 			paperService.reorderChoicequestionOption(paperDetailUnitExps);
 			paperService.reorderChoicequestionOption(paperDetailUnitExps);
 			paperDetailExp.setPaperDetailUnits(paperDetailUnitExps);
 			paperDetailExp.setPaperDetailUnits(paperDetailUnitExps);
-			boolean hasTextAnswer = false;// 判断主观题
+			boolean isSubjective = false;// 判断主观题和客观题
 			if (paperDetailUnits.get(0).getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
 			if (paperDetailUnits.get(0).getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
 				for (Question ques : paperDetailUnits.get(0).getQuestion().getSubQuestions()) {
 				for (Question ques : paperDetailUnits.get(0).getQuestion().getSubQuestions()) {
 					if (ques.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION) {
 					if (ques.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION) {
-						hasTextAnswer = true;
+						isSubjective = true;
 						break;
 						break;
 					}
 					}
 				}
 				}
 			} else if (paperDetailUnits.get(0).getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION
 			} else if (paperDetailUnits.get(0).getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION
 					 ||paperDetailUnits.get(0).getQuestionType() == QuesStructType.FILL_BLANK_QUESTION) {
 					 ||paperDetailUnits.get(0).getQuestionType() == QuesStructType.FILL_BLANK_QUESTION) {
-				hasTextAnswer = true;
+				isSubjective = true;
 			}
 			}
-			if (hasTextAnswer) {
+			if (isSubjective) {
 				subjectiveDetails.add(paperDetailExp);
 				subjectiveDetails.add(paperDetailExp);
 				subjectiveScore += paperDetailExp.getScore();
 				subjectiveScore += paperDetailExp.getScore();
-			} else {
+			}else{
 				objectiveDetails.add(paperDetailExp);
 				objectiveDetails.add(paperDetailExp);
 				paperDetailExp.setNumber(objectNumber);
 				paperDetailExp.setNumber(objectNumber);
 				paperDetailExp.setCnNum(CommonUtils.toCHNum(objectNumber));
 				paperDetailExp.setCnNum(CommonUtils.toCHNum(objectNumber));
@@ -249,7 +248,7 @@ public abstract class ExportPaperAbstractService {
 		paperExp.setSubjectiveScore(subjectiveScore);
 		paperExp.setSubjectiveScore(subjectiveScore);
 		if (objectiveDetails.size() > 0) {
 		if (objectiveDetails.size() > 0) {
 			setUnitExpNumber(objectiveDetails, 0);
 			setUnitExpNumber(objectiveDetails, 0);
-			setScore(objectiveDetails);
+			appendScoreToQuestionBody(objectiveDetails);
 		}
 		}
 		if (subjectiveDetails.size() > 0) {
 		if (subjectiveDetails.size() > 0) {
 			for (PaperDetailExp subDetail : subjectiveDetails) {
 			for (PaperDetailExp subDetail : subjectiveDetails) {
@@ -258,7 +257,7 @@ public abstract class ExportPaperAbstractService {
 				objectNumber++;
 				objectNumber++;
 			}
 			}
 			setUnitExpNumber(subjectiveDetails, objetcUnitSum);
 			setUnitExpNumber(subjectiveDetails, objetcUnitSum);
-			setScore(subjectiveDetails);
+			appendScoreToQuestionBody(subjectiveDetails);
 		}
 		}
 		returnMap.put("paper", paperExp);
 		returnMap.put("paper", paperExp);
 		returnMap.put("fileName", paperExp.getName());
 		returnMap.put("fileName", paperExp.getName());
@@ -313,11 +312,9 @@ public abstract class ExportPaperAbstractService {
 	protected void setUnitExpNumber(List<PaperDetailExp> paperDetails,int startIndxt) throws Exception {
 	protected void setUnitExpNumber(List<PaperDetailExp> paperDetails,int startIndxt) throws Exception {
 		int subNum = startIndxt;
 		int subNum = startIndxt;
 		for (PaperDetailExp paperDetail : paperDetails) {
 		for (PaperDetailExp paperDetail : paperDetails) {
-			
 			List<PaperDetailUnitExp> paperDetailUnitExpList = paperDetail.getPaperDetailUnits();
 			List<PaperDetailUnitExp> paperDetailUnitExpList = paperDetail.getPaperDetailUnits();
-			
+			//对大题下的小题进行排序
 			Collections.sort(paperDetailUnitExpList);
 			Collections.sort(paperDetailUnitExpList);
-			
 			for (PaperDetailUnitExp paperDetailUnit:paperDetailUnitExpList) {
 			for (PaperDetailUnitExp paperDetailUnit:paperDetailUnitExpList) {
 				List<QuesOption> optionList = paperDetailUnit.getQuestion().getQuesOptions();
 				List<QuesOption> optionList = paperDetailUnit.getQuestion().getQuesOptions();
 				if (optionList != null && optionList.size() > 0) {
 				if (optionList != null && optionList.size() > 0) {
@@ -511,7 +508,7 @@ public abstract class ExportPaperAbstractService {
      * @param details
      * @param details
      * @throws Exception
      * @throws Exception
      */
      */
-    protected void setScore(List<PaperDetailExp> details) throws Exception{
+    protected void appendScoreToQuestionBody(List<PaperDetailExp> details) throws Exception{
     	for(PaperDetailExp paperDetailExp:details){
     	for(PaperDetailExp paperDetailExp:details){
     		if(!checkPaperDetailUnitScore(paperDetailExp)){
     		if(!checkPaperDetailUnitScore(paperDetailExp)){
     			for(PaperDetailUnitExp paperDetailUnit:paperDetailExp.getPaperDetailUnits()){
     			for(PaperDetailUnitExp paperDetailUnit:paperDetailExp.getPaperDetailUnits()){
@@ -555,8 +552,4 @@ public abstract class ExportPaperAbstractService {
         return pWordMl.toString();
         return pWordMl.toString();
     }
     }
     
     
-    protected String getRandomFileName(ExamFileType examFileType,String suffix){
-    	return examFileType.name()+"_"+CommonUtils.getCurNum()+suffix;
-    }
-    
 }
 }

+ 4 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/HzkjExportPaperService.java

@@ -36,10 +36,10 @@ public class HzkjExportPaperService extends ExportPaperAbstractService {
         Map<String,Object> dataMap = initExportPaper(paperId);
         Map<String,Object> dataMap = initExportPaper(paperId);
         List<String> fileList = new ArrayList<String>();
         List<String> fileList = new ArrayList<String>();
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
-            String paperfileName = (String) dataMap.get("fileName");
-            String answerFileName = paperfileName+"__答案";
-            DocxProcessUtil.exportPaper(dataMap, paperfileName,HZKJ_TEMPLATE_PAPER);
-            DocxProcessUtil.exportAnswer(dataMap,answerFileName,HZKJ_TEMPLATE_ANSWER);
+        	String paperfileName = (String) dataMap.get("fileName")+DOCX_SUFFIX;
+            String answerFileName = (String) dataMap.get("fileName")+"_"+ExamFileType.ANSWER.getName()+DOCX_SUFFIX;
+            DocxProcessUtil.exportWord(dataMap, paperfileName,HZKJ_TEMPLATE_PAPER);
+            DocxProcessUtil.exportWord(dataMap,answerFileName,HZKJ_TEMPLATE_ANSWER);
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             fileList.add(paperfileName);
             fileList.add(paperfileName);

+ 4 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/SddxExportPaperService.java

@@ -36,10 +36,10 @@ public class SddxExportPaperService extends ExportPaperAbstractService {
         Map<String,Object> dataMap = initExportPaper(paperId);
         Map<String,Object> dataMap = initExportPaper(paperId);
         List<String> fileList = new ArrayList<String>();
         List<String> fileList = new ArrayList<String>();
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
-            String paperfileName = (String) dataMap.get("fileName");
-            String answerFileName = paperfileName+"__答案";
-            DocxProcessUtil.exportPaper(dataMap, paperfileName,SDDX_TEMPLATE_PAPER);
-            DocxProcessUtil.exportAnswer(dataMap,answerFileName,SDDX_TEMPLATE_ANSWER);
+        	String paperfileName = (String) dataMap.get("fileName")+DOCX_SUFFIX;
+            String answerFileName = (String) dataMap.get("fileName")+"_"+ExamFileType.ANSWER.getName()+DOCX_SUFFIX;
+            DocxProcessUtil.exportWord(dataMap, paperfileName,SDDX_TEMPLATE_PAPER);
+            DocxProcessUtil.exportWord(dataMap,answerFileName,SDDX_TEMPLATE_ANSWER);
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             fileList.add(paperfileName);
             fileList.add(paperfileName);

+ 19 - 20
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/SxsfExportPaperService.java

@@ -47,10 +47,10 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
         Map<String,Object> dataMap = initExportPaper(paperId);
         Map<String,Object> dataMap = initExportPaper(paperId);
         List<String> fileList = new ArrayList<String>();
         List<String> fileList = new ArrayList<String>();
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
-            String paperfileName = (String) dataMap.get("fileName");
-            String answerFileName = paperfileName+"__答案";
-            DocxProcessUtil.exportPaper(dataMap, paperfileName,SXSF_TEMPLATE_PAPER);
-            DocxProcessUtil.exportAnswer(dataMap,answerFileName,SXSF_TEMPLATE_ANSWER);
+            String paperfileName = (String) dataMap.get("fileName")+DOCX_SUFFIX;
+            String answerFileName = (String) dataMap.get("fileName")+"_"+ExamFileType.ANSWER.getName()+DOCX_SUFFIX;
+            DocxProcessUtil.exportWord(dataMap, paperfileName,SXSF_TEMPLATE_PAPER);
+            DocxProcessUtil.exportWord(dataMap,answerFileName,SXSF_TEMPLATE_ANSWER);
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             fileList.add(paperfileName);
             fileList.add(paperfileName);
@@ -65,7 +65,6 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
         	String currNum = CommonUtils.getCurNum();
         	String currNum = CommonUtils.getCurNum();
     		ExportStructure exportStructure = (ExportStructure) exportStructureMap.get("exportStructure");
     		ExportStructure exportStructure = (ExportStructure) exportStructureMap.get("exportStructure");
-    		
     		List<QuestionTypeNum> questionTypeNums = new ArrayList<QuestionTypeNum>();
     		List<QuestionTypeNum> questionTypeNums = new ArrayList<QuestionTypeNum>();
     		if(exportStructure!=null){
     		if(exportStructure!=null){
     			questionTypeNums = exportStructure.getQuestionTypeNums();
     			questionTypeNums = exportStructure.getQuestionTypeNums();
@@ -96,12 +95,12 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
      * @param accessUser
      * @param accessUser
      */
      */
     private void uploadPaperWord(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
     private void uploadPaperWord(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
-    	String paperfileName = currNum+"_"+ExamFileType.PAPER.name();
+    	String paperfileName = currNum+ExamFileType.PAPER.name()+DOCX_SUFFIX;
     	try {
     	try {
-			DocxProcessUtil.exportPaper(dataMap, paperfileName,SXSF_TEMPLATE_PAPER);
+			DocxProcessUtil.exportWord(dataMap,paperfileName,SXSF_TEMPLATE_PAPER);
 			DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
 			DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
-			File paperFile  = new File(TEMP_FILE_EXP+paperfileName+DOCX_SUFFIX);
-			String paperFilePath = uploadUrl+paperfileName+DOCX_SUFFIX;
+			File paperFile  = new File(TEMP_FILE_EXP+paperfileName);
+			String paperFilePath = uploadUrl+paperfileName;
             UpYun upyun = new UpYun(bucketName,userName,password);
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(paperFilePath, paperFile,true);
 			upyun.writeFile(paperFilePath, paperFile,true);
 			examFileService.saveExamFile(new ExamFile(extractConfig,paperFilePath,ExamFileType.PAPER,DOCX_SUFFIX),accessUser);
 			examFileService.saveExamFile(new ExamFile(extractConfig,paperFilePath,ExamFileType.PAPER,DOCX_SUFFIX),accessUser);
@@ -120,12 +119,12 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
      * @param accessUser
      * @param accessUser
      */
      */
     private void uploadAnswerWord(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
     private void uploadAnswerWord(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
-    	String answerFileName = currNum+"_"+ExamFileType.ANSWER.name();
+    	String answerFileName = currNum+ExamFileType.ANSWER.name()+DOCX_SUFFIX;
     	try {
     	try {
-    		DocxProcessUtil.exportAnswer(dataMap,answerFileName,SXSF_TEMPLATE_ANSWER);
+    		DocxProcessUtil.exportWord(dataMap,answerFileName,SXSF_TEMPLATE_ANSWER);
     		DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
     		DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
-    		File answerFile  = new File(TEMP_FILE_EXP+answerFileName+DOCX_SUFFIX);
-    		String answerFilePath = uploadUrl+answerFileName+DOCX_SUFFIX;
+    		File answerFile  = new File(TEMP_FILE_EXP+answerFileName);
+    		String answerFilePath = uploadUrl+answerFileName;
             UpYun upyun = new UpYun(bucketName,userName,password);
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(answerFilePath, answerFile,true);
 			upyun.writeFile(answerFilePath, answerFile,true);
 			examFileService.saveExamFile(new ExamFile(extractConfig,answerFilePath,ExamFileType.ANSWER,DOCX_SUFFIX),accessUser);
 			examFileService.saveExamFile(new ExamFile(extractConfig,answerFilePath,ExamFileType.ANSWER,DOCX_SUFFIX),accessUser);
@@ -149,7 +148,7 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
      * @return
      * @return
      */
      */
     private void exportObjectiveQuestionStructures(Map<String,Object> dataMap,ExtractConfig extractConfig,AccessUser accessUser,String currNum,List<QuestionTypeNum> questionTypeNums){
     private void exportObjectiveQuestionStructures(Map<String,Object> dataMap,ExtractConfig extractConfig,AccessUser accessUser,String currNum,List<QuestionTypeNum> questionTypeNums){
-    	String objectiveFilename = currNum+"_"+ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name();
+    	String objectiveFilename = currNum+ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name()+EXCEL_SUFFIX;
     	PaperExp paperExp = (PaperExp) dataMap.get("paper");
     	PaperExp paperExp = (PaperExp) dataMap.get("paper");
     	List<PaperDetailExp> objectiveDetails = paperExp.getObjectiveDetails();
     	List<PaperDetailExp> objectiveDetails = paperExp.getObjectiveDetails();
     	//根据试卷结构导出设置中的数量补齐客观题
     	//根据试卷结构导出设置中的数量补齐客观题
@@ -162,10 +161,10 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
     	}
     	}
     	ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class); 
     	ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class); 
 		try {
 		try {
-			File file = new File(TEMP_FILE_EXP+objectiveFilename+".xlsx");
+			File file = new File(TEMP_FILE_EXP+objectiveFilename);
 			FileOutputStream out = new FileOutputStream(file);
 			FileOutputStream out = new FileOutputStream(file);
 			objectiveExcelExporter.write(objectiveFilename,objectiveQuestionStructureList,out);
 			objectiveExcelExporter.write(objectiveFilename,objectiveQuestionStructureList,out);
-			String objectiveFilePath = uploadUrl+objectiveFilename+".xlsx";
+			String objectiveFilePath = uploadUrl+objectiveFilename;
             UpYun upyun = new UpYun(bucketName,userName,password);
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(objectiveFilePath,file,true);
 			upyun.writeFile(objectiveFilePath,file,true);
 			examFileService.saveExamFile(new ExamFile(extractConfig,objectiveFilePath,ExamFileType.PAPER_STRUCTURE_OBJECTIVE,EXCEL_SUFFIX),accessUser);
 			examFileService.saveExamFile(new ExamFile(extractConfig,objectiveFilePath,ExamFileType.PAPER_STRUCTURE_OBJECTIVE,EXCEL_SUFFIX),accessUser);
@@ -228,7 +227,7 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
 					if(paperDetailExp.getUnitCount()>typeNum.getQuantity()){
 					if(paperDetailExp.getUnitCount()>typeNum.getQuantity()){
 						throw new RuntimeException("试卷:"+paperExp.getName()
 						throw new RuntimeException("试卷:"+paperExp.getName()
 								+"中"+quesStructType.getName()+"的数量:"+paperDetailExp.getUnitCount()
 								+"中"+quesStructType.getName()+"的数量:"+paperDetailExp.getUnitCount()
-								+ ",大于试卷结构导出设置的数量:"+typeNum.getQuantity()+",不符合导出规则");
+								+ ",大于试卷结构导出设置的数量:"+typeNum.getQuantity()+",不符合试卷结构导出规则");
 					}
 					}
 				}
 				}
 			}
 			}
@@ -241,7 +240,7 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
      * @return
      * @return
      */
      */
     private void exportSubjectiveQuestionStructures(Map<String,Object> dataMap,ExtractConfig extractConfig,AccessUser accessUser,String currNum){
     private void exportSubjectiveQuestionStructures(Map<String,Object> dataMap,ExtractConfig extractConfig,AccessUser accessUser,String currNum){
-    	String subjectiveFileName = currNum+"_"+ExamFileType.PAPER_STRUCTURE_SUBJECTIVE.name();
+    	String subjectiveFileName = currNum+ExamFileType.PAPER_STRUCTURE_SUBJECTIVE.name()+EXCEL_SUFFIX;
     	PaperExp paperExp = (PaperExp) dataMap.get("paper");
     	PaperExp paperExp = (PaperExp) dataMap.get("paper");
     	List<PaperDetailExp> subjectiveDetails = paperExp.getSubjectiveDetails();
     	List<PaperDetailExp> subjectiveDetails = paperExp.getSubjectiveDetails();
     	List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
     	List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
@@ -252,10 +251,10 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
     	}
     	}
     	ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class); 
     	ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class); 
 		try {
 		try {
-			File file = new File(TEMP_FILE_EXP+subjectiveFileName+EXCEL_SUFFIX);
+			File file = new File(TEMP_FILE_EXP+subjectiveFileName);
 			FileOutputStream out = new FileOutputStream(file);
 			FileOutputStream out = new FileOutputStream(file);
 			subjectiveExcelExporter.write(subjectiveFileName,subjectiveQuestionStructureList,out);
 			subjectiveExcelExporter.write(subjectiveFileName,subjectiveQuestionStructureList,out);
-			String subjectiveFilePath = uploadUrl+subjectiveFileName+EXCEL_SUFFIX;
+			String subjectiveFilePath = uploadUrl+subjectiveFileName;
             UpYun upyun = new UpYun(bucketName,userName,password);
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(subjectiveFilePath,file,true);
 			upyun.writeFile(subjectiveFilePath,file,true);
 			examFileService.saveExamFile(new ExamFile(extractConfig,subjectiveFilePath,ExamFileType.PAPER_STRUCTURE_SUBJECTIVE,EXCEL_SUFFIX),accessUser);
 			examFileService.saveExamFile(new ExamFile(extractConfig,subjectiveFilePath,ExamFileType.PAPER_STRUCTURE_SUBJECTIVE,EXCEL_SUFFIX),accessUser);

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

@@ -279,7 +279,7 @@ public class SydxExportPaperService{
         Map<String,Object> dataMap = initExportPaper(id);
         Map<String,Object> dataMap = initExportPaper(id);
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
             String fileName = (String) dataMap.get("fileName");
             String fileName = (String) dataMap.get("fileName");
-            DocxProcessUtil.exportPaper(dataMap, fileName,SYDX_TEMPLATE_NORMAL);
+            DocxProcessUtil.exportWord(dataMap, fileName,SYDX_TEMPLATE_NORMAL);
             DocxProcessUtil.processImage(fileName, getPkgList(id));
             DocxProcessUtil.processImage(fileName, getPkgList(id));
             fileNames.add(fileName);
             fileNames.add(fileName);
             DocxProcessUtil.processDownload(fileNames, response);
             DocxProcessUtil.processDownload(fileNames, response);

+ 4 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/TjdxExportPaperService.java

@@ -36,10 +36,10 @@ public class TjdxExportPaperService extends ExportPaperAbstractService {
         Map<String,Object> dataMap = initExportPaper(paperId);
         Map<String,Object> dataMap = initExportPaper(paperId);
         List<String> fileList = new ArrayList<String>();
         List<String> fileList = new ArrayList<String>();
         if (dataMap.get("fileName") != null) {
         if (dataMap.get("fileName") != null) {
-            String paperfileName = (String) dataMap.get("fileName");
-            String answerFileName = paperfileName+"__答案";
-            DocxProcessUtil.exportPaper(dataMap, paperfileName,TJDX_TEMPLATE_PAPER);
-            DocxProcessUtil.exportAnswer(dataMap,answerFileName,TJDX_TEMPLATE_ANSWER);
+        	String paperfileName = (String) dataMap.get("fileName")+DOCX_SUFFIX;
+            String answerFileName = (String) dataMap.get("fileName")+"_"+ExamFileType.ANSWER.getName()+DOCX_SUFFIX;
+            DocxProcessUtil.exportWord(dataMap, paperfileName,TJDX_TEMPLATE_PAPER);
+            DocxProcessUtil.exportWord(dataMap,answerFileName,TJDX_TEMPLATE_ANSWER);
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
             fileList.add(paperfileName);
             fileList.add(paperfileName);

+ 18 - 27
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigServiceImpl.java

@@ -678,36 +678,35 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 
 
 	@Override
 	@Override
 	public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response) throws Exception {
 	public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response) throws Exception {
+		//创建试卷和压缩文件 文件夹
+		FileDisposeUtil.createDirectory(downloadDirectory);
+		//创建压缩文件的文件夹
+		FileDisposeUtil.createDirectory(zipDirectory);
 		//如果是批量导出,首先检查该考试下的所有课程是否都制定了调卷规则
 		//如果是批量导出,首先检查该考试下的所有课程是否都制定了调卷规则
 		List<String> paperIds = new ArrayList<String>();
 		List<String> paperIds = new ArrayList<String>();
-		if(exportModel.getExportWay()==ExportWay.BATCH&&
-				exportModel.getExportContentList().contains("PAPER_STRUCTURE_OBJECTIVE")){
+		Map<String, Object> exportStructureMap = exportStructureService.findStructureByExamIdAndExamType(exportModel.getExamId()+"",exportModel.getExamType());
+		ExportStructure exportStructure = (ExportStructure) exportStructureMap.get("exportStructure");
+		//如果是批量导出
+		if(exportModel.getExportWay()==ExportWay.BATCH){
+			if(exportStructure==null){
+				throw new RuntimeException("该考试下的试卷结构导出设置未制定,不能导出");
+			}
 			paperIds = checkAllCourseByExamId(exportModel.getExamId());
 			paperIds = checkAllCourseByExamId(exportModel.getExamId());
+			//生成试卷结构到downloadDirectory目录
+			if(paperIds.size()>0){
+				//创建试卷结构Excel文件
+				makePaperStructure(exportStructure.getExamName(),paperIds,exportStructure);
+			}
 		}
 		}
+		//根据条件获取到文件下载路径,下载文件到服务器的downloadDirectory文件夹
 		List<ExamFile> examFiles = examFileService.findExamFileListByExportPaperInfoModel(exportModel);
 		List<ExamFile> examFiles = examFileService.findExamFileListByExportPaperInfoModel(exportModel);
-		//创建试卷和压缩文件 文件夹
-		createDirectory(downloadDirectory);
-		createDirectory(zipDirectory);
-		//下载文件到服务器
 		if(examFiles!=null&&examFiles.size()>0){
 		if(examFiles!=null&&examFiles.size()>0){
 			for(ExamFile examFile:examFiles){
 			for(ExamFile examFile:examFiles){
 				FileDisposeUtil.saveUrlAs(downloadUrl+examFile.getFilePath(),downloadDirectory+"\\"+examFile.getFileName());
 				FileDisposeUtil.saveUrlAs(downloadUrl+examFile.getFilePath(),downloadDirectory+"\\"+examFile.getFileName());
 			}
 			}
 		}
 		}
-		//生成试卷结构到downloadDirectory目录
-		Map<String, Object> exportStructureMap = exportStructureService.findStructureByExamIdAndExamType(exportModel.getExamId()+"",exportModel.getExamType());
-		ExportStructure exportStructure = (ExportStructure) exportStructureMap.get("exportStructure");
-		if(exportStructure==null){
-			throw new RuntimeException("该考试下的试卷结构导出设置未制定,不能导出");
-		}
-		if(paperIds.size()>0){
-			//创建试卷结构Excel文件
-			makePaperStructure(exportStructure.getExamName(),paperIds,exportStructure);
-		}
 		//创建压缩文件名称
 		//创建压缩文件名称
-		String zipFileName = exportStructure.getExamName()+"_"+
-							 exportStructure.getExamType().name()+"_"+
-							 CommonUtils.getCurNum();
+		String zipFileName = exportStructure.getExamName()+"_"+exportStructure.getExamType().name()+"_"+CommonUtils.getCurNum();
 		//将downloadDirectory文件夹压缩成zip文件,存放到zipDirectory文件夹中
 		//将downloadDirectory文件夹压缩成zip文件,存放到zipDirectory文件夹中
 		FileDisposeUtil.fileToZip(downloadDirectory,zipDirectory,zipFileName);
 		FileDisposeUtil.fileToZip(downloadDirectory,zipDirectory,zipFileName);
 		//下载zip文件到客户端
 		//下载zip文件到客户端
@@ -791,12 +790,4 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     	subjectiveExcelExporter.write(examName+"_主观题.xlsx",subjectiveQuestionStructureList,out2);
     	subjectiveExcelExporter.write(examName+"_主观题.xlsx",subjectiveQuestionStructureList,out2);
 	}
 	}
 	
 	
-	private void createDirectory(String downloadDirectory) {
-		File directory = new File(downloadDirectory);
-		if(directory.exists()){
-			FileUtils.deleteQuietly(directory);
-		}
-		directory.mkdir();
-	}
-	
 }
 }