| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ycl.jxkg.domain.entity.ExamPaperScore; |
| | | import com.ycl.jxkg.domain.entity.Question; |
| | | import com.ycl.jxkg.domain.entity.QuestionAnswerRecord; |
| | | import com.ycl.jxkg.domain.vo.DoQuestionVO; |
| | | import com.ycl.jxkg.domain.vo.PaperFixQuestionVO; |
| | | import com.ycl.jxkg.domain.vo.student.wrong.WrongPageVo; |
| | | import com.ycl.jxkg.domain.vo.student.wrong.WrongRequestVo; |
| | | import com.ycl.jxkg.domain.vo.student.wrong.WrongResponseVO; |
| | | import com.ycl.jxkg.mapper.ExamPaperScoreMapper; |
| | | import com.ycl.jxkg.mapper.QuestionAnswerRecordMapper; |
| | | import com.ycl.jxkg.mapper.QuestionMapper; |
| | | import com.ycl.jxkg.service.WrongService; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | private ExamPaperScoreMapper examPaperScoreMapper; |
| | | @Autowired |
| | | private QuestionMapper questionMapper; |
| | | @Autowired |
| | | private QuestionAnswerRecordMapper questionAnswerRecordMapper; |
| | | |
| | | |
| | | |
| | |
| | | * 条件查询错题 |
| | | * */ |
| | | @Override |
| | | public WrongResponseVO list(WrongRequestVo wrongRequestVo) { |
| | | WrongResponseVO wrongResponseVO = new WrongResponseVO(); |
| | | // 查询该用户的所有考试 |
| | | List<ExamPaperScore> examPaperScores = examPaperScoreMapper.selectByUserId(wrongRequestVo.getUserId()); |
| | | List<DoQuestionVO> questions = new ArrayList<>(); |
| | | // 遍历所有考试获得考试详情 |
| | | examPaperScores.stream().forEach(examPaperScore -> { |
| | | try{ |
| | | // 解析json字符串 |
| | | List<PaperFixQuestionVO> paperFixQuestionVOS = JsonUtil.toJsonListObject(examPaperScore.getPaperContent(), PaperFixQuestionVO.class); |
| | | paperFixQuestionVOS.stream().forEach(paperFixQuestionVO -> { |
| | | List<DoQuestionVO> doQuestionVOS = paperFixQuestionVO.getQuestionList().stream() |
| | | .filter(doQuestionVO -> !doQuestionVO.getRight()) |
| | | .map(doQuestionVO -> { |
| | | // 根据id查询题干 |
| | | Question question = questionMapper.selectOne(new LambdaQueryWrapper<>(Question.class).eq(Question::getId, doQuestionVO.getId())); |
| | | // Question question = questionMapper.selectById(doQuestionVO.getId()); |
| | | doQuestionVO.setExamId(examPaperScore.getExamId()); |
| | | doQuestionVO.setExamName(examPaperScore.getExamName()); |
| | | doQuestionVO.setTitle(question.getTitle()); |
| | | // 考试结果记录id |
| | | doQuestionVO.setId(examPaperScore.getId()); |
| | | return doQuestionVO; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | questions.addAll(doQuestionVOS); |
| | | }); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | public PageInfo<WrongResponseVO> list(WrongRequestVo wrongRequestVo) { |
| | | return PageHelper.startPage(wrongRequestVo.getPageIndex(), wrongRequestVo.getPageSize()).doSelectPageInfo(() -> { |
| | | questionAnswerRecordMapper.selectWrongQuestion(wrongRequestVo); |
| | | }); |
| | | // 条件查询 |
| | | // 对集合中的题目进行模糊查询过滤 |
| | | List<DoQuestionVO> doQuestionVOS = questions.stream() |
| | | // 标题不为空或空字符串,模糊查询 |
| | | .filter(question -> { |
| | | if (wrongRequestVo.getTitle() == null || wrongRequestVo.getTitle().trim().isEmpty()) { |
| | | return true; |
| | | } |
| | | return Optional.ofNullable(question.getTitle()).orElse("").toLowerCase().contains(wrongRequestVo.getTitle().toLowerCase()); |
| | | }) |
| | | .filter(question -> { |
| | | if (wrongRequestVo.getQuestionType() == null) { |
| | | return true; |
| | | } |
| | | return question.getQuestionType().equals(wrongRequestVo.getQuestionType()); |
| | | }) |
| | | .filter(question -> { |
| | | if (wrongRequestVo.getExamName() == null || wrongRequestVo.getExamName().trim().isEmpty()) { |
| | | return true; |
| | | } |
| | | return Optional.ofNullable(question.getExamName()).orElse("").toLowerCase().contains(wrongRequestVo.getExamName().toLowerCase()); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | // 分页 |
| | | List<DoQuestionVO> list = doQuestionVOS.stream().skip((wrongRequestVo.getPageIndex() - 1) * wrongRequestVo.getPageSize()).collect(Collectors.toList()).stream().limit(wrongRequestVo.getPageSize()).collect(Collectors.toList()); |
| | | wrongResponseVO.setList(list); |
| | | wrongResponseVO.setTotal(doQuestionVOS.size()); |
| | | wrongResponseVO.setPageSize(wrongRequestVo.getPageSize()); |
| | | wrongResponseVO.setPageIndex(wrongRequestVo.getPageIndex()); |
| | | return wrongResponseVO; |
| | | } |
| | | } |