|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
@@ -23,7 +24,6 @@ import org.docx4j.jaxb.Context;
|
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
import org.docx4j.wml.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -95,6 +95,9 @@ public class ExportPaperService {
|
|
|
paperDetailExp.setTitle(getDetailTitle(paperDetailExp));
|
|
|
List<PaperDetailUnit> paperDetailUnits =
|
|
|
paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
|
|
|
+
|
|
|
+ setAnswerWord(paperDetailUnits);
|
|
|
+
|
|
|
List<PaperDetailUnitExp> paperDetailUnitExps =
|
|
|
BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitExp.class);
|
|
|
//选择题,套题下选择题 选项顺序重新排列
|
|
@@ -110,6 +113,131 @@ public class ExportPaperService {
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置答案
|
|
|
+ * @param answer
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public String getObjectAnswer(String answerWordMl,String answer) throws Exception {
|
|
|
+ String tmpStr = DocxProcessUtil.BODY_HEADER + answerWordMl + DocxProcessUtil.BODY_TAIL;
|
|
|
+ Body body = (Body)XmlUtils.unmarshalString(tmpStr,
|
|
|
+ Context.jc,Body.class);
|
|
|
+ List<Object> pList = body.getContent();
|
|
|
+ int index = 0;
|
|
|
+ for(Object pObj:pList){
|
|
|
+ if(index > 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ P p = (P) pObj;
|
|
|
+ List<Object> pContent = p.getContent();
|
|
|
+ pContent.removeAll(pContent);
|
|
|
+ R run = new R();
|
|
|
+ Text text = new Text();
|
|
|
+ text.setValue("[答案]:"+answer);
|
|
|
+ run.getContent().add(text);
|
|
|
+ pContent.add(0,run);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ StringBuffer pWordMl = new StringBuffer();
|
|
|
+ for(Object pObj:pList){
|
|
|
+ if(pObj instanceof P){
|
|
|
+ pWordMl.append(DocxProcessUtil.formatPWordMl(XmlUtils.marshaltoString(pObj)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pWordMl.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置答案
|
|
|
+ * @param answerWordMl
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public String getSubjectAnswer(String answerWordMl) throws Exception {
|
|
|
+ String tmpStr = DocxProcessUtil.BODY_HEADER + answerWordMl + DocxProcessUtil.BODY_TAIL;
|
|
|
+ Body body = (Body)XmlUtils.unmarshalString(tmpStr,
|
|
|
+ Context.jc,Body.class);
|
|
|
+ List<Object> pList = body.getContent();
|
|
|
+ int index = 0;
|
|
|
+ for(Object pObj:pList){
|
|
|
+ if(index > 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ P p = (P) pObj;
|
|
|
+ List<Object> pContent = p.getContent();
|
|
|
+ R run = new R();
|
|
|
+ Text text = new Text();
|
|
|
+ text.setValue("[答案]:");
|
|
|
+ run.getContent().add(text);
|
|
|
+ pContent.add(0,run);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ StringBuffer pWordMl = new StringBuffer();
|
|
|
+ for(Object pObj:pList){
|
|
|
+ if(pObj instanceof P){
|
|
|
+ pWordMl.append(DocxProcessUtil.formatPWordMl(XmlUtils.marshaltoString(pObj)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pWordMl.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAnswerWord(List<PaperDetailUnit> paperDetailUnits) throws Exception{
|
|
|
+ for (PaperDetailUnit paperDetailUnit : paperDetailUnits) {
|
|
|
+ if(paperDetailUnit==null||paperDetailUnit.getQuestion()==null){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String optionOrder = paperDetailUnit.getOptionOrder();
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ setAnswerWordUnit(question, optionOrder);
|
|
|
+ } else if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
+ List<Question> subQuestions = question.getSubQuestions();
|
|
|
+ int index = 0;
|
|
|
+ for (int k = 0; k < subQuestions.size(); k++) {
|
|
|
+ Question subQuestion = subQuestions.get(k);
|
|
|
+ if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ if(StringUtils.isNotEmpty(optionOrder) && optionOrder.contains(";")){
|
|
|
+ setAnswerWordUnit(subQuestion, optionOrder.split(";")[index]);
|
|
|
+ }else{
|
|
|
+ setAnswerWordUnit(subQuestion, "");
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ question.setQuesAnswerWord(getSubjectAnswer(question.getQuesAnswerWord()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAnswerWordUnit(Question question, String optionOrder) throws Exception{
|
|
|
+ List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
+ if(quesOptions == null || quesOptions.size() == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(optionOrder)){
|
|
|
+ int j = 0;
|
|
|
+ for(QuesOption quesOption : quesOptions){
|
|
|
+ if(quesOption.getIsCorrect() == 1){
|
|
|
+ question.setQuesAnswerWord(getObjectAnswer(question.getQuesAnswerWord(),CommonUtils.getOptionNum(j)));
|
|
|
+ }
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ String [] order = optionOrder.split(",");
|
|
|
+ for(int i = 0;i < order.length;i++){
|
|
|
+ for(QuesOption quesOption : quesOptions){
|
|
|
+ if(order[i].equals(quesOption.getNumber()) && quesOption.getIsCorrect() == 1){
|
|
|
+ question.setQuesAnswerWord(getObjectAnswer(question.getQuesAnswerWord(),CommonUtils.getOptionNum(i)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public String getDetailTitle(PaperDetailExp paperDetailExp){
|
|
|
int totalScore = paperDetailExp.getScore().intValue();
|
|
|
int count = paperDetailExp.getUnitCount();
|