|
@@ -31,7 +31,10 @@ import com.yntravelsky.buss.exam.userexam.entity.UserExam;
|
|
|
import com.yntravelsky.buss.exam.userexam.service.IUserExamService;
|
|
|
import com.yntravelsky.buss.exam.userexamquestion.entity.UserExamQuestion;
|
|
|
import com.yntravelsky.buss.exam.userexamquestion.service.IUserExamQuestionService;
|
|
|
+import com.yntravelsky.buss.exam.userexamquestionanswer.entity.UserExamQuestionAnswer;
|
|
|
+import com.yntravelsky.buss.exam.userexamquestionanswer.service.IUserExamQuestionAnswerService;
|
|
|
import com.yntravelsky.buss.exam.userexamresult.service.IUserExamResultService;
|
|
|
+import com.yntravelsky.common.utils.CharUtil;
|
|
|
import com.yntravelsky.common.utils.CronUtils;
|
|
|
import com.yntravelsky.common.utils.ThreadPoolUtil;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -92,6 +95,10 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
@Autowired
|
|
|
private ISysDepartService sysDepartService;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserExamQuestionAnswerService userExamQuestionAnswerService;
|
|
|
+
|
|
|
@Override
|
|
|
public Exam detail(String id) {
|
|
|
return examMapper.detail(id);
|
|
@@ -146,6 +153,11 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
List<PaperQuestion> paperQuestionList = null;
|
|
|
if (paper.getJoinType().intValue() == JoinType.XT.getCode()) {//选题
|
|
|
paperQuestionList = paperQuestionService.listByPaperId(paper.getId());
|
|
|
+ //题目乱序
|
|
|
+ if (!Objects.isNull(exam.getQuestionDisorder()) && exam.getQuestionDisorder()) {
|
|
|
+ //题目洗牌
|
|
|
+ paperQuestionList = questionShuffle(paperQuestionList);
|
|
|
+ }
|
|
|
} else if (paper.getJoinType().intValue() == JoinType.SJ.getCode()) {//随机抽题
|
|
|
//生成题目
|
|
|
paperQuestionList = paperService.generateQuestion(paper.getId());
|
|
@@ -157,6 +169,22 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
return this.saveExam(userId, exam, paper.getId(), paperQuestionList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 题目乱序
|
|
|
+ */
|
|
|
+ public List<PaperQuestion> questionShuffle(List<PaperQuestion> paperQuestionList) {
|
|
|
+ List<PaperQuestion> shuffleList = new ArrayList<>();
|
|
|
+ Map<Integer, List<PaperQuestion>> map = paperQuestionList.stream()
|
|
|
+ .collect(Collectors.groupingBy(PaperQuestion::getQuestionType, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ for (Map.Entry<Integer, List<PaperQuestion>> item : map.entrySet()) {
|
|
|
+ //题目洗牌
|
|
|
+ Collections.shuffle(item.getValue());
|
|
|
+ shuffleList.addAll(item.getValue());
|
|
|
+ }
|
|
|
+ //重新排序
|
|
|
+ return paperQuestionService.sort(shuffleList);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 保存考试
|
|
@@ -180,6 +208,8 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
//保存考试关联的试题列表
|
|
|
if (!CollectionUtils.isEmpty(paperQuestionList)) {
|
|
|
this.savePaperQuestion(userExam.getId(), paperQuestionList);
|
|
|
+ //保存用户考试的题目答案
|
|
|
+ this.saveQuestionAnswer(userExam.getId(), exam, paperQuestionList);
|
|
|
}
|
|
|
|
|
|
// 截止时间
|
|
@@ -196,6 +226,44 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
return userExam;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存用户考试的题目答案
|
|
|
+ *
|
|
|
+ * @param userExamId
|
|
|
+ * @param paperQuestionList
|
|
|
+ */
|
|
|
+ public void saveQuestionAnswer(String userExamId, Exam exam, List<PaperQuestion> paperQuestionList) {
|
|
|
+ //获取题目和答案
|
|
|
+ List<Question> questionList = listQuestion(paperQuestionList);
|
|
|
+ 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.JUDGE.getCode().intValue() != 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);
|
|
|
+ userExamQuestionAnswer.setTag(CharUtil.getZm(sort - 1));
|
|
|
+ userExamQuestionAnswerList.add(userExamQuestionAnswer);
|
|
|
+ sort++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ userExamQuestionAnswerService.saveBatch(userExamQuestionAnswerList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 创建定时任务
|
|
@@ -261,7 +329,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
List<Map<String, AnswerCardDTO>> answerCardList = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(userExamQuestionList)) {
|
|
|
//获取题目和答案
|
|
|
- Map<String, Question> questionMap = getQuestionMap(userExamQuestionList, needAnswerFlag, needAnalysis);
|
|
|
+ Map<String, Question> questionMap = getUserExamQuestionMap(userExamId, userExamQuestionList, needAnswerFlag, needAnalysis);
|
|
|
|
|
|
//设置题目
|
|
|
setUserExamQuestion(questionMap, userExamQuestionList);
|
|
@@ -386,7 +454,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
.toMap(UserExamQuestion::getQuestionIndex, a -> a, (k1, k2) -> k1));
|
|
|
|
|
|
//获取题目和答案
|
|
|
- Map<String, Question> questionMap = getQuestionMap(userExamQuestionList, true, false);
|
|
|
+ Map<String, Question> questionMap = getUserExamQuestionMap(dto.getUserExamId(), userExamQuestionList, true, false);
|
|
|
|
|
|
//计算最终得分
|
|
|
int score = calcFinalScore(examAnswers, userExamQuestionMap, questionMap, userExamQuestionList);
|
|
@@ -403,12 +471,19 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
|
|
|
|
|
|
//获取题目和答案
|
|
|
- public Map<String, Question> getQuestionMap(List<UserExamQuestion> userExamQuestionList, boolean needAnswerFlag, boolean needAnalysis) {
|
|
|
+ public Map<String, Question> getUserExamQuestionMap(String userExamId, List<UserExamQuestion> userExamQuestionList,
|
|
|
+ boolean needAnswerFlag, boolean needAnalysis) {
|
|
|
List<String> questionIdList = userExamQuestionList.stream().map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
- List<Question> questionList = questionService.selectQuestionList(questionIdList, needAnswerFlag, needAnalysis);
|
|
|
+ List<Question> questionList = questionService.listUserExamQuestionAnswer(userExamId, questionIdList, needAnswerFlag, needAnalysis);
|
|
|
return questionList.stream().collect(Collectors.toMap(Question::getId, a -> a, (k1, k2) -> k1));
|
|
|
}
|
|
|
|
|
|
+ //获取题目和答案
|
|
|
+ public List<Question> listQuestion(List<PaperQuestion> paperQuestionList) {
|
|
|
+ List<String> questionIdList = paperQuestionList.stream().map(PaperQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ return questionService.selectQuestionList(questionIdList, true, true);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 计算最终得分
|