考试,获取考试试题

This commit is contained in:
Lqc 2025-08-26 14:07:34 +08:00
parent a9a2a16618
commit 796f1502b6
5 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,109 @@
package org.jeecg.modules.biz.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.gen.exam.entity.Exam;
import org.jeecg.modules.gen.exam.service.IExamService;
import org.jeecg.modules.gen.examanswer.service.IExamAnswerService;
import org.jeecg.modules.gen.examrecord.service.IExamRecordService;
import org.jeecg.modules.gen.paper.entity.Paper;
import org.jeecg.modules.gen.paper.service.IPaperService;
import org.jeecg.modules.gen.paperquestion.entity.PaperQuestion;
import org.jeecg.modules.gen.paperquestion.service.IPaperQuestionService;
import org.jeecg.modules.gen.question.entity.Question;
import org.jeecg.modules.gen.question.service.IQuestionService;
import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo;
import org.jeecg.modules.gen.questionrepo.service.IQuestionRepoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/biz/exam")
@Tag(name = "考试")
@Slf4j
public class ExamBizController {
@Autowired
private IPaperService paperService;
@Autowired
private IExamService examService;
@Autowired
private IPaperQuestionService paperQuestionService;
@Autowired
private IExamAnswerService examAnswerService;
@Autowired
private IExamRecordService examRecordService;
@Autowired
private IQuestionService questionService;
@Autowired
private IQuestionRepoService questionRepoService;
//获取考试试题
@RequestMapping("/getExamQuestions/{examId}")
@Operation(summary = "获取考试试题")
public Result<?> getExamQuestions(@PathVariable String examId, @RequestParam String studentId) {
Exam exam = examService.getById(examId);
if(exam.getPaperId().isEmpty()){
return Result.error("考试未关联试卷");
}
Paper paper = paperService.getById(exam.getPaperId());
//题目id集合
List<String> questionIds;
List<PaperQuestion> paperQuestions = new ArrayList<>();
//随机组卷
if(paper.getGenerateMode()==1){
List<QuestionRepo> list = questionRepoService.list(
new LambdaQueryWrapper<QuestionRepo>().
eq(QuestionRepo::getRepoId, paper.getRepoId())
);
questionIds = list.stream()
.map(QuestionRepo::getQuestionId)
.collect(Collectors.toList());
}else {
//固定组卷
// 获取试卷中的试题关联信息
paperQuestions = paperQuestionService.getQuestions(paper.getId());
// 如果没有试题关联信息直接返回空列表
if (CollectionUtils.isEmpty(paperQuestions)) {
return Result.OK("试卷中没有试题");
}
// 提取所有试题ID
questionIds = paperQuestions.stream()
.map(PaperQuestion::getQuestionId)
.collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(questionIds)) {
return Result.OK("试卷中没有试题");
}
// 从题目表查询试题内容
List<Question> questions = questionService.listByIds(questionIds);
List<Question> sortedQuestions = questions;
// 将试题内容按试卷中的顺序排序
if(paper.getGenerateMode()==0){
Map<String, Question> questionMap = questions.stream()
.collect(Collectors.toMap(Question::getId, question -> question));
sortedQuestions = paperQuestions.stream()
.sorted(Comparator.comparing(PaperQuestion::getOrderNo))
.map(paperQuestion -> questionMap.get(paperQuestion.getQuestionId()))
.collect(Collectors.toList());
}
// 返回排序后的试题列表
return Result.OK(sortedQuestions);
}
}

View File

@ -75,6 +75,19 @@ public class PaperController extends JeecgController<Paper, IPaperService> {
IPage<Paper> pageList = paperService.page(page, queryWrapper);
return Result.OK(pageList);
}
//查询教师名下的试卷
@GetMapping(value = "/listByTeacher/{teacherId}")
public Result<IPage<Paper>> queryPageListByTeacher(@PathVariable String teacherId,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize
) {
QueryWrapper<Paper> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("teacher_id", teacherId);
Page<Paper> page = new Page<Paper>(pageNo, pageSize);
IPage<Paper> pageList = paperService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.gen.paperquestion.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.gen.paperquestion.entity.PaperQuestion;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @Date: 2025-08-26
* @Version: V1.0
*/
@Mapper
public interface PaperQuestionMapper extends BaseMapper<PaperQuestion> {
}

View File

@ -3,6 +3,8 @@ package org.jeecg.modules.gen.paperquestion.service;
import org.jeecg.modules.gen.paperquestion.entity.PaperQuestion;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @Description: 试卷试题
* @Author: jeecg-boot
@ -11,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IPaperQuestionService extends IService<PaperQuestion> {
List<PaperQuestion> getQuestions(String id);
}

View File

@ -1,12 +1,16 @@
package org.jeecg.modules.gen.paperquestion.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.gen.paperquestion.entity.PaperQuestion;
import org.jeecg.modules.gen.paperquestion.mapper.PaperQuestionMapper;
import org.jeecg.modules.gen.paperquestion.service.IPaperQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
/**
* @Description: 试卷试题
* @Author: jeecg-boot
@ -16,4 +20,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class PaperQuestionServiceImpl extends ServiceImpl<PaperQuestionMapper, PaperQuestion> implements IPaperQuestionService {
@Autowired
private PaperQuestionMapper paperQuestionMapper;
@Override
public List<PaperQuestion> getQuestions(String id) {
return paperQuestionMapper.selectList(new LambdaQueryWrapper<PaperQuestion>().eq(PaperQuestion::getPaperId, id));
}
}