|
@@ -67,30 +67,22 @@ import static java.util.stream.Collectors.toList;
|
|
|
@Service
|
|
|
public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IExamService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public RedisUtil redisUtil;
|
|
|
@Autowired
|
|
|
private ExamMapper examMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IPaperService paperService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IUserExamService userExamService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IPaperQuestionService paperQuestionService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IUserExamQuestionService userExamQuestionService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IQuestionService questionService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IUserExamResultService userExamResultService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public RedisUtil redisUtil;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IQuartzJobService quartzJobService;
|
|
|
|
|
@@ -210,9 +202,9 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
|
|
|
//保存考试关联的试题列表
|
|
|
if (!CollectionUtils.isEmpty(paperQuestionList)) {
|
|
|
- this.savePaperQuestion(userExam.getId(), paperQuestionList);
|
|
|
+ this.savePaperQuestion(paper.getId(), userExam.getId(), paperQuestionList);
|
|
|
//保存用户考试的题目答案
|
|
|
- this.saveQuestionAnswer(userExam.getId(), exam, paperQuestionList);
|
|
|
+ this.saveQuestionAnswer(paper.getId(), userExam.getId(), exam, paperQuestionList);
|
|
|
}
|
|
|
|
|
|
// 截止时间
|
|
@@ -235,42 +227,53 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* @param userExamId
|
|
|
* @param paperQuestionList
|
|
|
*/
|
|
|
- public void saveQuestionAnswer(String userExamId, Exam exam, List<PaperQuestion> paperQuestionList) {
|
|
|
- //获取题目和答案
|
|
|
- List<Question> questionList = listQuestion(paperQuestionList);
|
|
|
+ public void saveQuestionAnswer(String paperId, String userExamId, Exam exam, List<PaperQuestion> paperQuestionList) {
|
|
|
+ //组装试卷试题,子题目,答案
|
|
|
+ List<Question> questionList = paperService.assemblePaperQuestion(paperId, paperQuestionList, null, null);
|
|
|
if (!CollectionUtils.isEmpty(questionList)) {
|
|
|
List<UserExamQuestionAnswer> userExamQuestionAnswerList = new ArrayList<>();
|
|
|
- questionList.stream().forEach(question -> {
|
|
|
- List<QuestionAnswer> answerList = question.getAnswerList();
|
|
|
- if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
- //答案乱序(支持单选题,多选题)
|
|
|
- if (!Objects.isNull(exam.getAnswerDisorder()) && exam.getAnswerDisorder() && (QuestionType.RADIO.getCode().equals(question.getType()) || QuestionType.MULTI.getCode().equals(question.getType()))) {
|
|
|
- //答案洗牌
|
|
|
- Collections.shuffle(answerList);
|
|
|
- }
|
|
|
- int sort = 1;
|
|
|
- for (QuestionAnswer questionAnswer : answerList) {
|
|
|
- UserExamQuestionAnswer userExamQuestionAnswer = new UserExamQuestionAnswer();
|
|
|
- userExamQuestionAnswer.setUserExamId(userExamId);
|
|
|
- userExamQuestionAnswer.setQuestionId(question.getId());
|
|
|
- userExamQuestionAnswer.setAnswerId(questionAnswer.getId());
|
|
|
- userExamQuestionAnswer.setIsRight(questionAnswer.getIsRight());
|
|
|
- userExamQuestionAnswer.setSort(sort);
|
|
|
- //填空题不再生成tag
|
|
|
- if (QuestionType.BLANK.getCode().equals(question.getType())) {
|
|
|
- userExamQuestionAnswer.setTag(questionAnswer.getTag());
|
|
|
- } else {
|
|
|
- userExamQuestionAnswer.setTag(CharUtil.getZm(sort - 1));
|
|
|
- }
|
|
|
- userExamQuestionAnswerList.add(userExamQuestionAnswer);
|
|
|
- sort++;
|
|
|
+ questionList.forEach(question -> {
|
|
|
+ if (QuestionType.COMBINATION.getCode().equals(question.getType())) {//组合题
|
|
|
+ List<Question> subQuestionList = question.getSubQuestionList();
|
|
|
+ if (!CollectionUtils.isEmpty(subQuestionList)) {
|
|
|
+ subQuestionList.forEach(subQuestion -> genQuestionAnswer(userExamId, exam, subQuestion, userExamQuestionAnswerList));
|
|
|
}
|
|
|
+ } else {
|
|
|
+ genQuestionAnswer(userExamId, exam, question, userExamQuestionAnswerList);
|
|
|
}
|
|
|
});
|
|
|
userExamQuestionAnswerService.saveBatch(userExamQuestionAnswerList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void genQuestionAnswer(String userExamId, Exam exam, Question question, List<UserExamQuestionAnswer> userExamQuestionAnswerList) {
|
|
|
+ List<QuestionAnswer> answerList = question.getAnswerList();
|
|
|
+ if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
+ //答案乱序(支持单选题,多选题)
|
|
|
+ if (!Objects.isNull(exam.getAnswerDisorder()) && exam.getAnswerDisorder() && (QuestionType.RADIO.getCode().equals(question.getType()) || QuestionType.MULTI.getCode().equals(question.getType()))) {
|
|
|
+ //答案洗牌
|
|
|
+ Collections.shuffle(answerList);
|
|
|
+ }
|
|
|
+ int sort = 1;
|
|
|
+ for (QuestionAnswer questionAnswer : answerList) {
|
|
|
+ UserExamQuestionAnswer userExamQuestionAnswer = new UserExamQuestionAnswer();
|
|
|
+ userExamQuestionAnswer.setUserExamId(userExamId);
|
|
|
+ userExamQuestionAnswer.setQuestionId(question.getId());
|
|
|
+ userExamQuestionAnswer.setAnswerId(questionAnswer.getId());
|
|
|
+ userExamQuestionAnswer.setIsRight(questionAnswer.getIsRight());
|
|
|
+ userExamQuestionAnswer.setSort(sort);
|
|
|
+ //填空题不再生成tag
|
|
|
+ if (QuestionType.BLANK.getCode().equals(question.getType())) {
|
|
|
+ userExamQuestionAnswer.setTag(questionAnswer.getTag());
|
|
|
+ } else {
|
|
|
+ userExamQuestionAnswer.setTag(CharUtil.getZm(sort - 1));
|
|
|
+ }
|
|
|
+ userExamQuestionAnswerList.add(userExamQuestionAnswer);
|
|
|
+ sort++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 创建定时任务
|
|
@@ -306,35 +309,97 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
/**
|
|
|
* 保存试卷试题列表
|
|
|
*/
|
|
|
- private void savePaperQuestion(String userExamId, List<PaperQuestion> paperQuestionList) {
|
|
|
- paperQuestionList = paperQuestionList.stream().sorted(Comparator.comparing(PaperQuestion::getQuestionType).thenComparing(PaperQuestion::getSort)).collect(Collectors.toList());
|
|
|
+ private void savePaperQuestion(String paperId, String userExamId, List<PaperQuestion> paperQuestionList) {
|
|
|
+ paperQuestionList = paperQuestionList.stream().sorted(Comparator.comparing(PaperQuestion::getQuestionType)
|
|
|
+ .thenComparing(PaperQuestion::getSort)).collect(Collectors.toList());
|
|
|
//获取规则组map
|
|
|
Map<String, PaperRuleGroup> groupMap = getGroupMap(paperQuestionList);
|
|
|
|
|
|
List<UserExamQuestion> userExamQuestionList = new ArrayList<>();
|
|
|
int index = 1;
|
|
|
for (PaperQuestion item : paperQuestionList) {
|
|
|
- UserExamQuestion userExamQuestion = new UserExamQuestion();
|
|
|
- BeanUtils.copyProperties(item, userExamQuestion);
|
|
|
-
|
|
|
- if (!Objects.isNull(groupMap)) {
|
|
|
- PaperRuleGroup ruleGroup = groupMap.get(item.getGroupId());
|
|
|
- if (!Objects.isNull(ruleGroup)) {
|
|
|
- //设置题目是否允许漏选
|
|
|
- userExamQuestion.setCanMissOption(ruleGroup.getCanMissOption());
|
|
|
- //设置题目是否按空给分
|
|
|
- userExamQuestion.setCanBlankOption(ruleGroup.getCanBlankOption());
|
|
|
- }
|
|
|
- }
|
|
|
- userExamQuestion.setId(null);
|
|
|
- userExamQuestion.setQuestionIndex(index);
|
|
|
- userExamQuestion.setUserExamId(userExamId);
|
|
|
- userExamQuestionList.add(userExamQuestion);
|
|
|
+ //配置用户考试试题
|
|
|
+ configUserExamQuestion(userExamId, item, index, groupMap, userExamQuestionList);
|
|
|
index++;
|
|
|
}
|
|
|
+
|
|
|
+ //组合题
|
|
|
+ List<String> combinationIdList = paperQuestionList.stream().filter(r -> QuestionType.COMBINATION.getCode().equals(r.getQuestionType()))
|
|
|
+ .map(PaperQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ List<PaperQuestion> paperSubQuestionList = paperQuestionService.listPaperSubQuestionByIds(paperId, combinationIdList);
|
|
|
+ //配置子题目
|
|
|
+ configUserExamSubQuestion(userExamId, paperSubQuestionList, groupMap, userExamQuestionList);
|
|
|
+
|
|
|
userExamQuestionService.saveBatch(userExamQuestionList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 配置用户考试试题
|
|
|
+ *
|
|
|
+ * @param userExamId
|
|
|
+ * @param item
|
|
|
+ * @param index
|
|
|
+ * @param groupMap
|
|
|
+ * @param userExamQuestionList
|
|
|
+ */
|
|
|
+ public void configUserExamQuestion(String userExamId, PaperQuestion item, int index,
|
|
|
+ Map<String, PaperRuleGroup> groupMap, List<UserExamQuestion> userExamQuestionList) {
|
|
|
+ UserExamQuestion userExamQuestion = new UserExamQuestion();
|
|
|
+ BeanUtils.copyProperties(item, userExamQuestion);
|
|
|
+
|
|
|
+ //根据规则组设置题目
|
|
|
+ setQuestionByGroup(item, userExamQuestion, groupMap);
|
|
|
+
|
|
|
+ userExamQuestion.setId(null);
|
|
|
+ userExamQuestion.setQuestionIndex(index);
|
|
|
+ userExamQuestion.setUserExamId(userExamId);
|
|
|
+ userExamQuestionList.add(userExamQuestion);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据规则组设置题目
|
|
|
+ *
|
|
|
+ * @param item
|
|
|
+ * @param userExamQuestion
|
|
|
+ * @param groupMap
|
|
|
+ */
|
|
|
+ public void setQuestionByGroup(PaperQuestion item, UserExamQuestion userExamQuestion, Map<String, PaperRuleGroup> groupMap) {
|
|
|
+ if (!Objects.isNull(groupMap)) {
|
|
|
+ PaperRuleGroup ruleGroup = groupMap.get(item.getGroupId());
|
|
|
+ if (!Objects.isNull(ruleGroup)) {
|
|
|
+ //设置题目是否允许漏选
|
|
|
+ userExamQuestion.setCanMissOption(ruleGroup.getCanMissOption());
|
|
|
+ //设置题目是否按空给分
|
|
|
+ userExamQuestion.setCanBlankOption(ruleGroup.getCanBlankOption());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 配置用户考试试题子题目
|
|
|
+ *
|
|
|
+ * @param userExamId
|
|
|
+ * @param groupMap
|
|
|
+ * @param userExamQuestionList
|
|
|
+ */
|
|
|
+ public void configUserExamSubQuestion(String userExamId, List<PaperQuestion> paperSubQuestionList,
|
|
|
+ Map<String, PaperRuleGroup> groupMap, List<UserExamQuestion> userExamQuestionList) {
|
|
|
+ if (!CollectionUtils.isEmpty(paperSubQuestionList)) {
|
|
|
+ paperSubQuestionList.forEach(subQuestion -> {
|
|
|
+ UserExamQuestion userExamQuestion = new UserExamQuestion();
|
|
|
+ BeanUtils.copyProperties(subQuestion, userExamQuestion);
|
|
|
+ //根据规则组设置题目
|
|
|
+ setQuestionByGroup(subQuestion, userExamQuestion, groupMap);
|
|
|
+ userExamQuestion.setId(null);
|
|
|
+ userExamQuestion.setChild(true);
|
|
|
+ userExamQuestion.setParentQuestionId(subQuestion.getParentQuestionId());
|
|
|
+ userExamQuestion.setQuestionIndex(subQuestion.getSort());
|
|
|
+ userExamQuestion.setUserExamId(userExamId);
|
|
|
+ userExamQuestionList.add(userExamQuestion);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 在线考试试卷详情,包括答题卡,试题(不包含正确答案和解析)
|
|
@@ -357,14 +422,21 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
List<UserExamQuestion> userExamQuestionList = dto.getUserExamQuestionList();
|
|
|
List<Map<String, AnswerCardDTO>> answerCardList = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(userExamQuestionList)) {
|
|
|
- //获取题目和答案
|
|
|
- Map<String, Question> questionMap = getUserExamQuestionMap(userExamId, userExamQuestionList, needAnswerFlag, needAnalysis, false, true, needClearBlankContent);
|
|
|
-
|
|
|
- //设置题目
|
|
|
- setUserExamQuestion(questionMap, userExamQuestionList, needRenderBlank);
|
|
|
+ List<UserExamQuestion> rootQuestionList = userExamQuestionList.stream().filter(r -> !Objects.isNull(r.getChild()) && !r.getChild())
|
|
|
+ .sorted(Comparator.comparing(UserExamQuestion::getQuestionIndex)).collect(Collectors.toList());
|
|
|
+ List<UserExamQuestion> childQuestionList = userExamQuestionList.stream().filter(r -> !Objects.isNull(r.getChild()) && r.getChild())
|
|
|
+ .sorted(Comparator.comparing(UserExamQuestion::getQuestionIndex)).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(rootQuestionList)) {
|
|
|
+ //获取题目和答案
|
|
|
+ getUserExamQuestionMap(userExamId, rootQuestionList, childQuestionList, needAnswerFlag, needAnalysis, false, true, needClearBlankContent);
|
|
|
+
|
|
|
+ //设置题目
|
|
|
+ setUserExamQuestion(rootQuestionList, needRenderBlank);
|
|
|
+
|
|
|
+ //设置答题卡
|
|
|
+ setAnswerCard(rootQuestionList, answerCardList);
|
|
|
+ }
|
|
|
|
|
|
- //设置答题卡
|
|
|
- setAnswerCard(userExamQuestionList, answerCardList);
|
|
|
}
|
|
|
dto.setAnswerCardList(answerCardList);
|
|
|
return dto;
|
|
@@ -427,21 +499,36 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
/**
|
|
|
* 设置题目
|
|
|
*
|
|
|
- * @param questionMap
|
|
|
* @param userExamQuestionList
|
|
|
*/
|
|
|
- public void setUserExamQuestion(Map<String, Question> questionMap, List<UserExamQuestion> userExamQuestionList, boolean needRenderBlank) {
|
|
|
+ public void setUserExamQuestion(List<UserExamQuestion> userExamQuestionList, boolean needRenderBlank) {
|
|
|
//与问题关联
|
|
|
for (UserExamQuestion userExamQuestion : userExamQuestionList) {
|
|
|
- if (!Objects.isNull(questionMap) && !Objects.isNull(questionMap.get(userExamQuestion.getQuestionId()))) {
|
|
|
- Question question = questionMap.get(userExamQuestion.getQuestionId());
|
|
|
- //渲染填空题的题干,填充进答案
|
|
|
- if (needRenderBlank && QuestionType.BLANK.getCode().equals(userExamQuestion.getQuestionType())) {
|
|
|
- renderBlank(question, userExamQuestion.getAnswer());
|
|
|
- }
|
|
|
- userExamQuestion.setQuestion(question);
|
|
|
- userExamQuestion.setQuestionTypeName(QuestionType.getByCode(userExamQuestion.getQuestionType()).getValue());
|
|
|
+ Question question = userExamQuestion.getQuestion();
|
|
|
+ //渲染填空题的题干,填充进答案
|
|
|
+ if (QuestionType.COMBINATION.getCode().equals(question.getType())) {//组合题
|
|
|
+ userExamQuestion.getSubQuestionList().forEach(subQuestion -> {
|
|
|
+ rendBlank(needRenderBlank, userExamQuestion, subQuestion.getQuestion());
|
|
|
+ subQuestion.setQuestionTypeName(QuestionType.getByCode(subQuestion.getQuestionType()).getValue());
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ rendBlank(needRenderBlank, userExamQuestion, question);
|
|
|
}
|
|
|
+ userExamQuestion.setQuestion(question);
|
|
|
+ userExamQuestion.setQuestionTypeName(QuestionType.getByCode(userExamQuestion.getQuestionType()).getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 渲染填空题
|
|
|
+ *
|
|
|
+ * @param needRenderBlank
|
|
|
+ * @param userExamQuestion
|
|
|
+ * @param question
|
|
|
+ */
|
|
|
+ public void rendBlank(boolean needRenderBlank, UserExamQuestion userExamQuestion, Question question) {
|
|
|
+ if (needRenderBlank && QuestionType.BLANK.getCode().equals(userExamQuestion.getQuestionType())) {
|
|
|
+ renderBlank(question, userExamQuestion.getAnswer());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -520,10 +607,10 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
Map<Integer, UserExamQuestion> userExamQuestionMap = userExamQuestionList.stream().collect(Collectors.toMap(UserExamQuestion::getQuestionIndex, a -> a, (k1, k2) -> k1));
|
|
|
|
|
|
//获取题目和答案
|
|
|
- Map<String, Question> questionMap = getUserExamQuestionMap(dto.getUserExamId(), userExamQuestionList, true, false, true, false, false);
|
|
|
+ getUserExamQuestionMap(dto.getUserExamId(), userExamQuestionList, null, true, false, true, false, false);
|
|
|
|
|
|
//计算客观题得分
|
|
|
- int score = calcObjectiveScore(examAnswers, userExamQuestionMap, questionMap, userExamQuestionList);
|
|
|
+ int score = calcObjectiveScore(examAnswers, userExamQuestionMap, null, userExamQuestionList);
|
|
|
//更新用户考试信息和成绩
|
|
|
updateUserExamAndResult(score, userExam);
|
|
|
}
|
|
@@ -552,28 +639,104 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
}
|
|
|
|
|
|
//获取题目和答案
|
|
|
- public Map<String, Question> getUserExamQuestionMap(String userExamId, List<UserExamQuestion> userExamQuestionList, boolean needAnswerFlag, boolean needAnalysis, boolean needPathScore, boolean needSubjective, boolean needClearBlankContent) {
|
|
|
- List<String> subjectiveList = null;
|
|
|
+ public void getUserExamQuestionMap(String userExamId, List<UserExamQuestion> rootExamQuestionList,
|
|
|
+ List<UserExamQuestion> childQuestionList, boolean needAnswerFlag,
|
|
|
+ boolean needAnalysis, boolean needPathScore, boolean needSubjective,
|
|
|
+ boolean needClearBlankContent) {
|
|
|
+ List<String> subjectiveList = new ArrayList<>();
|
|
|
if (needSubjective) {//是否需要主观题
|
|
|
- subjectiveList = userExamQuestionList.stream().filter(o -> o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ List<String> rootSubjectList = getSubjectList(rootExamQuestionList);
|
|
|
+ List<String> childSubjectList = getSubjectList(childQuestionList);
|
|
|
+ if (!CollectionUtils.isEmpty(rootSubjectList)) {
|
|
|
+ subjectiveList.addAll(rootSubjectList);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(childSubjectList)) {
|
|
|
+ subjectiveList.addAll(childSubjectList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//客观题
|
|
|
- List<String> objectiveList = userExamQuestionList.stream().filter(o -> !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
- List<Question> questionList = questionService.listUserExamQuestionAnswer(userExamId, objectiveList, subjectiveList, needAnswerFlag, needAnalysis, needPathScore, needSubjective);
|
|
|
- //题目答案重新排序
|
|
|
+ List<String> objectiveList = new ArrayList<>();
|
|
|
+ List<String> rootObjectiveList = getObjectiveList(rootExamQuestionList);
|
|
|
+ List<String> childObjectiveList = getObjectiveList(childQuestionList);
|
|
|
+ if (!CollectionUtils.isEmpty(rootObjectiveList)) {
|
|
|
+ objectiveList.addAll(rootObjectiveList);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(childObjectiveList)) {
|
|
|
+ objectiveList.addAll(childObjectiveList);
|
|
|
+ }
|
|
|
+ List<Question> resultList = new ArrayList<>();
|
|
|
+ List<Question> questionList = questionService.listUserExamQuestionAnswer(userExamId, objectiveList,
|
|
|
+ subjectiveList, needAnswerFlag, needAnalysis, needPathScore, needSubjective);
|
|
|
+
|
|
|
+ List<String> combinationIdList = rootExamQuestionList.stream().filter(o -> o.getQuestionType()
|
|
|
+ .equals(QuestionType.COMBINATION.getCode())).map(UserExamQuestion::getQuestionId).collect(toList());
|
|
|
+ List<Question> combinationQuestionList = questionService.listByIds(combinationIdList);
|
|
|
if (!CollectionUtils.isEmpty(questionList)) {
|
|
|
- questionList.stream().forEach(question -> {
|
|
|
- List<QuestionAnswer> answerList = question.getAnswerList();
|
|
|
- if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
- if (QuestionType.BLANK.getCode().equals(question.getType()) && needClearBlankContent) {//填空题是否清空答案内容
|
|
|
- answerList.stream().forEach(o -> o.setContent(null));
|
|
|
- }
|
|
|
- question.setAnswerList(answerList.stream().sorted(Comparator.comparing(QuestionAnswer::getSort)).collect(Collectors.toList()));
|
|
|
+ resultList.addAll(questionList);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(combinationQuestionList)) {
|
|
|
+ resultList.addAll(combinationQuestionList);
|
|
|
+ }
|
|
|
+ //清空填空题答案并重新排序
|
|
|
+ if (!CollectionUtils.isEmpty(resultList)) {
|
|
|
+ resultList.forEach(question -> clearBlankAnswer(question, needClearBlankContent));
|
|
|
+ }
|
|
|
+ rootExamQuestionList.forEach(o -> {
|
|
|
+ Question question = resultList.stream().filter(r -> r.getId().equals(o.getQuestionId())).findFirst().orElse(null);
|
|
|
+ if (QuestionType.COMBINATION.getCode().equals(o.getQuestionType())) {//组合题
|
|
|
+ List<UserExamQuestion> subQuestionList = childQuestionList.stream().filter(c -> StringUtils.isNotBlank(c.getParentQuestionId())
|
|
|
+ && c.getParentQuestionId().equals(o.getQuestionId())).sorted(Comparator.comparing(UserExamQuestion::getSort))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!Objects.isNull(question) && !CollectionUtils.isEmpty(subQuestionList)) {
|
|
|
+ subQuestionList.forEach(subQuestion -> {
|
|
|
+ Question tmp = resultList.stream().filter(r -> r.getId().equals(subQuestion.getQuestionId())).findFirst().orElse(null);
|
|
|
+ if (!Objects.isNull(tmp)) {
|
|
|
+ subQuestion.setQuestion(tmp);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ o.setSubQuestionList(subQuestionList);
|
|
|
}
|
|
|
- });
|
|
|
+ o.setQuestion(question);
|
|
|
+ } else {
|
|
|
+ if (!Objects.isNull(question)) {
|
|
|
+ o.setQuestion(question);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取主观题
|
|
|
+ *
|
|
|
+ * @param userExamQuestionList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getSubjectList(List<UserExamQuestion> userExamQuestionList) {
|
|
|
+ return userExamQuestionList.stream().filter(o -> o.getQuestionType().equals(QuestionType.SIMPLE.getCode()))
|
|
|
+ .map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getObjectiveList(List<UserExamQuestion> userExamQuestionList) {
|
|
|
+ return userExamQuestionList.stream().filter(o -> !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())
|
|
|
+ && !o.getQuestionType().equals(QuestionType.COMBINATION.getCode())).map(UserExamQuestion::getQuestionId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清空填空题答案
|
|
|
+ *
|
|
|
+ * @param question
|
|
|
+ * @param needClearBlankContent
|
|
|
+ */
|
|
|
+ public void clearBlankAnswer(Question question, boolean needClearBlankContent) {
|
|
|
+ List<QuestionAnswer> answerList = question.getAnswerList();
|
|
|
+ if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
+ if (QuestionType.BLANK.getCode().equals(question.getType()) && needClearBlankContent) {//填空题是否清空答案内容
|
|
|
+ answerList.forEach(o -> o.setContent(null));
|
|
|
+ }
|
|
|
+ question.setAnswerList(answerList.stream().sorted(Comparator.comparing(QuestionAnswer::getSort)).collect(Collectors.toList()));
|
|
|
}
|
|
|
- return questionList.stream().collect(Collectors.toMap(Question::getId, a -> a, (k1, k2) -> k1));
|
|
|
}
|
|
|
|
|
|
//获取题目和答案
|