luohairen
2024-11-11 cd59ededbf05a0ae73b8f4944fbf40a1fb01d28a
src/main/java/com/ycl/jxkg/service/impl/WrongServiceImpl.java
@@ -1,10 +1,13 @@
package com.ycl.jxkg.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ycl.jxkg.domain.entity.ExamPaperScore;
import com.ycl.jxkg.domain.entity.Question;
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.QuestionMapper;
import com.ycl.jxkg.service.WrongService;
@@ -30,17 +33,13 @@
    /**
     * 分页条件查询错题
     * 条件查询错题
     * */
    @Override
    public List<DoQuestionVO> page(WrongRequestVo wrongRequestVo) {
        // 查询该用户的所有非随机试卷及试卷错题
//        List<ExamPaperScore> examPaperScores = examPaperScoreMapper
//                .selectList(new LambdaQueryChainWrapper<>(ExamPaperScore.class)
//                        .eq(ExamPaperScore::getUserId,wrongRequestVo.getUserId()));
    public WrongResponseVO page(WrongRequestVo wrongRequestVo) {
        WrongResponseVO wrongResponseVO = new WrongResponseVO();
        // 查询该用户的所有考试
        List<ExamPaperScore> examPaperScores = examPaperScoreMapper.selectByUserId(wrongRequestVo.getUserId());
        List<PaperFixQuestionVO> paperList = new ArrayList<>();
        List<DoQuestionVO> questions = new ArrayList<>();
        // 遍历所有考试获得考试详情
        examPaperScores.stream().forEach(examPaperScore -> {
@@ -52,10 +51,13 @@
                            .filter(doQuestionVO -> !doQuestionVO.getRight())
                            .map(doQuestionVO -> {
                                // 根据id查询题干
                                Question question = questionMapper.selectById(doQuestionVO.getId());
                                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());
@@ -65,6 +67,35 @@
                e.printStackTrace();
            }
        });
        return questions;
        // 条件查询
        // 对集合中的题目进行模糊查询过滤
        List<DoQuestionVO> doQuestionVOS = questions.stream()
                // 标题不为空或空字符串,模糊查询
                .filter(question -> {
                    if (wrongRequestVo.getTitle() == null || wrongRequestVo.getTitle().trim().equals("")) {
                        return true;
                    }
                    return question.getTitle().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().equals("")) {
                        return true;
                    }
                    return question.getExamName().toLowerCase().contains(wrongRequestVo.getExamName().toLowerCase());
                })
                .collect(Collectors.toList());
        // 分页
        List<DoQuestionVO> list = doQuestionVOS.stream().skip((wrongRequestVo.getPageIndex() - 1) * wrongRequestVo.getPageSize()).collect(Collectors.toList());
        wrongResponseVO.setList(list);
        wrongResponseVO.setTotal(doQuestionVOS.size());
        wrongResponseVO.setPageSize(wrongRequestVo.getPageSize());
        wrongResponseVO.setPageIndex(wrongRequestVo.getPageIndex());
        return wrongResponseVO;
    }
}