| | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | private final UserMapper userMapper; |
| | | private final ExamPaperScoreMapper examPaperScoreMapper; |
| | | private final ExamPaperScoreService examPaperScoreService; |
| | | private final QuestionAnswerRecordMapper questionAnswerRecordMapper; |
| | | |
| | | private final Producer producer; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result all() { |
| | | List<Exam> entities = baseMapper.selectList(null); |
| | | public Result all(ExamQuery query) { |
| | | List<Exam> entities; |
| | | // 判断如果examName为空或空字符串,则查询所有 |
| | | if (query.getExamName() == null || query.getExamName().isEmpty()) { |
| | | entities = baseMapper.selectList(null); |
| | | }else { |
| | | entities = baseMapper.selectList(new LambdaQueryWrapper<>(Exam.class).like(Exam::getExamName,query.getExamName())); |
| | | } |
| | | List<ExamVO> vos = entities.stream() |
| | | .map(entity -> ExamVO.getVoByEntity(entity, null)) |
| | | .map(entity -> { |
| | | ExamVO vo = new ExamVO(); |
| | | vo = ExamVO.getVoByEntity(entity, vo); |
| | | vo.setStatus(entity.getStatus().getDesc()); |
| | | return vo; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | |
| | | examPaperScore.setTotalScore(new BigDecimal(examPaperMark.getTotalScore())); |
| | | examPaperScore.setJudgeUser(userId); |
| | | examPaperScore.setJudgeTime(new Date()); |
| | | if (!StringUtils.isEmpty(examPaperMark.getTitleItems())) { |
| | | if (!org.springframework.util.CollectionUtils.isEmpty(examPaperMark.getTitleItems())) { |
| | | examPaperScore.setPaperContent(JSON.toJSONString(examPaperMark.getTitleItems())); |
| | | // 保存答题记录 |
| | | this.saveQuestionAnswerRecord(examPaperMark.getUserId(), examPaperMark.getTitleItems(), examPaperMark.getExamId(), examPaperMark.getPaperId()); |
| | | } |
| | | if (!StringUtils.isEmpty(examPaperMark.getNavbar())) { |
| | | if (!org.springframework.util.CollectionUtils.isEmpty(examPaperMark.getNavbar())) { |
| | | examPaperScore.setNavbar(JSON.toJSONString(examPaperMark.getNavbar())); |
| | | } |
| | | long questionCorrect = 0; |
| | |
| | | return Result.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 保存答题记录 |
| | | * |
| | | * @param titleItems |
| | | */ |
| | | private void saveQuestionAnswerRecord(Integer studentUserId, List<PaperFixQuestionVO> titleItems, Integer examId, Integer paperId) { |
| | | // 删除原来的答题记录 |
| | | new LambdaUpdateChainWrapper<>(questionAnswerRecordMapper) |
| | | .eq(QuestionAnswerRecord::getExamId, examId) |
| | | .eq(QuestionAnswerRecord::getUserId, studentUserId).remove(); |
| | | for (PaperFixQuestionVO titleItem : titleItems) { |
| | | for (DoQuestionVO question : titleItem.getQuestionList()) { |
| | | QuestionAnswerRecord record = new QuestionAnswerRecord(); |
| | | record.setQuestionType(titleItem.getQuestionType()); |
| | | record.setUserId(studentUserId); |
| | | record.setDoRight(question.getRight()); |
| | | record.setExamId(examId); |
| | | record.setPaperId(paperId); |
| | | record.setQuestionId(question.getId()); |
| | | record.setScore(question.getScore()); |
| | | record.setUserAnswer(StringUtils.hasText(question.getAnswer()) ? question.getAnswer() : question.getAnswerList().stream().collect(Collectors.joining("、"))); |
| | | questionAnswerRecordMapper.insert(record); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result monitorList(ExamQuery query) { |