|
@@ -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.support.helper.ExamCacheTransferHelper;
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
-import com.mysql.cj.util.StringUtils;
|
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiResponse;
|
|
import io.swagger.annotations.ApiResponse;
|
|
import io.swagger.annotations.ApiResponses;
|
|
import io.swagger.annotations.ApiResponses;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -145,7 +145,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
}
|
|
}
|
|
|
|
|
|
String subjectCode = req.getSubjectCode();
|
|
String subjectCode = req.getSubjectCode();
|
|
- if (StringUtils.isNullOrEmpty(subjectCode)) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(subjectCode)) {
|
|
throw new StatusException("101002", "科目代码不允许为空");
|
|
throw new StatusException("101002", "科目代码不允许为空");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -211,7 +211,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
}
|
|
}
|
|
|
|
|
|
String subjectCode = req.getSubjectCode();
|
|
String subjectCode = req.getSubjectCode();
|
|
- if (StringUtils.isNullOrEmpty(subjectCode)) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(subjectCode)) {
|
|
throw new StatusException("105002", "科目代码不允许为空");
|
|
throw new StatusException("105002", "科目代码不允许为空");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -230,23 +230,20 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
throw new StatusException("105004", "当前科目无主观题");
|
|
throw new StatusException("105004", "当前科目无主观题");
|
|
}
|
|
}
|
|
|
|
|
|
- OuterSubjectivePaperBean osb=new OuterSubjectivePaperBean();
|
|
|
|
|
|
+ OuterSubjectivePaperBean osb = new OuterSubjectivePaperBean();
|
|
osb.setExamId(examId);
|
|
osb.setExamId(examId);
|
|
osb.setSubjectCode(subjectCode);
|
|
osb.setSubjectCode(subjectCode);
|
|
osb.setSubjectName(course.getName());
|
|
osb.setSubjectName(course.getName());
|
|
|
|
|
|
- List<OuterSubjectivePaperQuestionBean> subPaperQuesList=new ArrayList<>();
|
|
|
|
- //所有试题信息
|
|
|
|
- List<OuterQuestionBean> allQuestions = outletPaperStructService.getPaperStructQuestions(
|
|
|
|
- req.getExamId(), course.getCode(), QuestionCategory.SUBJECTIVE);
|
|
|
|
-
|
|
|
|
|
|
+ List<OuterSubjectivePaperQuestionBean> subPaperQuesList = new ArrayList<>();
|
|
for (OuterQuestionBean subQues : subjectiveQuestions) {
|
|
for (OuterQuestionBean subQues : subjectiveQuestions) {
|
|
- OuterSubjectivePaperQuestionBean subPaperQues=new OuterSubjectivePaperQuestionBean();
|
|
|
|
|
|
+ OuterSubjectivePaperQuestionBean subPaperQues = new OuterSubjectivePaperQuestionBean();
|
|
|
|
+
|
|
//获取指定小题的题干相关信息
|
|
//获取指定小题的题干相关信息
|
|
- QuestionCacheBean cachedQues = CacheHelper.getQuestion(examId, subjectCode, subQues.getPaperType(), subQues.getQuestionId());
|
|
|
|
- String strAnswer=getCorrectAnswer(subQues.getSubNumber(), subQues.getQuestionId(), cachedQues, allQuestions);
|
|
|
|
- String strParentBody=getParentBody(cachedQues);
|
|
|
|
- String strBody=getBody(subQues.getSubNumber(), subQues.getQuestionId(), cachedQues, allQuestions);
|
|
|
|
|
|
+ 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类中有公共字段,需要多例,不能搞成单例,否则会出问题
|
|
//注意:ComplexTextHandler类中有公共字段,需要多例,不能搞成单例,否则会出问题
|
|
RichTextHandler answerComplexRichTextHandler = RichTextHandlerFactory.getHandler("complex");
|
|
RichTextHandler answerComplexRichTextHandler = RichTextHandlerFactory.getHandler("complex");
|
|
@@ -260,10 +257,11 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
subPaperQues.setMainNumber(subQues.getMainNumber());
|
|
subPaperQues.setMainNumber(subQues.getMainNumber());
|
|
subPaperQues.setSubNumber(subQues.getSubNumber());
|
|
subPaperQues.setSubNumber(subQues.getSubNumber());
|
|
subPaperQues.setQuestionId(subQues.getQuestionId());
|
|
subPaperQues.setQuestionId(subQues.getQuestionId());
|
|
|
|
+
|
|
subPaperQuesList.add(subPaperQues);
|
|
subPaperQuesList.add(subPaperQues);
|
|
}
|
|
}
|
|
- osb.setQuestions(subPaperQuesList);
|
|
|
|
|
|
|
|
|
|
+ osb.setQuestions(subPaperQuesList);
|
|
resp.setSubjectivePaper(osb);
|
|
resp.setSubjectivePaper(osb);
|
|
|
|
|
|
return resp;
|
|
return resp;
|
|
@@ -291,7 +289,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
@PostMapping("/getQuestionAnswer")
|
|
@PostMapping("/getQuestionAnswer")
|
|
@Override
|
|
@Override
|
|
public OuterGetQuestionAnswerResp getQuestionAnswer(@RequestBody OuterGetQuestionAnswerReq req) {
|
|
public OuterGetQuestionAnswerResp getQuestionAnswer(@RequestBody OuterGetQuestionAnswerReq req) {
|
|
- if (StringUtils.isNullOrEmpty(req.getQuestionId())) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(req.getQuestionId())) {
|
|
throw new StatusException("102001", "题目id不允许为空");
|
|
throw new StatusException("102001", "题目id不允许为空");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -317,11 +315,11 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
throw new StatusException("103002", "课程代码不允许为空");
|
|
throw new StatusException("103002", "课程代码不允许为空");
|
|
}
|
|
}
|
|
|
|
|
|
- if (StringUtils.isNullOrEmpty(req.getPaperType())) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(req.getPaperType())) {
|
|
throw new StatusException("103003", "试卷类型不允许为空");
|
|
throw new StatusException("103003", "试卷类型不允许为空");
|
|
}
|
|
}
|
|
|
|
|
|
- if (StringUtils.isNullOrEmpty(req.getBasePaperId())) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(req.getBasePaperId())) {
|
|
throw new StatusException("103004", "原始试卷id不允许为空");
|
|
throw new StatusException("103004", "原始试卷id不允许为空");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -444,12 +442,12 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
|
|
|
//图片作答特殊处理:将图片作答中的文字部分和图片部分拆开
|
|
//图片作答特殊处理:将图片作答中的文字部分和图片部分拆开
|
|
if (BlockType.image.name().equals(transformedAnswerType)) {
|
|
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*>");
|
|
String firstMatch = RegExpUtil.find(stuAnswer, "<div \\S*photo-answers-block\\S*>");
|
|
|
|
|
|
int index;
|
|
int index;
|
|
- if (StringUtils.isNullOrEmpty(firstMatch)) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(firstMatch)) {
|
|
index = -1;
|
|
index = -1;
|
|
} else {
|
|
} else {
|
|
index = stuAnswer.indexOf(firstMatch);
|
|
index = stuAnswer.indexOf(firstMatch);
|
|
@@ -588,7 +586,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
DefaultQuestionStructure questionStructure = cachedQues.getDefaultQuestion().getMasterVersion();
|
|
DefaultQuestionStructure questionStructure = cachedQues.getDefaultQuestion().getMasterVersion();
|
|
|
|
|
|
//body为空,则说明当前小题为非套题(即questionUnitList集合大小为1),可直接返回小题题干
|
|
//body为空,则说明当前小题为非套题(即questionUnitList集合大小为1),可直接返回小题题干
|
|
- if (StringUtils.isNullOrEmpty(questionStructure.getBody())) {
|
|
|
|
|
|
+ if (StringUtils.isEmpty(questionStructure.getBody())) {
|
|
return questionStructure.getQuestionUnitList().get(0).getBody();
|
|
return questionStructure.getQuestionUnitList().get(0).getBody();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -614,49 +612,57 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
/**
|
|
/**
|
|
* 获取当前小题的标准答案
|
|
* 获取当前小题的标准答案
|
|
*
|
|
*
|
|
- * @param curSubNumber 当前小题号
|
|
|
|
- * @param questionId 原小题id
|
|
|
|
- * @param cachedQues 带题干的试卷结构
|
|
|
|
- * @param allEqList 所有作答集合
|
|
|
|
|
|
+ * @param curSubNumber 当前小题号
|
|
|
|
+ * @param questionId 原小题id
|
|
|
|
+ * @param baseQuestion 带题干的试题结构
|
|
|
|
+ * @param questions 所有作答集合
|
|
* @return
|
|
* @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),可直接返回
|
|
//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());
|
|
filter(p -> p.getQuestionId().equals(questionId)).collect(Collectors.toList());
|
|
|
|
|
|
- for (int i = 0; i < noBodySubjectiveQuesList.size(); i++) {
|
|
|
|
- //如果小题号相同,则根据相同索引从带题干的集合中取出对应的小题题干
|
|
|
|
- if (noBodySubjectiveQuesList.get(i).getSubNumber().intValue() == curSubNumber.intValue()) {
|
|
|
|
- return rightAnswerList.get(i);
|
|
|
|
|
|
+ for (int i = 0; i < collectQuestions.size(); i++) {
|
|
|
|
+ //如果小题号相同,则根据相同索引从带题干的集合中取出对应的小题答案
|
|
|
|
+ if (collectQuestions.get(i).getSubNumber().intValue() == curSubNumber.intValue()) {
|
|
|
|
+ if (QuestionCategory.SUBJECTIVE == questionCategory) {
|
|
|
|
+ return subjectiveRightAnswers.get(i);
|
|
|
|
+ } else if (QuestionCategory.OBJECTIVE == questionCategory) {
|
|
|
|
+ return objectiveRightAnswers.get(i);
|
|
|
|
+ } else {
|
|
|
|
+ return allRightAnswers.get(i);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- String str1 ="111";
|
|
|
|
- String str2 ="222";
|
|
|
|
- String str3 ="111111";
|
|
|
|
- String str4 ="222222";
|
|
|
|
- String str5 ="222222dfsdffsd234234234234rwefsfsdfsdfaasfdsadfasdfsad";
|
|
|
|
- String str6 ="222222dfsdffsd234234234239rwefsfsdfsdfaasfdsadfasdfsad";
|
|
|
|
- System.out.println("1001110101011100111001101110101110100100001000000111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".length());
|
|
|
|
- System.out.println("9D5CE6EBA420717BE7E7D308B11F8207681B066C951D68F3994D19828F342474".length());
|
|
|
|
- System.out.println(String.format("str1=%s,str2=%s,str3=%s,str4=%s,str5=%s,str6=%s",
|
|
|
|
- str1.hashCode(),str2.hashCode(),str3.hashCode(),str4.hashCode(),str5.hashCode(),str6.hashCode()));
|
|
|
|
- }
|
|
|
|
}
|
|
}
|