From 53f8fc0e1e152656652d58a374c973191a527b9d Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期二, 12 十一月 2024 16:06:25 +0800
Subject: [PATCH] 优化错题查询
---
src/main/java/com/ycl/jxkg/service/impl/WrongServiceImpl.java | 50 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/service/impl/WrongServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/WrongServiceImpl.java
index aaa7bb6..70aa8fe 100644
--- a/src/main/java/com/ycl/jxkg/service/impl/WrongServiceImpl.java
+++ b/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;
@@ -16,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.stream.Collectors;
@Service
@@ -30,17 +34,13 @@
/**
- * 鍒嗛〉鏉′欢鏌ヨ閿欓
+ * 鏉′欢鏌ヨ閿欓
* */
@Override
- public List<DoQuestionVO> page(WrongRequestVo wrongRequestVo) {
- // 鏌ヨ璇ョ敤鎴风殑鎵�鏈夐潪闅忔満璇曞嵎鍙婅瘯鍗烽敊棰�
-// List<ExamPaperScore> examPaperScores = examPaperScoreMapper
-// .selectList(new LambdaQueryChainWrapper<>(ExamPaperScore.class)
-// .eq(ExamPaperScore::getUserId,wrongRequestVo.getUserId()));
+ public WrongResponseVO list(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 +52,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 +68,35 @@
e.printStackTrace();
}
});
- return questions;
+ // 鏉′欢鏌ヨ
+ // 瀵归泦鍚堜腑鐨勯鐩繘琛屾ā绯婃煡璇㈣繃婊�
+ 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;
}
}
--
Gitblit v1.8.0