|
@@ -5,6 +5,7 @@ import java.util.Set;
|
|
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.docx4j.openpackaging.exceptions.InvalidFormatException;
|
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
@@ -54,6 +55,17 @@ public class QuesServiceImpl implements QuesService{
|
|
|
|
|
|
@Autowired
|
|
|
private CourseRepo courseRepo;
|
|
|
+
|
|
|
+ private static WordprocessingMLPackage wordMLPackage = null;
|
|
|
+
|
|
|
+ static{
|
|
|
+ try {
|
|
|
+ wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 套题子题按序号自动生成ID
|
|
|
*
|
|
@@ -138,6 +150,7 @@ public class QuesServiceImpl implements QuesService{
|
|
|
} else {
|
|
|
question.setUpdateTime(now);
|
|
|
}
|
|
|
+ setSelectQuestionAnswer(question,"");
|
|
|
updateSubId(question);
|
|
|
updateQuesWord(question);
|
|
|
if(question.getHasAudio()!=null&&question.getHasAudio()){
|
|
@@ -300,9 +313,10 @@ public class QuesServiceImpl implements QuesService{
|
|
|
* @param question
|
|
|
*/
|
|
|
public void updateQuesWord(Question question) {
|
|
|
- WordprocessingMLPackage wordMLPackage = null;
|
|
|
try {
|
|
|
- wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ if(wordMLPackage==null){
|
|
|
+ wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ }
|
|
|
updateQuesWordUnit(wordMLPackage, question);
|
|
|
List<Question> subQuesList = question.getSubQuestions();
|
|
|
if (subQuesList != null && subQuesList.size() > 0) {
|
|
@@ -323,10 +337,15 @@ public class QuesServiceImpl implements QuesService{
|
|
|
question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, quesBody));
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(quesAnswer)
|
|
|
- && question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
|
|
|
- && question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
+ && (question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION)){
|
|
|
question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, quesAnswer));
|
|
|
}
|
|
|
+ if(!StringUtils.isEmpty(quesAnswer)&&
|
|
|
+ (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ ||question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION)){
|
|
|
+ question.setQuesAnswerWord(makeQuesAnswerWord(quesAnswer));
|
|
|
+ }
|
|
|
List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
if (quesOptions != null && quesOptions.size() > 0) {
|
|
|
for (QuesOption quesOption : quesOptions) {
|
|
@@ -337,6 +356,19 @@ public class QuesServiceImpl implements QuesService{
|
|
|
}
|
|
|
question.setQuesPkg(DocxProcessUtil.getPkgByte(wordMLPackage));
|
|
|
}
|
|
|
+
|
|
|
+ private String makeQuesAnswerWord(String quesAnswer){
|
|
|
+ String template = "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidR=\"00F65544\" w:rsidP=\"00F65544\" w:rsidRDefault=\"001738E2\">"+
|
|
|
+ "<w:r w:rsidR=\"00F65544\">"+
|
|
|
+ "<w:rPr>"+
|
|
|
+ "<w:rFonts w:hint=\"eastAsia\"/>"+
|
|
|
+ "<w:szCs w:val=\"21\"/>"+
|
|
|
+ "</w:rPr>"+
|
|
|
+ "<w:t>quesAnswer</w:t>"+
|
|
|
+ "</w:r>"+
|
|
|
+ "</w:p>";
|
|
|
+ return template.replace("quesAnswer", quesAnswer);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取试题有效文本
|
|
@@ -359,5 +391,56 @@ public class QuesServiceImpl implements QuesService{
|
|
|
}
|
|
|
return quesText.toString();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setSelectQuestionAnswer(Question question, String optionOrder) {
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ question.setQuesAnswer(getSelectQuestionAnswer(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(";")){
|
|
|
+ subQuestion.setQuesAnswer(getSelectQuestionAnswer(subQuestion, optionOrder.split(";")[index]));
|
|
|
+ }else{
|
|
|
+ subQuestion.setQuesAnswer(getSelectQuestionAnswer(subQuestion, ""));
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSelectQuestionAnswer(Question question,String optionOrder){
|
|
|
+ String answer = "";
|
|
|
+ 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){
|
|
|
+ answer += 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){
|
|
|
+ answer += CommonUtils.getOptionNum(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return answer;
|
|
|
+ }
|
|
|
}
|
|
|
|