|
@@ -15,6 +15,7 @@ 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.PaperDetailExp;
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperExp;
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperExp;
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -31,17 +32,15 @@ import java.util.List;
|
|
*/
|
|
*/
|
|
public class PreviewPaperHandler {
|
|
public class PreviewPaperHandler {
|
|
private static final Logger log = LoggerFactory.getLogger(PreviewPaperHandler.class);
|
|
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 DETAIL_STYLE = "class=\"e_detail\"";//试卷大题样式
|
|
private final static String QUESTION_STYLE = "class=\"e_question\"";//试题标题样式
|
|
private final static String QUESTION_STYLE = "class=\"e_question\"";//试题标题样式
|
|
private final static String OPTION_STYLE = "class=\"e_option\"";//试题答案项样式
|
|
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 OPTION_END_STYLE = "class=\"e_option e_option_end\"";//试题答案结束项样式
|
|
|
|
+
|
|
|
|
+ private final static String FORMAT_DETAIL = "<p %s><b>%s、%s</b></p>";//大题标题格式
|
|
private final static String FORMAT_QUESTION = "<p %s>%s、%s</p>";//试题标题格式
|
|
private final static String FORMAT_QUESTION = "<p %s>%s、%s</p>";//试题标题格式
|
|
- private final static String FORMAT_SUB_QUESTION = "<p %s>%s、%s</p>";//子试题标题格式
|
|
|
|
private final static String FORMAT_OPTION = "<p %s>%s、%s</p>";//选项内容格式
|
|
private final static String FORMAT_OPTION = "<p %s>%s、%s</p>";//选项内容格式
|
|
|
|
+
|
|
private final static String[] REGEX_FILL_1 = {"[#][#]", "____"};//正则关键字
|
|
private final static String[] REGEX_FILL_1 = {"[#][#]", "____"};//正则关键字
|
|
private final static String[] REGEX_FILL_2 = {"[_][#]", "_"};//正则关键字
|
|
private final static String[] REGEX_FILL_2 = {"[_][#]", "_"};//正则关键字
|
|
|
|
|
|
@@ -55,8 +54,7 @@ public class PreviewPaperHandler {
|
|
}
|
|
}
|
|
|
|
|
|
List<PaperDetailExp> details = data.getPaperDetails();
|
|
List<PaperDetailExp> details = data.getPaperDetails();
|
|
- if (details == null || details.size() == 0) {
|
|
|
|
- log.warn("Paper detail is empty.");
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(details)) {
|
|
return "[]";
|
|
return "[]";
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,17 +62,21 @@ public class PreviewPaperHandler {
|
|
for (int x = 0; x < details.size(); x++) {
|
|
for (int x = 0; x < details.size(); x++) {
|
|
PaperDetailExp detail = details.get(x);
|
|
PaperDetailExp detail = details.get(x);
|
|
if (StringUtils.isNotBlank(detail.getTitle())) {
|
|
if (StringUtils.isNotBlank(detail.getTitle())) {
|
|
- htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), replaceTagP(detail.getName() + detail.getTitle())));
|
|
|
|
|
|
+ htmlTags.add(String.format(FORMAT_DETAIL, DETAIL_STYLE, detail.getCnNum(), replaceTagP(detail.getName() + detail.getTitle())));
|
|
} else {
|
|
} else {
|
|
- htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), replaceTagP(detail.getName())));
|
|
|
|
|
|
+ htmlTags.add(String.format(FORMAT_DETAIL, DETAIL_STYLE, detail.getCnNum(), replaceTagP(detail.getName())));
|
|
}
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(detail.getTitleDetail())) {
|
|
if (StringUtils.isNotBlank(detail.getTitleDetail())) {
|
|
- htmlTags.add(String.format("<p>%s</p>", replaceTagP(detail.getTitleDetail())));
|
|
|
|
|
|
+ htmlTags.add(String.format("<p><b>%s</b></p>", replaceTagP(detail.getTitleDetail())));
|
|
}
|
|
}
|
|
|
|
|
|
//封装大题的试题列表
|
|
//封装大题的试题列表
|
|
List<PaperDetailUnitExp> units = detail.getPaperDetailUnits();
|
|
List<PaperDetailUnitExp> units = detail.getPaperDetailUnits();
|
|
|
|
+ if (CollectionUtils.isEmpty(units)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
for (int y = 0; y < units.size(); y++) {
|
|
for (int y = 0; y < units.size(); y++) {
|
|
PaperDetailUnitExp unit = units.get(y);
|
|
PaperDetailUnitExp unit = units.get(y);
|
|
Question question = unit.getQuestion();
|
|
Question question = unit.getQuestion();
|
|
@@ -102,7 +104,7 @@ public class PreviewPaperHandler {
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
//套题的子题
|
|
//套题的子题
|
|
List<Question> subQuestions = question.getSubQuestions();
|
|
List<Question> subQuestions = question.getSubQuestions();
|
|
- if (subQuestions != null && subQuestions.size() > 0) {
|
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(subQuestions)) {
|
|
for (int m = 0; m < subQuestions.size(); m++) {
|
|
for (int m = 0; m < subQuestions.size(); m++) {
|
|
Question subQues = subQuestions.get(m);
|
|
Question subQues = subQuestions.get(m);
|
|
|
|
|
|
@@ -115,7 +117,7 @@ public class PreviewPaperHandler {
|
|
//题干 替换特殊关键字
|
|
//题干 替换特殊关键字
|
|
subBody = replaceFill(subQues, subBody);
|
|
subBody = replaceFill(subQues, subBody);
|
|
String subQuesNumber = subQues.getQuesParams().get("number");
|
|
String subQuesNumber = subQues.getQuesParams().get("number");
|
|
- htmlTags.add(String.format(FORMAT_SUB_QUESTION, QUESTION_STYLE, subQuesNumber, subBody));
|
|
|
|
|
|
+ htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, subQuesNumber, subBody));
|
|
|
|
|
|
//客观题 选项列表
|
|
//客观题 选项列表
|
|
handleOptionStyle(htmlTags, subQues);
|
|
handleOptionStyle(htmlTags, subQues);
|
|
@@ -127,20 +129,6 @@ public class PreviewPaperHandler {
|
|
return JsonUtil.toJson(htmlTags);
|
|
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())));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 转换试卷答案HTML内容
|
|
* 转换试卷答案HTML内容
|
|
*/
|
|
*/
|
|
@@ -150,7 +138,7 @@ public class PreviewPaperHandler {
|
|
}
|
|
}
|
|
|
|
|
|
List<PaperDetailExp> details = data.getPaperDetails();
|
|
List<PaperDetailExp> details = data.getPaperDetails();
|
|
- if (details == null || details.size() == 0) {
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(details)) {
|
|
return "[]";
|
|
return "[]";
|
|
}
|
|
}
|
|
|
|
|
|
@@ -158,12 +146,16 @@ public class PreviewPaperHandler {
|
|
List<String> htmlTags = new ArrayList<>();
|
|
List<String> htmlTags = new ArrayList<>();
|
|
for (PaperDetailExp detail : details) {
|
|
for (PaperDetailExp detail : details) {
|
|
if (StringUtils.isNotBlank(detail.getTitle())) {
|
|
if (StringUtils.isNotBlank(detail.getTitle())) {
|
|
- htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), detail.getName() + detail.getTitle()));
|
|
|
|
|
|
+ htmlTags.add(String.format(FORMAT_DETAIL, DETAIL_STYLE, detail.getCnNum(), replaceTagP(detail.getName() + detail.getTitle())));
|
|
} else {
|
|
} else {
|
|
- htmlTags.add(String.format(FORMAT_SECTION, SECTION_STYLE, detail.getCnNum(), detail.getName()));
|
|
|
|
|
|
+ htmlTags.add(String.format(FORMAT_DETAIL, DETAIL_STYLE, detail.getCnNum(), replaceTagP(detail.getName())));
|
|
}
|
|
}
|
|
|
|
|
|
List<PaperDetailUnitExp> units = detail.getPaperDetailUnits();
|
|
List<PaperDetailUnitExp> units = detail.getPaperDetailUnits();
|
|
|
|
+ if (CollectionUtils.isEmpty(units)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
for (PaperDetailUnitExp unit : units) {
|
|
for (PaperDetailUnitExp unit : units) {
|
|
Question question = unit.getQuestion();
|
|
Question question = unit.getQuestion();
|
|
if (question == null) {
|
|
if (question == null) {
|
|
@@ -173,10 +165,10 @@ public class PreviewPaperHandler {
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
//htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), "题"));
|
|
//htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, unit.getNumber(), "题"));
|
|
List<Question> subQuestions = question.getSubQuestions();
|
|
List<Question> subQuestions = question.getSubQuestions();
|
|
- if (subQuestions != null && subQuestions.size() > 0) {
|
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(subQuestions)) {
|
|
for (Question subQues : subQuestions) {
|
|
for (Question subQues : subQuestions) {
|
|
String subQuesNumber = subQues.getQuesParams().get("number");
|
|
String subQuesNumber = subQues.getQuesParams().get("number");
|
|
- htmlTags.add(String.format(FORMAT_SUB_QUESTION, QUESTION_STYLE, subQuesNumber, replaceFill(subQues, subQues.getQuesAnswer())));
|
|
|
|
|
|
+ htmlTags.add(String.format(FORMAT_QUESTION, QUESTION_STYLE, subQuesNumber, replaceFill(subQues, subQues.getQuesAnswer())));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -187,6 +179,20 @@ public class PreviewPaperHandler {
|
|
return JsonUtil.toJson(htmlTags);
|
|
return JsonUtil.toJson(htmlTags);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static void handleOptionStyle(List<String> htmlTags, Question question) {
|
|
|
|
+ List<QuesOption> options = question.getQuesOptions();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(options)) {
|
|
|
|
+ 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 String formatValue(Double score) {
|
|
public static String formatValue(Double score) {
|
|
if (score == null) {
|
|
if (score == null) {
|
|
return "";
|
|
return "";
|
|
@@ -220,13 +226,13 @@ public class PreviewPaperHandler {
|
|
* 去掉"p"标签
|
|
* 去掉"p"标签
|
|
*/
|
|
*/
|
|
public static String replaceTagP(String str) {
|
|
public static String replaceTagP(String str) {
|
|
- if (str == null) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (StringUtils.isEmpty(str)) {
|
|
|
|
+ return "";
|
|
}
|
|
}
|
|
return str.replace("<p>", "")
|
|
return str.replace("<p>", "")
|
|
.replace("</p>", "")
|
|
.replace("</p>", "")
|
|
- .replace("<P>", "")
|
|
|
|
- .replace("</P>", "");
|
|
|
|
|
|
+ .replace("<span>", "")
|
|
|
|
+ .replace("</span>", "");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|