From d9c50d475072c00035d617ec62df7345571e20a0 Mon Sep 17 00:00:00 2001 From: Lqc Date: Sat, 23 Aug 2025 14:57:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=AF=B9=E4=BA=8E=E5=A4=8D=E5=90=88=E9=A2=98?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=A2=98=E7=9B=AE=E5=8F=8A=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/controller/RepoBizController.java | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java index 9c8e7e88..93dd51e7 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java @@ -22,8 +22,10 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @RestController @@ -96,19 +98,52 @@ public class RepoBizController { @GetMapping("/repoList/{questionId}") @Operation(summary = "查询题目详情") public Result questionDetail(@PathVariable String questionId,@RequestParam Integer type) { - if (type == 1 || type == 2 || type == 3) { - return Result.ok(choiceDetail(questionId)); - }else if(type == 4 || type == 5) { + if (type == 0 || type == 1 || type == 2) { + List questionOptions = choiceDetail(questionId); + return Result.ok(questionOptions); + }else if(type == 3 || type == 4) { return Result.ok(answerDetail(questionId)); }else { - return Result.ok(questionService.list( + //查询复合题所包含的题目 + List list = questionService.list( new LambdaQueryWrapper(). eq(Question::getParentId, questionId) - ) ); + //根据题目类型进行分组(false:选择多选判断题,true:填空简答题) + Map> groupedQuestions = list.stream() + .collect(Collectors.partitioningBy( + q -> q.getType() > 2 + )); + Map>> questionOptionMap = new HashMap<>(); + //获取选择题,多选题,判断题答案 + List question = groupedQuestions.get(false); + if(!question.isEmpty()){ + Map> questionListHashMap = new HashMap<>(); + question.forEach(q -> { + ArrayList objects = new ArrayList<>(); + objects.add(q); + objects.add(choiceDetail(q.getId())); + questionListHashMap.put(q.getId(), objects); + }); + questionOptionMap.put("questionOption", questionListHashMap); + } + //获取填空题,简答题答案 + List question1 = groupedQuestions.get(true); + if(!question1.isEmpty()){ + Map> questionAnswerMap = new HashMap<>(); + question1.forEach(q -> { + ArrayList objects = new ArrayList<>(); + objects.add(q); + objects.add(answerDetail(q.getId())); + questionAnswerMap.put(q.getId(), objects); + }); + questionOptionMap.put("questionAnswer", questionAnswerMap); + } + return Result.ok(questionOptionMap); } } + //查询选择题,多选题,判断题答案 public List choiceDetail(String questionId) { return questionOptionService.list( new LambdaQueryWrapper(). @@ -117,7 +152,7 @@ public class RepoBizController { ); } - + //查询填空题,简答题答案 public List answerDetail(String questionId) { return questionAnswerService.list( new LambdaQueryWrapper(). From 52798ce478c49fec9167a75a12b80885020aefbc Mon Sep 17 00:00:00 2001 From: Lqc Date: Mon, 25 Aug 2025 12:46:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=A2=98=E5=BA=93?= =?UTF-8?q?=E4=B8=8B=E9=A2=98=E7=9B=AE=E6=97=B6=EF=BC=8C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E5=90=88=E9=A2=98=E4=B8=8B=E7=9A=84=E5=AD=90=E9=A2=98?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/controller/RepoBizController.java | 34 ++++++++++++++++--- .../controller/QuestionController.java | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java index 93dd51e7..aee92008 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/RepoBizController.java @@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @@ -79,7 +76,34 @@ public class RepoBizController { @Operation(summary = "查询题库下题目") public Result> questionList(@PathVariable String repoId) { List list = questionRepoService.questionList(repoId); - return Result.ok(questionService.listByIds(list)); + List questions = questionService.listByIds(list); + //获取复选题id + List type5Ids = questions.stream() + .filter(question -> question.getType() == 5) + .map(Question::getId) + .collect(Collectors.toList()); + //获取复选题所包含的题目 + List type5Questions = new ArrayList<>(); + if (!type5Ids.isEmpty()) { + type5Questions = questionService.list( + new LambdaQueryWrapper() + .in(Question::getParentId, type5Ids) + ); + } + // 创建一个映射,用于快速查找父ID对应的子题目 + Map> parentToChildrenMap = type5Questions.stream() + .collect(Collectors.groupingBy(Question::getParentId)); + + // 将子题目添加到原始列表中,保持原有顺序 + List resultQuestions = new ArrayList<>(); + for (Question question : questions) { + resultQuestions.add(question); + if (question.getType() == 5) { + List children = parentToChildrenMap.getOrDefault(question.getId(), Collections.emptyList()); + resultQuestions.addAll(children); + } + } + return Result.ok(resultQuestions); } @GetMapping("course_list") diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/question/controller/QuestionController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/question/controller/QuestionController.java index b7262f81..08921abe 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/question/controller/QuestionController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/question/controller/QuestionController.java @@ -119,6 +119,7 @@ public class QuestionController extends JeecgController delete(@RequestParam(name="id",required=true) String id) { Question question = questionService.getById(id); questionService.removeById(id);