|
@@ -39,12 +39,12 @@ import cn.com.qmth.examcloud.support.handler.richText.bean.SectionCollectionBean
|
|
|
import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
|
-import com.mysql.cj.util.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiResponse;
|
|
|
import io.swagger.annotations.ApiResponses;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -145,7 +145,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
}
|
|
|
|
|
|
String subjectCode = req.getSubjectCode();
|
|
|
- if (StringUtils.isNullOrEmpty(subjectCode)) {
|
|
|
+ if (StringUtils.isEmpty(subjectCode)) {
|
|
|
throw new StatusException("101002", "科目代码不允许为空");
|
|
|
}
|
|
|
|
|
@@ -211,7 +211,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
}
|
|
|
|
|
|
String subjectCode = req.getSubjectCode();
|
|
|
- if (StringUtils.isNullOrEmpty(subjectCode)) {
|
|
|
+ if (StringUtils.isEmpty(subjectCode)) {
|
|
|
throw new StatusException("105002", "科目代码不允许为空");
|
|
|
}
|
|
|
|
|
@@ -240,10 +240,10 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
OuterSubjectivePaperQuestionBean subPaperQues = new OuterSubjectivePaperQuestionBean();
|
|
|
|
|
|
//获取指定小题的题干相关信息
|
|
|
- QuestionCacheBean cachedQues = CacheHelper.getQuestion(examId, subjectCode, subQues.getPaperType(), subQues.getQuestionId());
|
|
|
- String strAnswer = getCorrectAnswer(subQues.getSubNumber(), subQues.getQuestionId(), cachedQues, subjectiveQuestions);
|
|
|
- String strParentBody = getParentBody(cachedQues);
|
|
|
- String strBody = getBody(subQues.getSubNumber(), subQues.getQuestionId(), cachedQues, subjectiveQuestions);
|
|
|
+ QuestionCacheBean baseQuestion = CacheHelper.getQuestion(examId, subjectCode, subQues.getPaperType(), subQues.getQuestionId());
|
|
|
+ String strAnswer = getCorrectAnswer(subQues.getSubNumber(), subQues.getQuestionId(), baseQuestion, subjectiveQuestions, QuestionCategory.SUBJECTIVE);
|
|
|
+ String strParentBody = getParentBody(baseQuestion);
|
|
|
+ String strBody = getBody(subQues.getSubNumber(), subQues.getQuestionId(), baseQuestion, subjectiveQuestions);
|
|
|
|
|
|
//注意:ComplexTextHandler类中有公共字段,需要多例,不能搞成单例,否则会出问题
|
|
|
RichTextHandler answerComplexRichTextHandler = RichTextHandlerFactory.getHandler("complex");
|
|
@@ -289,7 +289,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
@PostMapping("/getQuestionAnswer")
|
|
|
@Override
|
|
|
public OuterGetQuestionAnswerResp getQuestionAnswer(@RequestBody OuterGetQuestionAnswerReq req) {
|
|
|
- if (StringUtils.isNullOrEmpty(req.getQuestionId())) {
|
|
|
+ if (StringUtils.isEmpty(req.getQuestionId())) {
|
|
|
throw new StatusException("102001", "题目id不允许为空");
|
|
|
}
|
|
|
|
|
@@ -315,11 +315,11 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
throw new StatusException("103002", "课程代码不允许为空");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isNullOrEmpty(req.getPaperType())) {
|
|
|
+ if (StringUtils.isEmpty(req.getPaperType())) {
|
|
|
throw new StatusException("103003", "试卷类型不允许为空");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isNullOrEmpty(req.getBasePaperId())) {
|
|
|
+ if (StringUtils.isEmpty(req.getBasePaperId())) {
|
|
|
throw new StatusException("103004", "原始试卷id不允许为空");
|
|
|
}
|
|
|
|
|
@@ -442,12 +442,12 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
|
|
|
//图片作答特殊处理:将图片作答中的文字部分和图片部分拆开
|
|
|
if (BlockType.image.name().equals(transformedAnswerType)) {
|
|
|
- if (!StringUtils.isNullOrEmpty(stuAnswer)) {
|
|
|
+ if (!StringUtils.isEmpty(stuAnswer)) {
|
|
|
//图片作答的标识
|
|
|
String firstMatch = RegExpUtil.find(stuAnswer, "<div \\S*photo-answers-block\\S*>");
|
|
|
|
|
|
int index;
|
|
|
- if (StringUtils.isNullOrEmpty(firstMatch)) {
|
|
|
+ if (StringUtils.isEmpty(firstMatch)) {
|
|
|
index = -1;
|
|
|
} else {
|
|
|
index = stuAnswer.indexOf(firstMatch);
|
|
@@ -586,7 +586,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
DefaultQuestionStructure questionStructure = cachedQues.getDefaultQuestion().getMasterVersion();
|
|
|
|
|
|
//body为空,则说明当前小题为非套题(即questionUnitList集合大小为1),可直接返回小题题干
|
|
|
- if (StringUtils.isNullOrEmpty(questionStructure.getBody())) {
|
|
|
+ if (StringUtils.isEmpty(questionStructure.getBody())) {
|
|
|
return questionStructure.getQuestionUnitList().get(0).getBody();
|
|
|
}
|
|
|
|
|
@@ -614,31 +614,51 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
*
|
|
|
* @param curSubNumber 当前小题号
|
|
|
* @param questionId 原小题id
|
|
|
- * @param cachedQues 带题干的试题结构
|
|
|
- * @param allEqList 所有作答集合
|
|
|
+ * @param baseQuestion 带题干的试题结构
|
|
|
+ * @param questions 所有作答集合
|
|
|
* @return
|
|
|
*/
|
|
|
- private String getCorrectAnswer(Integer curSubNumber, String questionId,
|
|
|
- QuestionCacheBean cachedQues, List<OuterQuestionBean> allEqList) {
|
|
|
- QuestionAnswerCacheBean questionAnswerCache = CacheHelper.getQuestionAnswer(questionId);
|
|
|
- List<String> rightAnswerList = questionAnswerCache.getRightAnswers();
|
|
|
- DefaultQuestionStructure questionStructure = cachedQues.getDefaultQuestion().getMasterVersion();
|
|
|
-
|
|
|
+ private String getCorrectAnswer(Integer curSubNumber, String questionId, QuestionCacheBean baseQuestion,
|
|
|
+ List<OuterQuestionBean> questions, QuestionCategory questionCategory) {
|
|
|
+ // QuestionAnswerCacheBean questionAnswerCache = CacheHelper.getQuestionAnswer(questionId);
|
|
|
+ // List<String> rightAnswerList = questionAnswerCache.getRightAnswers();
|
|
|
+
|
|
|
+ List<String> allRightAnswers = new ArrayList<>();
|
|
|
+ List<String> objectiveRightAnswers = new ArrayList<>();
|
|
|
+ List<String> subjectiveRightAnswers = new ArrayList<>();
|
|
|
+
|
|
|
+ // 套题下多个子题同时存在有“客观题”和“主观题”情况,取答案时注意过滤
|
|
|
+ DefaultQuestionStructure questionStructure = baseQuestion.getDefaultQuestion().getMasterVersion();
|
|
|
+ for (DefaultQuestionUnit unit : questionStructure.getQuestionUnitList()) {
|
|
|
+ if (QuestionType.SINGLE_CHOICE == unit.getQuestionType() ||
|
|
|
+ QuestionType.MULTIPLE_CHOICE == unit.getQuestionType() ||
|
|
|
+ QuestionType.TRUE_OR_FALSE == unit.getQuestionType()) {
|
|
|
+ objectiveRightAnswers.add(StringUtils.join(unit.getRightAnswer(), ""));
|
|
|
+ } else {
|
|
|
+ subjectiveRightAnswers.add(StringUtils.join(unit.getRightAnswer(), ""));
|
|
|
+ }
|
|
|
+ allRightAnswers.add(StringUtils.join(unit.getRightAnswer(), ""));
|
|
|
+ }
|
|
|
|
|
|
//body为空,则说明当前小题为非套题(rightAnswerList集合大小为1),可直接返回
|
|
|
- if (StringUtils.isNullOrEmpty(questionStructure.getBody())) {
|
|
|
- return rightAnswerList.get(0);
|
|
|
+ if (StringUtils.isEmpty(questionStructure.getBody())) {
|
|
|
+ return allRightAnswers.get(0);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //同一questionId的主观题集合(不带题干,有小题号)
|
|
|
- List<OuterQuestionBean> noBodySubjectiveQuesList = allEqList.stream().
|
|
|
+ //同一questionId的套题集合(不带题干,有小题号)
|
|
|
+ List<OuterQuestionBean> collectQuestions = questions.stream().
|
|
|
filter(p -> p.getQuestionId().equals(questionId)).collect(Collectors.toList());
|
|
|
|
|
|
- for (int i = 0; i < noBodySubjectiveQuesList.size(); i++) {
|
|
|
+ for (int i = 0; i < collectQuestions.size(); i++) {
|
|
|
//如果小题号相同,则根据相同索引从带题干的集合中取出对应的小题答案
|
|
|
- if (noBodySubjectiveQuesList.get(i).getSubNumber().intValue() == curSubNumber.intValue()) {
|
|
|
- return rightAnswerList.get(i);
|
|
|
+ if (collectQuestions.get(i).getSubNumber().intValue() == curSubNumber.intValue()) {
|
|
|
+ if (QuestionCategory.SUBJECTIVE == questionCategory) {
|
|
|
+ return allRightAnswers.get(i);
|
|
|
+ } else if (QuestionCategory.OBJECTIVE == questionCategory) {
|
|
|
+ return allRightAnswers.get(i);
|
|
|
+ } else {
|
|
|
+ return allRightAnswers.get(i);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|