deason 5 jaren geleden
bovenliggende
commit
b34ca29768

+ 80 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/QuestionAnswerConvert.java

@@ -0,0 +1,80 @@
+package cn.com.qmth.examcloud.core.questions.service.bean;
+
+import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
+import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
+import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class QuestionAnswerConvert {
+
+    /**
+     * 设置试题答案
+     */
+    public static List<String> parseQuestionAnswerList(Question question) {
+        List<String> values = new ArrayList<>();
+
+        if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
+            //判断题答案
+            if (question.getQuesAnswer().equals("正确")) {
+                values.add("true");
+            } else if (question.getQuesAnswer().equals("错误")) {
+                values.add("false");
+            }
+            return values;
+        }
+
+        /*if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
+            //填空题答案
+            String[] rightAnswers = question.getQuesAnswer().split("##");
+            for (String value : rightAnswers) {
+                values.add(value);
+            }
+            return values;
+        }*/
+
+        values.add(question.getQuesAnswer());
+        return values;
+    }
+
+    public static String[] parseQuestionAnswers(Question question) {
+        List<String> rightAnswers = parseQuestionAnswerList(question);
+
+        if (rightAnswers.size() == 0) {
+            return new String[0];
+        }
+
+        return rightAnswers.toArray(new String[rightAnswers.size()]);
+    }
+
+    /**
+     * 设置单选题和多选题答案
+     */
+    public static List<String> parseQuestionOptionAnswerList(List<QuesOption> options) {
+        List<String> values = new ArrayList<>();
+
+        if (CollectionUtils.isNotEmpty(options)) {
+            for (int i = 0; i < options.size(); i++) {
+                QuesOption option = options.get(i);
+                if (option.getIsCorrect() == 1) {
+                    values.add(String.valueOf(i));
+                }
+            }
+        }
+
+        return values;
+    }
+
+    public static String[] parseQuestionOptionAnswers(List<QuesOption> options) {
+        List<String> rightAnswers = parseQuestionOptionAnswerList(options);
+
+        if (rightAnswers.size() == 0) {
+            return new String[0];
+        }
+
+        return rightAnswers.toArray(new String[rightAnswers.size()]);
+    }
+
+}

+ 5 - 60
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigProviderServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.core.questions.dao.*;
 import cn.com.qmth.examcloud.core.questions.dao.entity.*;
 import cn.com.qmth.examcloud.core.questions.service.*;
+import cn.com.qmth.examcloud.core.questions.service.bean.QuestionAnswerConvert;
 import cn.com.qmth.examcloud.core.questions.service.bean.extract.ExtractConfigPaper;
 import cn.com.qmth.examcloud.core.questions.service.config.SysProperty;
 import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
@@ -434,70 +435,14 @@ public class ExtractConfigProviderServiceImpl implements ExtractConfigProviderSe
                 }
             }
             defaultQuestionUnit.setQuestionOptionList(defaultQuestionOptions);
-            defaultQuestionUnit.setRightAnswer(getSelectQuestionAnswer(quesOptions));
+            defaultQuestionUnit.setRightAnswer(QuestionAnswerConvert.parseQuestionOptionAnswers(quesOptions));
         } else {
-            defaultQuestionUnit.setRightAnswer(getAnswer(question));
+            defaultQuestionUnit.setRightAnswer(QuestionAnswerConvert.parseQuestionAnswers(question));
         }
 
         return defaultQuestionUnit;
     }
 
-    /**
-     * 设置单选题和多选题 答案
-     *
-     * @param quesOptions
-     * @return
-     */
-    private String[] getSelectQuestionAnswer(List<QuesOption> quesOptions) {
-        List<String> list = new ArrayList<>();
-
-        if (CollectionUtils.isNotEmpty(quesOptions)) {
-            for (int i = 0; i < quesOptions.size(); i++) {
-                QuesOption quesOption = quesOptions.get(i);
-                if (quesOption.getIsCorrect() == 1) {
-                    list.add(String.valueOf(i));
-                }
-            }
-        }
-
-        if (list.size() > 0) {
-            return list.toArray(new String[list.size()]);
-        }
-
-        return new String[0];
-    }
-
-    /**
-     * 设置试题答案
-     *
-     * @param question
-     * @return
-     */
-    private String[] getAnswer(Question question) {
-        String[] rightAnswer = null;
-        //判断题答案
-        if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
-            if (question.getQuesAnswer().equals("正确")) {
-                rightAnswer = new String[1];
-                rightAnswer[0] = "true";
-                return rightAnswer;
-            }
-            if (question.getQuesAnswer().equals("错误")) {
-                rightAnswer = new String[1];
-                rightAnswer[0] = "false";
-                return rightAnswer;
-            }
-        }
-        //填空题答案
-		/*if(question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION){
-			rightAnswer = question.getQuesAnswer().split("##");
-			return rightAnswer;
-		}*/
-        rightAnswer = new String[1];
-        rightAnswer[0] = question.getQuesAnswer();
-        return rightAnswer;
-    }
-
     /**
      * html中添加音频标签
      *
@@ -672,7 +617,7 @@ public class ExtractConfigProviderServiceImpl implements ExtractConfigProviderSe
                 String answer = "";
                 for (Question subQuestion : subList) {
                     if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
-                        String[] answers = getSelectQuestionAnswer(subQuestion.getQuesOptions());
+                        String[] answers = QuestionAnswerConvert.parseQuestionOptionAnswers(subQuestion.getQuesOptions());
                         for (int i = 0; i < answers.length; i++) {
                             if (i == 0) {
                                 answer = answers[i];
@@ -694,7 +639,7 @@ public class ExtractConfigProviderServiceImpl implements ExtractConfigProviderSe
         } else {
             String answer = "";
             if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
-                String[] answers = getSelectQuestionAnswer(question.getQuesOptions());
+                String[] answers = QuestionAnswerConvert.parseQuestionOptionAnswers(question.getQuesOptions());
                 for (int i = 0; i < answers.length; i++) {
                     if (i == 0) {
                         answer = answers[i];