查询题目详情更改返回结果
This commit is contained in:
parent
5861ce2655
commit
97419396f6
@ -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<String> 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<QuestionOption> 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<Question> list = questionService.list(
|
||||
new LambdaQueryWrapper<Question>().
|
||||
@ -138,35 +146,31 @@ public class RepoBizController {
|
||||
.collect(Collectors.partitioningBy(
|
||||
q -> q.getType() > 2
|
||||
));
|
||||
Map<String, Map<String, List<?>>> questionOptionMap = new HashMap<>();
|
||||
//获取选择题,多选题,判断题答案
|
||||
List<Question> question = groupedQuestions.get(false);
|
||||
if(!question.isEmpty()){
|
||||
Map<String, List<?>> questionListHashMap = new HashMap<>();
|
||||
if (!question.isEmpty()) {
|
||||
question.forEach(q -> {
|
||||
ArrayList<Object> 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<Question> question1 = groupedQuestions.get(true);
|
||||
if(!question1.isEmpty()){
|
||||
Map<String, List<?>> questionAnswerMap = new HashMap<>();
|
||||
if (!question1.isEmpty()) {
|
||||
question1.forEach(q -> {
|
||||
ArrayList<Object> 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<QuestionOption> choiceDetail(String questionId) {
|
||||
return questionOptionService.list(
|
||||
@ -180,7 +184,8 @@ public class RepoBizController {
|
||||
public List<QuestionAnswer> answerDetail(String questionId) {
|
||||
return questionAnswerService.list(
|
||||
new LambdaQueryWrapper<QuestionAnswer>().
|
||||
eq(QuestionAnswer::getQuestionId, questionId)
|
||||
eq(QuestionAnswer::getQuestionId, questionId).
|
||||
orderByAsc(QuestionAnswer::getOrderNo)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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<QuestionAnswerDTO> children = new ArrayList<>();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user