查询题库下题目时,返回复合题下的子题目

This commit is contained in:
Lqc 2025-08-25 12:46:40 +08:00
parent 35ed6f0b1b
commit 52798ce478
2 changed files with 30 additions and 5 deletions

View File

@ -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<List<Question>> questionList(@PathVariable String repoId) {
List<String> list = questionRepoService.questionList(repoId);
return Result.ok(questionService.listByIds(list));
List<Question> questions = questionService.listByIds(list);
//获取复选题id
List<String> type5Ids = questions.stream()
.filter(question -> question.getType() == 5)
.map(Question::getId)
.collect(Collectors.toList());
//获取复选题所包含的题目
List<Question> type5Questions = new ArrayList<>();
if (!type5Ids.isEmpty()) {
type5Questions = questionService.list(
new LambdaQueryWrapper<Question>()
.in(Question::getParentId, type5Ids)
);
}
// 创建一个映射用于快速查找父ID对应的子题目
Map<String, List<Question>> parentToChildrenMap = type5Questions.stream()
.collect(Collectors.groupingBy(Question::getParentId));
// 将子题目添加到原始列表中保持原有顺序
List<Question> resultQuestions = new ArrayList<>();
for (Question question : questions) {
resultQuestions.add(question);
if (question.getType() == 5) {
List<Question> children = parentToChildrenMap.getOrDefault(question.getId(), Collections.emptyList());
resultQuestions.addAll(children);
}
}
return Result.ok(resultQuestions);
}
@GetMapping("course_list")

View File

@ -119,6 +119,7 @@ public class QuestionController extends JeecgController<Question, IQuestionServi
@Operation(summary="题目-通过id删除")
@RequiresPermissions("gen.question:question:delete")
@DeleteMapping(value = "/delete")
@Transactional
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
Question question = questionService.getById(id);
questionService.removeById(id);