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 aee92008..b3988c24 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 @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.biz.constant.EntityLinkConst; +import org.jeecg.modules.biz.dto.QuestionAnswerDTO; import org.jeecg.modules.biz.service.EntityLinkBizService; import org.jeecg.modules.gen.question.entity.Question; import org.jeecg.modules.gen.question.service.IQuestionService; @@ -41,7 +42,7 @@ public class RepoBizController { @Autowired private EntityLinkBizService entityLinkBizService; @Autowired - private IQuestionService questionService; + private IQuestionService questionService; @Autowired private IQuestionOptionService questionOptionService; @Autowired @@ -68,7 +69,7 @@ public class RepoBizController { @PostMapping(value = "/courseAdd") @Operation(summary = "课程新建题库") public Result courseAdd(@RequestBody Repo repo) { - return repoService.save(repo)?Result.OK("添加成功!"):Result.error("添加失败!"); + return repoService.save(repo) ? Result.OK("添加成功!") : Result.error("添加失败!"); } @@ -121,13 +122,20 @@ public class RepoBizController { @GetMapping("/repoList/{questionId}") @Operation(summary = "查询题目详情") - public Result questionDetail(@PathVariable String questionId,@RequestParam Integer type) { - 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 { + public Result questionDetail(@PathVariable String questionId) { + Question rootQuestion = questionService.getById(questionId); + if (rootQuestion == null) { + return Result.error("题目不存在"); + } + QuestionAnswerDTO questionAnswerDTO = new QuestionAnswerDTO(); + questionAnswerDTO.setQuestion(rootQuestion); + if (rootQuestion.getType() >= 0 && rootQuestion.getType() <= 2) { + questionAnswerDTO.setAnswer(choiceDetail(questionId)); + return Result.ok(questionAnswerDTO); + } else if (rootQuestion.getType() == 3 || rootQuestion.getType() == 4) { + questionAnswerDTO.setAnswer(answerDetail(questionId)); + return Result.ok(questionAnswerDTO); + } else { //查询复合题所包含的题目 List list = questionService.list( new LambdaQueryWrapper(). @@ -138,35 +146,31 @@ public class RepoBizController { .collect(Collectors.partitioningBy( q -> q.getType() > 2 )); - Map>> questionOptionMap = new HashMap<>(); //获取选择题,多选题,判断题答案 List question = groupedQuestions.get(false); - if(!question.isEmpty()){ - Map> questionListHashMap = new HashMap<>(); + if (!question.isEmpty()) { question.forEach(q -> { - ArrayList objects = new ArrayList<>(); - objects.add(q); - objects.add(choiceDetail(q.getId())); - questionListHashMap.put(q.getId(), objects); + QuestionAnswerDTO qad = new QuestionAnswerDTO(); + qad.setQuestion(q); + qad.setAnswer(choiceDetail(q.getId())); + questionAnswerDTO.getChildren().add(qad); }); - questionOptionMap.put("questionOption", questionListHashMap); } //获取填空题,简答题答案 List question1 = groupedQuestions.get(true); - if(!question1.isEmpty()){ - Map> questionAnswerMap = new HashMap<>(); + if (!question1.isEmpty()) { question1.forEach(q -> { - ArrayList objects = new ArrayList<>(); - objects.add(q); - objects.add(answerDetail(q.getId())); - questionAnswerMap.put(q.getId(), objects); + QuestionAnswerDTO qad = new QuestionAnswerDTO(); + qad.setQuestion(q); + qad.setAnswer(answerDetail(q.getId())); + questionAnswerDTO.getChildren().add(qad); }); - questionOptionMap.put("questionAnswer", questionAnswerMap); } - return Result.ok(questionOptionMap); + return Result.ok(questionAnswerDTO); } } + //查询选择题,多选题,判断题答案 public List choiceDetail(String questionId) { return questionOptionService.list( @@ -180,7 +184,8 @@ public class RepoBizController { public List answerDetail(String questionId) { return questionAnswerService.list( new LambdaQueryWrapper(). - eq(QuestionAnswer::getQuestionId, questionId) + eq(QuestionAnswer::getQuestionId, questionId). + orderByAsc(QuestionAnswer::getOrderNo) ); } diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/dto/QuestionAnswerDTO.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/dto/QuestionAnswerDTO.java new file mode 100644 index 00000000..37e2dbaf --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/dto/QuestionAnswerDTO.java @@ -0,0 +1,17 @@ +package org.jeecg.modules.biz.dto; + +import lombok.Data; +import org.jeecg.modules.gen.question.entity.Question; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class QuestionAnswerDTO { + //题目内容 + private Question question; + //答案 + private List answer; + //子题目列表 + private List children = new ArrayList<>(); +}