|
@@ -147,6 +147,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
}
|
|
|
List<PaperQuestion> paperQuestionList = null;
|
|
|
if (paper.getJoinType().equals(JoinType.XT.getCode()) || paper.getJoinType().equals(JoinType.CT.getCode())) {//选题或者抽题
|
|
|
+ //只查询父题目
|
|
|
paperQuestionList = paperQuestionService.listByPaperId(paper.getId());
|
|
|
//题目乱序
|
|
|
if (!Objects.isNull(exam.getQuestionDisorder()) && exam.getQuestionDisorder()) {
|
|
@@ -161,7 +162,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
throw new JeecgBootException("无对应的考题!");
|
|
|
}
|
|
|
//保存考试
|
|
|
- return this.saveExam(userId, exam, paper, paperQuestionList);
|
|
|
+ return this.saveExam(userId, exam, paper, paperQuestionList, paper.getJoinType());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -188,7 +189,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* @param paperQuestionList
|
|
|
* @return
|
|
|
*/
|
|
|
- public UserExam saveExam(String userId, Exam exam, Paper paper, List<PaperQuestion> paperQuestionList) {
|
|
|
+ public UserExam saveExam(String userId, Exam exam, Paper paper, List<PaperQuestion> paperQuestionList, Integer joinType) {
|
|
|
UserExam userExam = new UserExam();
|
|
|
userExam.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
|
|
userExam.setExamId(exam.getId());
|
|
@@ -202,7 +203,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
|
|
|
//保存考试关联的试题列表
|
|
|
if (!CollectionUtils.isEmpty(paperQuestionList)) {
|
|
|
- this.savePaperQuestion(paper.getId(), userExam.getId(), paperQuestionList);
|
|
|
+ this.savePaperQuestion(paper.getId(), userExam.getId(), paperQuestionList, joinType);
|
|
|
//保存用户考试的题目答案
|
|
|
this.saveQuestionAnswer(paper.getId(), userExam.getId(), exam, paperQuestionList);
|
|
|
}
|
|
@@ -309,7 +310,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
/**
|
|
|
* 保存试卷试题列表
|
|
|
*/
|
|
|
- private void savePaperQuestion(String paperId, String userExamId, List<PaperQuestion> paperQuestionList) {
|
|
|
+ private void savePaperQuestion(String paperId, String userExamId, List<PaperQuestion> paperQuestionList, Integer joinType) {
|
|
|
paperQuestionList = paperQuestionList.stream().sorted(Comparator.comparing(PaperQuestion::getQuestionType)
|
|
|
.thenComparing(PaperQuestion::getSort)).collect(Collectors.toList());
|
|
|
//获取规则组map
|
|
@@ -326,13 +327,58 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
//组合题
|
|
|
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);
|
|
|
+ List<PaperQuestion> paperSubQuestionList = null;
|
|
|
+ if (!CollectionUtils.isEmpty(combinationIdList)) {
|
|
|
+ if (joinType.equals(JoinType.XT.getCode()) || joinType.equals(JoinType.CT.getCode())) {//选题或者抽题
|
|
|
+ paperSubQuestionList = paperQuestionService.listPaperSubQuestionByIds(paperId, combinationIdList);
|
|
|
+ } else if (joinType.equals(JoinType.SJ.getCode())) {//随机抽题
|
|
|
+ paperSubQuestionList = new ArrayList<>();
|
|
|
+ List<Question> subQuestionList = questionService.listSubQuestionNoAnswerByIds(combinationIdList);
|
|
|
+ Map<String, Long> subQuestionCountMap = subQuestionList.stream().collect(Collectors.groupingBy(Question::getParentId, Collectors.counting()));
|
|
|
+ for (Question sub : subQuestionList) {
|
|
|
+ PaperQuestion parent = paperQuestionList.stream().filter(r -> r.getQuestionId().equals(sub.getParentId())).findFirst().orElse(null);
|
|
|
+ PaperQuestion paperSubQuestion = getPaperQuestion(paperId, sub, parent, calcSubQuestionScore(subQuestionCountMap, parent));
|
|
|
+ paperSubQuestionList.add(paperSubQuestion);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//配置子题目
|
|
|
configUserExamSubQuestion(userExamId, paperSubQuestionList, groupMap, userExamQuestionList);
|
|
|
|
|
|
userExamQuestionService.saveBatch(userExamQuestionList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 随机组卷组合题计算每个子题目分数
|
|
|
+ *
|
|
|
+ * @param subQuestionCountMap
|
|
|
+ * @param parent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer calcSubQuestionScore(Map<String, Long> subQuestionCountMap, PaperQuestion parent) {
|
|
|
+ int subQuestionScore = 0;
|
|
|
+ if (!Objects.isNull(parent) && !Objects.isNull(subQuestionCountMap)
|
|
|
+ && !Objects.isNull(subQuestionCountMap.get(parent.getQuestionId()))) {
|
|
|
+ //TODO 分数改为double
|
|
|
+ subQuestionScore = parent.getQuestionScore() / subQuestionCountMap.get(parent.getQuestionId()).intValue();
|
|
|
+ }
|
|
|
+ return subQuestionScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static PaperQuestion getPaperQuestion(String paperId, Question sub, PaperQuestion parent, int subQuestionScore) {
|
|
|
+ PaperQuestion paperSubQuestion = new PaperQuestion();
|
|
|
+ paperSubQuestion.setGroupId(!Objects.isNull(parent) ? parent.getGroupId() : null);
|
|
|
+ paperSubQuestion.setPaperId(paperId);
|
|
|
+ paperSubQuestion.setQuestionId(sub.getId());
|
|
|
+ paperSubQuestion.setQuestionType(sub.getType());
|
|
|
+ paperSubQuestion.setChild(sub.getChild());
|
|
|
+ paperSubQuestion.setQuestionScore(subQuestionScore);
|
|
|
+ paperSubQuestion.setSort(sub.getSort());
|
|
|
+ paperSubQuestion.setParentQuestionId(sub.getParentId());
|
|
|
+ return paperSubQuestion;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 配置用户考试试题
|
|
|
*
|