luohairen
2024-11-07 4adad521e6464025402639d0c2f7602610d15a67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.ycl.jxkg.service.impl;
 
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.WrongRequestVo;
import com.ycl.jxkg.mapper.ExamPaperScoreMapper;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
@RequiredArgsConstructor
@Slf4j
public class WrongServiceImpl implements WrongService {
    @Autowired
    private ExamPaperScoreMapper examPaperScoreMapper;
    @Autowired
    private QuestionMapper questionMapper;
 
 
 
    /**
     * 分页条件查询错题
     * */
    @Override
    public List<DoQuestionVO> page(WrongRequestVo wrongRequestVo) {
        // 查询该用户的所有非随机试卷及试卷错题
//        List<ExamPaperScore> examPaperScores = examPaperScoreMapper
//                .selectList(new LambdaQueryChainWrapper<>(ExamPaperScore.class)
//                        .eq(ExamPaperScore::getUserId,wrongRequestVo.getUserId()));
        // 查询该用户的所有考试
        List<ExamPaperScore> examPaperScores = examPaperScoreMapper.selectByUserId(wrongRequestVo.getUserId());
        List<PaperFixQuestionVO> paperList = new ArrayList<>();
        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.selectById(doQuestionVO.getId());
                                doQuestionVO.setExamId(examPaperScore.getExamId());
                                doQuestionVO.setExamName(examPaperScore.getExamName());
                                doQuestionVO.setTitle(question.getTitle());
                                return doQuestionVO;
                            })
                            .collect(Collectors.toList());
                    questions.addAll(doQuestionVOS);
                });
            }catch (Exception e){
                e.printStackTrace();
            }
        });
        return questions;
    }
}