|
@@ -1,20 +1,20 @@
|
|
|
/*
|
|
|
* *************************************************
|
|
|
* Copyright (c) 2019 QMTH. All Rights Reserved.
|
|
|
- * Created by Deason on 2019-01-18 16:55:58.
|
|
|
+ * Created by Deason on 2019-05-23 11:39:26.
|
|
|
* *************************************************
|
|
|
*/
|
|
|
|
|
|
-package cn.com.qmth.examcloud.core.questions.api.bean;
|
|
|
+package cn.com.qmth.examcloud.core.questions.service.bean.paper;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
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 cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailExp;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperExp;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -23,11 +23,21 @@ import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-public class ParsePaper {
|
|
|
- private static final Logger log = LoggerFactory.getLogger(ParsePaper.class);
|
|
|
+/**
|
|
|
+ * 试卷预览内容处理
|
|
|
+ *
|
|
|
+ * @author: fengdesheng
|
|
|
+ * @since: 2019/5/23
|
|
|
+ */
|
|
|
+public class PreviewPaperHandler {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(PreviewPaperHandler.class);
|
|
|
+ private final static String SINGLE_TITLE = "<p><b>在每小题列出的备选项中只有一个符合题目要求的,请将其选出并将“答题卡”的相应代码涂黑,错涂、多涂或未涂均无分。</b></p>";//单选题提示语
|
|
|
+ private final static String MULTIPLE_TITLE = "<p><b>在每小题列出的备选项中有一个或多个符合题目要求的,请将符合项选出并将“答题卡”的相应代码涂黑。</b></p>";//多选题提示语
|
|
|
+ private final static String BOOL_TITLE = "<p><b>正确的填涂√、错误填涂×。错涂、多涂或未涂均无分正确的填涂√、错误填涂×。错涂、多涂或未涂均无分。</b></p>";//判断题提示语
|
|
|
private final static String SECTION_STYLE = "class=\"e_detail\"";//试卷大题样式
|
|
|
private final static String QUESTION_STYLE = "class=\"e_question\"";//试题标题样式
|
|
|
private final static String OPTION_STYLE = "class=\"e_option\"";//试题答案项样式
|
|
|
+ private final static String OPTION_END_STYLE = "class=\"e_option e_option_end\"";//试题答案项样式
|
|
|
private final static String FORMAT_SECTION = "<p %s><b>%s、%s</b></p>";//大题标题格式
|
|
|
private final static String FORMAT_QUESTION = "<p %s>%s、%s</p>";//试题标题格式
|
|
|
private final static String FORMAT_SUB_QUESTION = "<p %s>%s、%s</p>";//子试题标题格式
|
|
@@ -35,30 +45,32 @@ public class ParsePaper {
|
|
|
private final static String[] REGEX_FILL_1 = {"[#][#]", "____"};//正则关键字
|
|
|
private final static String[] REGEX_FILL_2 = {"[_][#]", "_"};//正则关键字
|
|
|
|
|
|
- public static List<String> convertPaperHtml(PaperExp data) {
|
|
|
+ /**
|
|
|
+ * 转换试卷的HTML内容
|
|
|
+ */
|
|
|
+ public static String convertPaperHtml(PaperExp data) {
|
|
|
if (data == null) {
|
|
|
- log.warn("Paper is null.");
|
|
|
+ log.warn("Paper data is not exist.");
|
|
|
throw new StatusException("500", "试卷信息不存在!");
|
|
|
}
|
|
|
|
|
|
List<PaperDetailExp> details = data.getPaperDetails();
|
|
|
if (details == null || details.size() == 0) {
|
|
|
- log.warn("Paper Detail is empty.");
|
|
|
- return Lists.newArrayList();
|
|
|
+ log.warn("Paper detail is empty.");
|
|
|
+ return "[]";
|
|
|
}
|
|
|
|
|
|
- //封装试卷的HTML内容
|
|
|
- List<String> htmlList = new ArrayList<>();
|
|
|
+ List<String> htmlTags = new ArrayList<>();
|
|
|
for (int x = 0; x < details.size(); x++) {
|
|
|
PaperDetailExp detail = details.get(x);
|
|
|
if (StringUtils.isNotBlank(detail.getTitle())) {
|
|
|
- htmlList.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), replaceTagP(detail.getName() + detail.getTitle())));
|
|
|
+ htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), replaceTagP(detail.getName() + detail.getTitle())));
|
|
|
} else {
|
|
|
- htmlList.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), replaceTagP(detail.getName())));
|
|
|
+ htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), replaceTagP(detail.getName())));
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(detail.getTitleDetail())) {
|
|
|
- htmlList.add(String.format("<p>%s</p>", replaceTagP(detail.getTitleDetail())));
|
|
|
+ htmlTags.add(String.format("<p>%s</p>", replaceTagP(detail.getTitleDetail())));
|
|
|
}
|
|
|
|
|
|
//封装大题的试题列表
|
|
@@ -79,18 +91,13 @@ public class ParsePaper {
|
|
|
//题干 替换特殊关键字
|
|
|
qBody = replaceFill(question, qBody);
|
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- htmlList.add(String.format("<p %s>%s</p>", QUESTION_STYLE, qBody));
|
|
|
+ htmlTags.add(String.format("<p %s>%s</p>", QUESTION_STYLE, qBody));
|
|
|
} else {
|
|
|
- htmlList.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), qBody));
|
|
|
+ htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), qBody));
|
|
|
}
|
|
|
|
|
|
//客观题 选项列表
|
|
|
- List<QuesOption> options = question.getQuesOptions();
|
|
|
- if (options != null && options.size() > 0) {
|
|
|
- for (QuesOption option : options) {
|
|
|
- htmlList.add(String.format(FORMAT_OPTION, OPTION_STYLE, formatNum(option.getNumber()), replaceTagP(option.getOptionBody())));
|
|
|
- }
|
|
|
- }
|
|
|
+ handleOptionStyle(htmlTags, question);
|
|
|
|
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
//套题的子题
|
|
@@ -108,41 +115,52 @@ public class ParsePaper {
|
|
|
//题干 替换特殊关键字
|
|
|
subBody = replaceFill(subQues, subBody);
|
|
|
String subQuesNumber = subQues.getQuesParams().get("number");
|
|
|
- htmlList.add(String.format(FORMAT_SUB_QUESTION, QUESTION_STYLE, subQuesNumber, subBody));
|
|
|
+ htmlTags.add(String.format(FORMAT_SUB_QUESTION, QUESTION_STYLE, subQuesNumber, subBody));
|
|
|
|
|
|
//客观题 选项列表
|
|
|
- List<QuesOption> subOptions = subQues.getQuesOptions();
|
|
|
- if (subOptions != null && subOptions.size() > 0) {
|
|
|
- for (int n = 0; n < subOptions.size(); n++) {
|
|
|
- QuesOption subOpt = subOptions.get(n);
|
|
|
- htmlList.add(String.format(FORMAT_OPTION, OPTION_STYLE, formatNum(subOpt.getNumber()), replaceTagP(subOpt.getOptionBody())));
|
|
|
- }
|
|
|
- }
|
|
|
+ handleOptionStyle(htmlTags, subQues);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return htmlList;
|
|
|
+ return JsonUtil.toJson(htmlTags);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void handleOptionStyle(List<String> htmlTags, Question question) {
|
|
|
+ List<QuesOption> options = question.getQuesOptions();
|
|
|
+ if (options != null && options.size() > 0) {
|
|
|
+ for (int i = 0; i < options.size(); i++) {
|
|
|
+ QuesOption option = options.get(i);
|
|
|
+ if (i == (options.size() - 1)) {
|
|
|
+ htmlTags.add(String.format(FORMAT_OPTION, OPTION_END_STYLE, formatNum(option.getNumber()), replaceTagP(option.getOptionBody())));
|
|
|
+ } else {
|
|
|
+ htmlTags.add(String.format(FORMAT_OPTION, OPTION_STYLE, formatNum(option.getNumber()), replaceTagP(option.getOptionBody())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public static List<String> convertAnswerHtml(PaperExp data) {
|
|
|
+ /**
|
|
|
+ * 转换试卷答案HTML内容
|
|
|
+ */
|
|
|
+ public static String convertPaperAnswerHtml(PaperExp data) {
|
|
|
if (data == null) {
|
|
|
throw new StatusException("500", "试卷信息不存在!");
|
|
|
}
|
|
|
|
|
|
List<PaperDetailExp> details = data.getPaperDetails();
|
|
|
if (details == null || details.size() == 0) {
|
|
|
- return Lists.newArrayList();
|
|
|
+ return "[]";
|
|
|
}
|
|
|
|
|
|
//封装试卷答案的HTML内容
|
|
|
- List<String> htmlList = new ArrayList<>();
|
|
|
+ List<String> htmlTags = new ArrayList<>();
|
|
|
for (PaperDetailExp detail : details) {
|
|
|
if (StringUtils.isNotBlank(detail.getTitle())) {
|
|
|
- htmlList.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), detail.getName() + detail.getTitle()));
|
|
|
+ htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), detail.getName() + detail.getTitle()));
|
|
|
} else {
|
|
|
- htmlList.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), detail.getName()));
|
|
|
+ htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), detail.getName()));
|
|
|
}
|
|
|
|
|
|
List<PaperDetailUnitExp> units = detail.getPaperDetailUnits();
|
|
@@ -153,20 +171,20 @@ public class ParsePaper {
|
|
|
}
|
|
|
|
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- //htmlList.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), "题"));
|
|
|
+ //htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), "题"));
|
|
|
List<Question> subQuestions = question.getSubQuestions();
|
|
|
if (subQuestions != null && subQuestions.size() > 0) {
|
|
|
for (Question subQues : subQuestions) {
|
|
|
String subQuesNumber = subQues.getQuesParams().get("number");
|
|
|
- htmlList.add(String.format(FORMAT_SUB_QUESTION, QUESTION_STYLE, subQuesNumber, replaceFill(subQues, subQues.getQuesAnswer())));
|
|
|
+ htmlTags.add(String.format(FORMAT_SUB_QUESTION, QUESTION_STYLE, subQuesNumber, replaceFill(subQues, subQues.getQuesAnswer())));
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- htmlList.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), replaceFill(question, question.getQuesAnswer())));
|
|
|
+ htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), replaceFill(question, question.getQuesAnswer())));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return htmlList;
|
|
|
+ return JsonUtil.toJson(htmlTags);
|
|
|
}
|
|
|
|
|
|
public static String formatValue(Double score) {
|