Browse Source

提交导出试卷结构的BUG,增加导出试卷结构的字段

chenken 7 years ago
parent
commit
ebdc4c2735

+ 60 - 5
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/ObjectiveQuestionStructure.java

@@ -30,34 +30,73 @@ public class ObjectiveQuestionStructure implements Serializable{
 	 */
 	@ExcelProperty(name="课程名称",index = 1)
 	private String courseName;
+	
+	/**
+	 * 试卷名称
+	 */
+	@ExcelProperty(name="试卷名称",index = 2)
+	private String paperName;
+	
+	/**
+	 * 试卷类型
+	 */
+	@ExcelProperty(name="试卷类型",index = 3)
+	private String paperType;
 	/**
 	 * 大题号
 	 */
-	@ExcelProperty(name="大题号",index = 2)
+	@ExcelProperty(name="大题号",index = 4)
 	private Integer bigQuestionNo;
 	/**
 	 * 小题号
 	 */
-	@ExcelProperty(name="小题号",index = 3)
+	@ExcelProperty(name="小题号",index = 5)
 	private Integer smallQuestionNo;
 	/**
 	 * 题目类型
 	 */
-	@ExcelProperty(name="题目类型",index = 4)
+	@ExcelProperty(name="题目类型",index = 6)
 	private String questionType;
 	/**
 	 * 标准答案
 	 */
-	@ExcelProperty(name="标准答案",index = 5)
+	@ExcelProperty(name="标准答案",index = 7)
 	private String answer;
 	/**
 	 * 小题分数
 	 */
-	@ExcelProperty(name="小题分数",index = 6)
+	@ExcelProperty(name="小题分数",index = 8)
 	private Double smallQuestionScore;
 	
 	public ObjectiveQuestionStructure(){}
 	
+	public ObjectiveQuestionStructure(PaperExp paperExp,PaperDetailExp paperDetailExp,PaperDetailUnitExp unit,String paperType){
+		this.paperType = paperType;
+		this.paperName = paperExp.getName();
+		this.courseNo = paperExp.getCourseNo();
+		this.courseName = paperExp.getCourseName();
+		this.bigQuestionNo = paperDetailExp.getNumber();
+		this.questionType = unit.getQuestionType().getName();
+		this.smallQuestionNo = unit.getNumber();
+		this.smallQuestionScore = unit.getScore();
+		if(StringUtils.isNotBlank(unit.getQuestion().getQuesAnswer())){
+			if(unit.getQuestionType()==QuesStructType.BOOL_ANSWER_QUESTION){
+				if("正确".equals(unit.getQuestion().getQuesAnswer())){
+					this.answer = "A";
+				}else if("错误".equals(unit.getQuestion().getQuesAnswer())){
+					this.answer = "B";
+				}else if("#".equals(unit.getQuestion().getQuesAnswer())){
+					this.answer = "#";
+				}
+			}else if(unit.getQuestionType()==QuesStructType.MULTIPLE_ANSWER_QUESTION){
+				this.answer = unit.getQuestion().getQuesAnswer().replaceAll(",", "");
+			}else{
+				this.answer = unit.getQuestion().getQuesAnswer();
+			}
+		}
+	}
+	
+	
 	public ObjectiveQuestionStructure(PaperExp paperExp,PaperDetailExp paperDetailExp,PaperDetailUnitExp unit){
 		this.courseNo = paperExp.getCourseNo();
 		this.courseName = paperExp.getCourseName();
@@ -148,6 +187,22 @@ public class ObjectiveQuestionStructure implements Serializable{
 	public void setSmallQuestionScore(Double smallQuestionScore) {
 		this.smallQuestionScore = smallQuestionScore;
 	}
+
+	public String getPaperName() {
+		return paperName;
+	}
+
+	public void setPaperName(String paperName) {
+		this.paperName = paperName;
+	}
+
+	public String getPaperType() {
+		return paperType;
+	}
+
+	public void setPaperType(String paperType) {
+		this.paperType = paperType;
+	}
 	
 }
 

+ 42 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/SubjectiveQuestionStructure.java

@@ -25,25 +25,36 @@ public class SubjectiveQuestionStructure implements Serializable{
 	 */
 	@ExcelProperty(name="科目名称",index = 1)
 	private String courseName;
+	/**
+	 * 试卷名称
+	 */
+	@ExcelProperty(name="试卷名称",index = 2)
+	private String paperName;
+	
+	/**
+	 * 试卷类型
+	 */
+	@ExcelProperty(name="试卷类型",index = 3)
+	private String paperType;
 	/**
 	 * 大题号
 	 */
-	@ExcelProperty(name="大题号",index = 2)
+	@ExcelProperty(name="大题号",index = 4)
 	private Integer bigQuestionNo;
 	/**
 	 * 大题名称
 	 */
-	@ExcelProperty(name="大题名称",index = 3)
+	@ExcelProperty(name="大题名称",index = 5)
 	private String bigQuestionName;
 	/**
 	 * 小题号
 	 */
-	@ExcelProperty(name="小题号",index = 4)
+	@ExcelProperty(name="小题号",index = 6)
 	private Integer smallQuestionNo;
 	/**
 	 * 小题分数
 	 */
-	@ExcelProperty(name="满分",index = 5)
+	@ExcelProperty(name="满分",index = 7)
 	private Double questionScore;
 	
 	public SubjectiveQuestionStructure(){}
@@ -57,6 +68,17 @@ public class SubjectiveQuestionStructure implements Serializable{
 		this.questionScore = unit.getScore();
 	}
 	
+	public SubjectiveQuestionStructure(PaperExp paperExp,PaperDetailExp paperDetailExp,PaperDetailUnitExp unit,String paperType){
+		this.paperName = paperExp.getName();
+		this.paperType = paperType;
+		this.courseNo = paperExp.getCourseNo();
+		this.courseName = paperExp.getCourseName();
+		this.bigQuestionNo = paperDetailExp.getNumber();
+		this.bigQuestionName = paperDetailExp.getName();
+		this.smallQuestionNo = unit.getNumber();
+		this.questionScore = unit.getScore();
+	}
+	
 	
 	public String getCourseNo() {
 		return courseNo;
@@ -96,6 +118,22 @@ public class SubjectiveQuestionStructure implements Serializable{
 	public void setQuestionScore(Double questionScore) {
 		this.questionScore = questionScore;
 	}
+
+	public String getPaperName() {
+		return paperName;
+	}
+
+	public void setPaperName(String paperName) {
+		this.paperName = paperName;
+	}
+
+	public String getPaperType() {
+		return paperType;
+	}
+
+	public void setPaperType(String paperType) {
+		this.paperType = paperType;
+	}
 	
 }
 

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

@@ -8,9 +8,11 @@ import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Map.Entry;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -18,6 +20,7 @@ import java.util.stream.Collectors;
 import javax.xml.bind.JAXBElement;
 
 import com.qmth.cqb.question.dao.QuesPkgPathRepo;
+
 import main.java.com.UpYun;
 
 import org.apache.commons.io.FileUtils;
@@ -801,9 +804,11 @@ public abstract class ExportPaperAbstractService {
     	//根据试卷结构导出设置中的数量补齐客观题
     	List<PaperDetailExp> paperDetailExps = fillObjectiveQuestions(objectiveDetails,questionTypeNums);
     	List<ObjectiveQuestionStructure> objectiveQuestionStructureList = new ArrayList<ObjectiveQuestionStructure>();
+    	
+    	String paperType = findPaperType(extractConfig,paperExp.getId());
     	for(PaperDetailExp paperDetailExp:paperDetailExps){
     		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-    			objectiveQuestionStructureList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+    			objectiveQuestionStructureList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
     		}
     	}
     	ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class); 
@@ -833,9 +838,10 @@ public abstract class ExportPaperAbstractService {
     	String subjectiveFileName = currNum+ExamFileType.PAPER_STRUCTURE_SUBJECTIVE.name()+EXCEL_SUFFIX;
     	List<PaperDetailExp> subjectiveDetails = getAllSubjectiveDetails(paperExp);
     	List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
+    	String paperType = findPaperType(extractConfig,paperExp.getId());
     	for(PaperDetailExp paperDetailExp:subjectiveDetails){
     		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-    			subjectiveQuestionStructureList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+    			subjectiveQuestionStructureList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
     		}
     	}
     	ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class); 
@@ -945,9 +951,23 @@ public abstract class ExportPaperAbstractService {
         		newPaperDetailExp.setPaperDetailUnits(newPaperDetailUnits);
     			//设置大题题号
         		newPaperDetailExp.setNumber(Integer.parseInt(quesStructType.getId()+""));
+        		newPaperDetailExp.setSortNumber(paperDetailExp.getSortNumber());
     			paperDetailExps.add(newPaperDetailExp);
     		}
     	}
+		
+		//刷一遍number
+		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);
+				}
+			}
+		}
+		
 		//计算差额、补齐试题
 		int quantity = getQuantity(questionTypeNums,quesStructType)-currentSize;
 		PaperDetailExp paperDetailExp = new PaperDetailExp();
@@ -1057,5 +1077,26 @@ public abstract class ExportPaperAbstractService {
 		return DocxProcessUtil.getPkg(pkgByte);
 	}
     
+    /**
+     * 筛选出试卷类型
+     * @param extractConfig
+     * @param paperId
+     * @return
+     */
+    private String findPaperType(ExtractConfig extractConfig,String paperId){
+    	String paperType = "";
+    	Map<String,String> paperIdMap = extractConfig.getFinishedPaperIdMap();
+    	Set<Entry<String,String>> entry = paperIdMap.entrySet();
+		Iterator<Entry<String,String>> iterator = entry.iterator();
+		while(iterator.hasNext()){
+			Entry<String,String> next = iterator.next();
+			if(paperId.equals(next.getValue())){
+				paperType = next.getKey();
+				break;
+			}
+		}
+		return paperType;
+    }
+    
 }
 

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

@@ -127,7 +127,7 @@ public  class InitPaperExpService {
     public PaperExp initPaperExp(String paperId) throws Exception{
     	//根据paperId取到paper对象
     	Paper paper = paperRepo.findOne(paperId);
-    	paperService.formatPaper(paper, null);
+    	//paperService.formatPaper(paper, null);
     	if (paper == null) {
 			throw new PaperException("该试卷不存在");
 		}
@@ -504,8 +504,6 @@ public  class InitPaperExpService {
                                     int curNum = num + index;
                                     if(!StringUtils.isEmpty(preStr) && preStr.startsWith("#")){
                                         text.setValue("___"+(curNum)+"___");
-                                    }else{
-                                    	text.setValue(curNum+"");
                                     }
                                     index++;
                                 }

+ 26 - 13
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigFileServiceImpl.java

@@ -3,6 +3,7 @@ package com.qmth.cqb.paper.service.impl;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -182,7 +183,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 		}
 		//如果是普通类型的批量导出
 		if(exportModel.getExportWay()==ExportWay.BATCH){
-			List<String> paperIds = checkAllCourseByExamId(exportModel.getExamId(),exportStructure.getExportType());
+			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);
@@ -291,8 +292,8 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	 * 查询该考试下是否所有课程都制定了调卷规则
 	 * @param examId
 	 */
-	private List<String> checkAllCourseByExamId(String examId,ExportType exportType) {
-		List<String> paperIdList = new ArrayList<String>();
+	private Map<String,String> checkAllCourseByExamId(String examId,ExportType exportType) {
+		Map<String,String> paperIdMap = new HashMap<String,String>();
 		List<ExamCourseDto> examCourseDtoList = examCourseClient.findExamCourseByExamId(examId);
 		for(ExamCourseDto examCourseDto:examCourseDtoList){
 			ExtractConfig condition = new ExtractConfig();
@@ -310,11 +311,12 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			Set<Entry<String,String>> entry = finishedPaperIdMap.entrySet();
 			Iterator<Entry<String,String>> iterator = entry.iterator();
 			while(iterator.hasNext()){
-				String paperId = iterator.next().getValue();
-				paperIdList.add(paperId);
+				Entry<String,String> next = iterator.next();
+				//paperId为key,paperType为value
+				paperIdMap.put(next.getValue(),next.getKey());
 			}
 		}
-		return paperIdList;
+		return paperIdMap;
 	}
 	
 	/**
@@ -358,12 +360,12 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	 * @param exportStructure
 	 * @throws Exception
 	 */
-	private void makePaperStructure(String examName,List<String> paperIds,ExportStructure exportStructure) throws Exception{
+	private void makePaperStructure(String examName,Map<String,String> paperIds,ExportStructure exportStructure) throws Exception{
 		logger.info("正在批量生成试卷结构...");
 		List<QuestionTypeNum> questionTypeNums = exportStructure.getQuestionTypeNums();
-		
+		//客观题集合
 		List<ObjectiveQuestionStructure> objectiveQuestionStructureList = new ArrayList<ObjectiveQuestionStructure>();
-		
+		//主观题集合
 		List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
 		
 		ExportServiceManage esm = exportServiceManageRepo.findByOrgName(exportStructure.getOrgName());
@@ -371,28 +373,39 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			esm = exportServiceManageRepo.findByOrgName("陕西师范大学");
 		}
     	ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(esm.getExportServiceName());
-		for(String paperId:paperIds){
+    	Set<Entry<String,String>> entrySet = paperIds.entrySet();
+		Iterator<Entry<String,String>> iterator = entrySet.iterator();
+		
+		while(iterator.hasNext()){
+			Entry<String,String> entry = iterator.next();
+			String paperId = entry.getKey();
+			String paperType = entry.getValue();
+			logger.info("初始化试卷:"+paperId);
 			PaperExp paperExp = initPaperExpService.initPaperExp(paperId);
-			//添加主观题
+			logger.info("处理客观题...");
+			//添加客观题
 			List<PaperDetailExp> objectiveDetails = exportPaperAbstractService.getAllObjectiveDetails(paperExp);
 			//得到补齐后的客观题大题
 			List<PaperDetailExp> paperDetailExps = exportPaperAbstractService.fillObjectiveQuestions(objectiveDetails, questionTypeNums);
 			List<ObjectiveQuestionStructure> objectiveList = new ArrayList<ObjectiveQuestionStructure>();
 	    	for(PaperDetailExp paperDetailExp:paperDetailExps){
 	    		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-	    			objectiveList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+	    			objectiveList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
 	    		}
 	    	}
 	    	objectiveQuestionStructureList.addAll(objectiveList);
+	    	logger.info("处理客观题完成");
 	    	//添加主观题
+	    	logger.info("处理主观题...");
 	    	List<PaperDetailExp> subjectiveDetails = exportPaperAbstractService.getAllSubjectiveDetails(paperExp);
 	    	List<SubjectiveQuestionStructure> subjectiveList = new ArrayList<SubjectiveQuestionStructure>();
 	    	for(PaperDetailExp paperDetailExp:subjectiveDetails){
 	    		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-	    			subjectiveList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+	    			subjectiveList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
 	    		}
 	    	}
 	    	subjectiveQuestionStructureList.addAll(subjectiveList);
+	    	logger.info("处理主观题完成");
 		}
 		
 		ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class);