|
@@ -0,0 +1,234 @@
|
|
|
+package com.qmth.cqb.paper.service.export;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
|
+import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
|
+import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
+import com.qmth.cqb.paper.dto.PaperDetailExp;
|
|
|
+import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
|
|
|
+import com.qmth.cqb.paper.dto.PaperExp;
|
|
|
+import com.qmth.cqb.paper.model.Paper;
|
|
|
+import com.qmth.cqb.paper.model.PaperDetail;
|
|
|
+import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
|
+import com.qmth.cqb.paper.service.PaperService;
|
|
|
+import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
+import com.qmth.cqb.question.model.QuesOption;
|
|
|
+import com.qmth.cqb.question.model.Question;
|
|
|
+import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
+import com.qmth.cqb.utils.CommonUtils;
|
|
|
+import com.qmth.cqb.utils.exception.PaperException;
|
|
|
+import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
+
|
|
|
+@Service("zkdExportPaperService")
|
|
|
+public class DzkdExportPaperService extends ExportPaperAbstractService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaperRepo paperRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaperService paperService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaperDetailRepo paperDetailRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ QuesRepo quesRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExportPaperService exportPaperService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化导出试卷DTO
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map initExportPaper(String id) throws Exception{
|
|
|
+ //创建返回Map
|
|
|
+ Map returnMap = new HashMap();
|
|
|
+ //获取paper
|
|
|
+ Paper paper = paperRepo.findOne(id);
|
|
|
+
|
|
|
+ paperService.formatPaper(paper,null);
|
|
|
+
|
|
|
+ if(paper == null){
|
|
|
+ throw new PaperException("该试卷不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建paperDto
|
|
|
+ PaperExp paperExp = BeanCopierUtil.copyProperties(paper,PaperExp.class);
|
|
|
+ paperExp.setCourseLevel(paper.getLevel().getName());
|
|
|
+ List<PaperDetailExp> objectiveDetails = new ArrayList<PaperDetailExp>();//客观题
|
|
|
+ List<PaperDetailExp> subjectiveDetails = new ArrayList<PaperDetailExp>();//主观题
|
|
|
+ double objectiveScore = 0;
|
|
|
+ double subjectiveScore = 0;
|
|
|
+ paperExp.setTitle(CommonUtils.PAPER_TITLE);
|
|
|
+ paperExp.setSubTitle(CommonUtils.PAPER_SUB_TITLE);
|
|
|
+ //获取大题
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
+
|
|
|
+ int objectNumber = 1;//客观题大题序号
|
|
|
+ int objetcUnitSum = 0;
|
|
|
+ for(int i = 0; i < paperDetails.size(); i++){
|
|
|
+ PaperDetailExp paperDetailExp = BeanCopierUtil.copyProperties(paperDetails.get(i), PaperDetailExp.class);
|
|
|
+ List<PaperDetailUnit> paperDetailUnits =
|
|
|
+ paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
|
|
|
+ //把大题分类 :客观题和主观题
|
|
|
+ List<PaperDetailUnitExp> paperDetailUnitExps =
|
|
|
+ BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitExp.class);
|
|
|
+ //选择题,套题下选择题 选项顺序重新排列
|
|
|
+ paperService.reorderChoicequestionOption(paperDetailUnitExps);
|
|
|
+ paperDetailExp.setPaperDetailUnits(paperDetailUnitExps);
|
|
|
+ boolean hasTextAnswer = false;//判断主观题
|
|
|
+ if(paperDetailUnits.get(0).getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
+ for(Question ques :paperDetailUnits.get(0).getQuestion().getSubQuestions()){
|
|
|
+ if(ques.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
+ hasTextAnswer = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if(paperDetailUnits.get(0).getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION) {
|
|
|
+ hasTextAnswer = true;
|
|
|
+ }
|
|
|
+ if(hasTextAnswer){
|
|
|
+ subjectiveDetails.add(paperDetailExp);
|
|
|
+ subjectiveScore += paperDetailExp.getScore();
|
|
|
+ } else {
|
|
|
+ objectiveDetails.add(paperDetailExp);
|
|
|
+ paperDetailExp.setNumber(objectNumber);
|
|
|
+ paperDetailExp.setCnNum(CommonUtils.toCHNum(objectNumber));
|
|
|
+ objectiveScore += paperDetailExp.getScore();
|
|
|
+ objetcUnitSum += paperDetailExp.getUnitCount();
|
|
|
+ objectNumber++;
|
|
|
+ }
|
|
|
+ setExpTitle(paperDetailExp);
|
|
|
+ }
|
|
|
+
|
|
|
+ paperExp.setObjectiveDetails(objectiveDetails);
|
|
|
+ paperExp.setSubjectiveDetails(subjectiveDetails);
|
|
|
+ paperExp.setObjectiveScore(objectiveScore);
|
|
|
+ paperExp.setSubjectiveScore(subjectiveScore);
|
|
|
+ if(objectiveDetails.size()>0){
|
|
|
+ setUnitExpNumber(objectiveDetails, 0);
|
|
|
+ }
|
|
|
+ if(subjectiveDetails.size()>0){
|
|
|
+ for(PaperDetailExp subDetail:subjectiveDetails){
|
|
|
+ subDetail.setNumber(objectNumber);
|
|
|
+ subDetail.setCnNum(CommonUtils.toCHNum(objectNumber));
|
|
|
+ objectNumber++;
|
|
|
+ }
|
|
|
+ setUnitExpNumber(subjectiveDetails,objetcUnitSum);
|
|
|
+ }
|
|
|
+ returnMap.put("paper", paperExp);
|
|
|
+ returnMap.put("fileName", paperExp.getName());
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载试卷
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void dzkdDownloadPaper(String id, HttpServletResponse response) throws Exception {
|
|
|
+ Map dataMap = initExportPaper(id);
|
|
|
+ List<String> fileList = new ArrayList<String>();
|
|
|
+ if (dataMap.get("fileName") != null) {
|
|
|
+ String paperfileName = (String) dataMap.get("fileName");
|
|
|
+ String answerFileName = paperfileName+"__答案";
|
|
|
+ DocxProcessUtil.exportPaper(dataMap, paperfileName,"dzkd_paper_template.ftl");
|
|
|
+ DocxProcessUtil.exportAnswer(dataMap,answerFileName,"dzkd_answer_template.ftl");
|
|
|
+ DocxProcessUtil.processImage(paperfileName, exportPaperService.getPkgList(id));
|
|
|
+ DocxProcessUtil.processImage(answerFileName, exportPaperService.getPkgList(id));
|
|
|
+ fileList.add(paperfileName);
|
|
|
+ fileList.add(answerFileName);
|
|
|
+ DocxProcessUtil.processDownload(fileList, response);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setExpTitle(PaperDetailExp paperDetailExp){
|
|
|
+ String title ="";
|
|
|
+ String totalScore = BigDecimal.valueOf(paperDetailExp.getScore()).stripTrailingZeros().toPlainString();
|
|
|
+ String unitScore = BigDecimal.valueOf(paperDetailExp.getPaperDetailUnits().get(0).getScore()).stripTrailingZeros().toPlainString();
|
|
|
+ QuesStructType type = paperDetailExp.getPaperDetailUnits().get(0).getQuestionType();
|
|
|
+ if(type == QuesStructType.SINGLE_ANSWER_QUESTION){
|
|
|
+ paperDetailExp.setName("单项选择题");
|
|
|
+ title = "(本大题共"+paperDetailExp.getUnitCount()+"小题,每小题"+unitScore+"分共"+totalScore+"分)。"
|
|
|
+ + "在每小题列出的四个备选中只有一个符合题目要求的,请将其选出并将“答题卡”的相应代码涂黑,错涂、多涂或未涂均无分";
|
|
|
+ } else if (type == QuesStructType.BOOL_ANSWER_QUESTION){
|
|
|
+ paperDetailExp.setName("判断题");
|
|
|
+ title = "(本大题共"+paperDetailExp.getUnitCount()+"小题,每小题"+unitScore+"分共"+totalScore+"分。正确的填涂A、错误填涂B。错涂、多涂或未涂均无分)";
|
|
|
+ } else if(type == QuesStructType.FILL_BLANK_QUESTION){
|
|
|
+ paperDetailExp.setName("填空题");
|
|
|
+ int blankNum = 0;
|
|
|
+ for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
|
|
|
+ String tempStr = unit.getQuestion().getQuesBody().replaceAll("###", "");
|
|
|
+ int lenTimes = (unit.getQuestion().getQuesBody().length()-tempStr.length())/"###".length();//出现的次数
|
|
|
+ blankNum +=lenTimes;
|
|
|
+ }
|
|
|
+ title = "(本大题共"+blankNum+"个空格,将每空答在答题卡 “1—"+blankNum+"”相应的序号上。每空"+unitScore+"分共"+totalScore+"分)";
|
|
|
+ } else {
|
|
|
+ title = "(本大题共"+paperDetailExp.getUnitCount()+"小题,每小题"+unitScore+"分共"+totalScore+"分)";
|
|
|
+ }
|
|
|
+ paperDetailExp.setTitle(title);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setUnitExpNumber(List<PaperDetailExp> paperDetails,int startIndxt) throws Exception {
|
|
|
+ int subNum = startIndxt;
|
|
|
+ for(PaperDetailExp paperDetail: paperDetails){
|
|
|
+ for(PaperDetailUnitExp paperDetailUnit:paperDetail.getPaperDetailUnits()){
|
|
|
+ List<QuesOption> optionList = paperDetailUnit.getQuestion().getQuesOptions();
|
|
|
+ if(optionList != null && optionList.size() > 0){
|
|
|
+ int index = 0;
|
|
|
+ for(QuesOption quesOption:optionList){
|
|
|
+ quesOption.setOptionBodyWord(exportPaperService.setOptionNum(quesOption.getOptionBodyWord(),exportPaperService.getOptionNum(index)));
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
+ //套题序号
|
|
|
+ if(subQuesList != null && subQuesList.size() > 0){
|
|
|
+
|
|
|
+ question.setQuesBodyWord(exportPaperService.replaceQuesBlank(question.getQuesBodyWord(),subNum + 1));
|
|
|
+
|
|
|
+ for(Question subQues:subQuesList){
|
|
|
+ int curSubNum = ++subNum;
|
|
|
+ subQues.setQuesBodyWord(exportPaperService.setSubQuesNum(subQues.getQuesBodyWord(),curSubNum));
|
|
|
+ subQues.setQuesAnswerWord(exportPaperService.setSubQuesNum(subQues.getQuesAnswerWord(),curSubNum));
|
|
|
+ subQues.setQuesBodyWord(exportPaperService.replaceQuesBlank(subQues.getQuesBodyWord(),curSubNum));
|
|
|
+ List<QuesOption> subOptionList = subQues.getQuesOptions();
|
|
|
+ if(subOptionList != null && subOptionList.size() > 0){
|
|
|
+ int sub_index = 0;
|
|
|
+ for(QuesOption quesOption:subOptionList){
|
|
|
+ quesOption.setOptionBodyWord(exportPaperService.setOptionNum(quesOption.getOptionBodyWord(),exportPaperService.getOptionNum(sub_index)));
|
|
|
+ sub_index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ int curSubNum = ++subNum;
|
|
|
+ question.setQuesBodyWord(exportPaperService.setSubQuesNum(question.getQuesBodyWord(),curSubNum));
|
|
|
+ question.setQuesAnswerWord(exportPaperService.setSubQuesNum(question.getQuesAnswerWord(),curSubNum));
|
|
|
+ question.setQuesBodyWord(exportPaperService.replaceQuesBlank(question.getQuesBodyWord(),curSubNum));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|