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 page(WrongRequestVo wrongRequestVo) { // 查询该用户的所有非随机试卷及试卷错题 // List examPaperScores = examPaperScoreMapper // .selectList(new LambdaQueryChainWrapper<>(ExamPaperScore.class) // .eq(ExamPaperScore::getUserId,wrongRequestVo.getUserId())); // 查询该用户的所有考试 List examPaperScores = examPaperScoreMapper.selectByUserId(wrongRequestVo.getUserId()); List paperList = new ArrayList<>(); List questions = new ArrayList<>(); // 遍历所有考试获得考试详情 examPaperScores.stream().forEach(examPaperScore -> { try{ // 解析json字符串 List paperFixQuestionVOS = JsonUtil.toJsonListObject(examPaperScore.getPaperContent(), PaperFixQuestionVO.class); paperFixQuestionVOS.stream().forEach(paperFixQuestionVO -> { List 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; } }