|
|
@ -1,9 +1,6 @@
|
|
|
|
/***********************************************************
|
|
|
|
/**
|
|
|
|
* @Description : 考试服务
|
|
|
|
* @Description : 这是一个REST控制器,处理与考试、问题和考试记录相关的HTTP请求,它包括创建、更新和检索考试和问题的方法,以及处理用户提交和评分。
|
|
|
|
* @author : 梁山广(Laing Shan Guang)
|
|
|
|
*/
|
|
|
|
* @date : 2019-05-28 08:04
|
|
|
|
|
|
|
|
* @email : liangshanguang2@gmail.com
|
|
|
|
|
|
|
|
***********************************************************/
|
|
|
|
|
|
|
|
package lsgwr.exam.controller;
|
|
|
|
package lsgwr.exam.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import lsgwr.exam.entity.Exam;
|
|
|
|
import lsgwr.exam.entity.Exam;
|
|
|
@ -22,54 +19,58 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Api(tags = "Exam APIs")
|
|
|
|
@Api(tags = "Exam APIs")
|
|
|
|
|
|
|
|
//将此控制器中的所有端点映射到/api/exam URL路径
|
|
|
|
@RequestMapping("/api/exam")
|
|
|
|
@RequestMapping("/api/exam")
|
|
|
|
public class ExamController {
|
|
|
|
public class ExamController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired //注入一个ExamService实例,用于处理与考试和问题相关的业务逻辑
|
|
|
|
private ExamService examService;
|
|
|
|
private ExamService examService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.getQuestionAll()获取数据,并将其包装在ResultVO对象中,用于获取所有考试列表
|
|
|
|
|
|
|
|
* @ApiOperation注解用于描述API操作,它将显示在SwaggerUI中
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/question/all")
|
|
|
|
@GetMapping("/question/all")
|
|
|
|
@ApiOperation("获取所有问题的列表")
|
|
|
|
@ApiOperation("获取所有问题的列表")
|
|
|
|
// 获取全部问题列表
|
|
|
|
ResultVO<List<QuestionVo>> getQuestionAll() {
|
|
|
|
ResultVO<List<QuestionVo>> getQuestionAll() {
|
|
|
|
|
|
|
|
// 定义返回值
|
|
|
|
|
|
|
|
ResultVO<List<QuestionVo>> resultVO;
|
|
|
|
ResultVO<List<QuestionVo>> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService获取全部问题列表
|
|
|
|
|
|
|
|
List<QuestionVo> questionAll = examService.getQuestionAll();
|
|
|
|
List<QuestionVo> questionAll = examService.getQuestionAll();
|
|
|
|
// 返回成功结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取全部问题列表成功", questionAll);
|
|
|
|
resultVO = new ResultVO<>(0, "获取全部问题列表成功", questionAll);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 返回失败结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取全部问题列表失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "获取全部问题列表失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回结果
|
|
|
|
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 从请求体中获取一个QuestionVo对象,并使用examService.updateQuestion()更新问题
|
|
|
|
|
|
|
|
* @param questionVo 从请求体中获取的QuestionVo对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
@PostMapping("/question/update")
|
|
|
|
@PostMapping("/question/update")
|
|
|
|
@ApiOperation("更新问题")
|
|
|
|
@ApiOperation("更新问题")
|
|
|
|
ResultVO<QuestionVo> questionUpdate(@RequestBody QuestionVo questionVo) {
|
|
|
|
ResultVO<QuestionVo> questionUpdate(@RequestBody QuestionVo questionVo) {
|
|
|
|
// 完成问题的更新
|
|
|
|
// 完成问题的更新
|
|
|
|
System.out.println(questionVo);
|
|
|
|
System.out.println(questionVo);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的updateQuestion方法,更新问题
|
|
|
|
|
|
|
|
QuestionVo questionVoResult = examService.updateQuestion(questionVo);
|
|
|
|
QuestionVo questionVoResult = examService.updateQuestion(questionVo);
|
|
|
|
// 返回更新成功的结果
|
|
|
|
|
|
|
|
return new ResultVO<>(0, "更新问题成功", questionVoResult);
|
|
|
|
return new ResultVO<>(0, "更新问题成功", questionVoResult);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 返回更新失败的结果
|
|
|
|
|
|
|
|
return new ResultVO<>(-1, "更新问题失败", null);
|
|
|
|
return new ResultVO<>(-1, "更新问题失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 创建问题
|
|
|
|
|
|
|
|
* @Description: 从请求体中获取一个QuestionCreateSimplifyVo对象,将其属性复制到QuestionCreateVo,设置创建者的ID,并使用examService.questionCreate()创建问题。
|
|
|
|
|
|
|
|
* @param questionCreateSimplifyVo 从请求体中获取的QuestionCreateSimplifyVo对象
|
|
|
|
|
|
|
|
* @param request HttpServletRequest对象,用于获取当前用户的ID
|
|
|
|
|
|
|
|
* @return ResultVO<String> 对象,包含操作结果信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@PostMapping("/question/create")
|
|
|
|
@PostMapping("/question/create")
|
|
|
|
@ApiOperation("创建问题")
|
|
|
|
@ApiOperation("创建问题")
|
|
|
|
ResultVO<String> questionCreate(@RequestBody QuestionCreateSimplifyVo questionCreateSimplifyVo, HttpServletRequest request) {
|
|
|
|
ResultVO<String> questionCreate(@RequestBody QuestionCreateSimplifyVo questionCreateSimplifyVo, HttpServletRequest request) {
|
|
|
|
// 创建一个QuestionCreateVo对象
|
|
|
|
|
|
|
|
QuestionCreateVo questionCreateVo = new QuestionCreateVo();
|
|
|
|
QuestionCreateVo questionCreateVo = new QuestionCreateVo();
|
|
|
|
// 把能拷贝过来的属性都拷贝过来
|
|
|
|
// 把能拷贝过来的属性都拷贝过来
|
|
|
|
BeanUtils.copyProperties(questionCreateSimplifyVo, questionCreateVo);
|
|
|
|
BeanUtils.copyProperties(questionCreateSimplifyVo, questionCreateVo);
|
|
|
@ -78,33 +79,34 @@ ResultVO<List<QuestionVo>> getQuestionAll() {
|
|
|
|
questionCreateVo.setQuestionCreatorId(userId);
|
|
|
|
questionCreateVo.setQuestionCreatorId(userId);
|
|
|
|
System.out.println(questionCreateVo);
|
|
|
|
System.out.println(questionCreateVo);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的questionCreate方法创建问题
|
|
|
|
|
|
|
|
examService.questionCreate(questionCreateVo);
|
|
|
|
examService.questionCreate(questionCreateVo);
|
|
|
|
// 返回问题创建成功的ResultVO
|
|
|
|
|
|
|
|
return new ResultVO<>(0, "问题创建成功", null);
|
|
|
|
return new ResultVO<>(0, "问题创建成功", null);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 返回创建问题失败的ResultVO
|
|
|
|
|
|
|
|
return new ResultVO<>(-1, "创建问题失败", null);
|
|
|
|
return new ResultVO<>(-1, "创建问题失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 获取全部问题列表,使用examService.getSelections()获取数据,并将其包装在ResultVO对象中
|
|
|
|
|
|
|
|
* @return ResultVO<QuestionAllVo> 对象,包含问题列表
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/question/selection")
|
|
|
|
@GetMapping("/question/selection")
|
|
|
|
@ApiOperation("获取问题分类的相关选项")
|
|
|
|
@ApiOperation("获取问题分类的相关选项")
|
|
|
|
// 获取问题分类选项
|
|
|
|
ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
|
|
|
|
// 调用examService的getSelections方法获取问题分类选项
|
|
|
|
|
|
|
|
QuestionSelectionVo questionSelectionVo = examService.getSelections();
|
|
|
|
QuestionSelectionVo questionSelectionVo = examService.getSelections();
|
|
|
|
// 如果获取成功
|
|
|
|
|
|
|
|
if (questionSelectionVo != null) {
|
|
|
|
if (questionSelectionVo != null) {
|
|
|
|
// 返回成功的结果
|
|
|
|
|
|
|
|
return new ResultVO<>(0, "获取问题分类选项成功", questionSelectionVo);
|
|
|
|
return new ResultVO<>(0, "获取问题分类选项成功", questionSelectionVo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 否则返回失败的结果
|
|
|
|
|
|
|
|
return new ResultVO<>(-1, "获取问题分类选项失败", null);
|
|
|
|
return new ResultVO<>(-1, "获取问题分类选项失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.getQuestionDetail(id)获取数据,并将其包装在ResultVO对象中,用于获取全部问题列表
|
|
|
|
|
|
|
|
* @param id 问题id
|
|
|
|
|
|
|
|
* @return ResultVO<QuestionDetailVo> 对象,包含问题详情
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/question/detail/{id}")
|
|
|
|
@GetMapping("/question/detail/{id}")
|
|
|
|
@ApiOperation("根据问题的id获取问题的详细信息")
|
|
|
|
@ApiOperation("根据问题的id获取问题的详细信息")
|
|
|
|
ResultVO<QuestionDetailVo> getQuestionDetail(@PathVariable String id) {
|
|
|
|
ResultVO<QuestionDetailVo> getQuestionDetail(@PathVariable String id) {
|
|
|
@ -112,115 +114,121 @@ ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
System.out.println(id);
|
|
|
|
System.out.println(id);
|
|
|
|
ResultVO<QuestionDetailVo> resultVO;
|
|
|
|
ResultVO<QuestionDetailVo> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的getQuestionDetail方法,根据问题id获取问题的详细信息
|
|
|
|
|
|
|
|
QuestionDetailVo questionDetailVo = examService.getQuestionDetail(id);
|
|
|
|
QuestionDetailVo questionDetailVo = examService.getQuestionDetail(id);
|
|
|
|
// 如果获取成功,则返回ResultVO对象,状态码为0,提示信息为"获取问题详情成功",数据为questionDetailVo
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取问题详情成功", questionDetailVo);
|
|
|
|
resultVO = new ResultVO<>(0, "获取问题详情成功", questionDetailVo);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 如果获取失败,则打印异常信息,并返回ResultVO对象,状态码为-1,提示信息为"获取问题详情失败",数据为null
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
resultVO = new ResultVO<>(-1, "获取问题详情失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "获取问题详情失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回ResultVO对象
|
|
|
|
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.getExamAll()获取数据,并将其包装在ResultVO对象中,用于获取全部考试列表
|
|
|
|
|
|
|
|
* @return ResultVO<QuestionDetailVo> 对象,包含考试列表详情
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/all")
|
|
|
|
@GetMapping("/all")
|
|
|
|
@ApiOperation("获取全部考试的列表")
|
|
|
|
@ApiOperation("获取全部考试的列表")
|
|
|
|
ResultVO<List<ExamVo>> getExamAll() {
|
|
|
|
ResultVO<List<ExamVo>> getExamAll() {
|
|
|
|
// 需要拼接前端需要的考试列表对象
|
|
|
|
// 需要拼接前端需要的考试列表对象
|
|
|
|
ResultVO<List<ExamVo>> resultVO;
|
|
|
|
ResultVO<List<ExamVo>> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的getExamAll方法获取全部考试的列表
|
|
|
|
|
|
|
|
List<ExamVo> examVos = examService.getExamAll();
|
|
|
|
List<ExamVo> examVos = examService.getExamAll();
|
|
|
|
// 将获取到的考试列表封装到ResultVO对象中,并返回
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取全部考试的列表成功", examVos);
|
|
|
|
resultVO = new ResultVO<>(0, "获取全部考试的列表成功", examVos);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 捕获异常,并打印异常信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 将异常信息封装到ResultVO对象中,并返回
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取全部考试的列表失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "获取全部考试的列表失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.getExamQuestionTypeList()获取数据,并将其包装在ResultVO对象中,用于获取问题列表
|
|
|
|
|
|
|
|
* @return ResultVO<ExamQuestionTypeVo> 对象,包含问题列表
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/question/type/list")
|
|
|
|
@GetMapping("/question/type/list")
|
|
|
|
@ApiOperation("获取问题列表,按照单选、多选和判断题分类返回")
|
|
|
|
@ApiOperation("获取问题列表,按照单选、多选和判断题分类返回")
|
|
|
|
ResultVO<ExamQuestionTypeVo> getExamQuestionTypeList() {
|
|
|
|
ResultVO<ExamQuestionTypeVo> getExamQuestionTypeList() {
|
|
|
|
// 获取问题的分类列表
|
|
|
|
// 获取问题的分类列表
|
|
|
|
ResultVO<ExamQuestionTypeVo> resultVO;
|
|
|
|
ResultVO<ExamQuestionTypeVo> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的getExamQuestionType方法获取问题分类列表
|
|
|
|
|
|
|
|
ExamQuestionTypeVo examQuestionTypeVo = examService.getExamQuestionType();
|
|
|
|
ExamQuestionTypeVo examQuestionTypeVo = examService.getExamQuestionType();
|
|
|
|
// 如果获取成功,则返回成功的结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取问题列表成功", examQuestionTypeVo);
|
|
|
|
resultVO = new ResultVO<>(0, "获取问题列表成功", examQuestionTypeVo);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 如果获取失败,则打印异常信息,并返回失败的结果
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
resultVO = new ResultVO<>(-1, "获取问题列表失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "获取问题列表失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回结果
|
|
|
|
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.createExam()获取数据,并将其包装在ResultVO对象中,用于获取问题列表
|
|
|
|
|
|
|
|
* @param examCreateVo 前端传过来的参数
|
|
|
|
|
|
|
|
* @param request 获取用户id
|
|
|
|
|
|
|
|
* @return ResultVO<Exam> 对象,包含考试信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@PostMapping("/create")
|
|
|
|
@PostMapping("/create")
|
|
|
|
@ApiOperation("创建考试")
|
|
|
|
@ApiOperation("创建考试")
|
|
|
|
ResultVO<Exam> createExam(@RequestBody ExamCreateVo examCreateVo, HttpServletRequest request) {
|
|
|
|
ResultVO<Exam> createExam(@RequestBody ExamCreateVo examCreateVo, HttpServletRequest request) {
|
|
|
|
// 从前端传参数过来,在这里完成考试的入库
|
|
|
|
// 从前端传参数过来,在这里完成考试的入库
|
|
|
|
ResultVO<Exam> resultVO;
|
|
|
|
ResultVO<Exam> resultVO;
|
|
|
|
// 获取当前用户的id
|
|
|
|
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的create方法,将examCreateVo和userId作为参数传入,创建考试
|
|
|
|
|
|
|
|
Exam exam = examService.create(examCreateVo, userId);
|
|
|
|
Exam exam = examService.create(examCreateVo, userId);
|
|
|
|
// 创建一个ResultVO对象,将创建成功的考试信息返回
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "创建考试成功", exam);
|
|
|
|
resultVO = new ResultVO<>(0, "创建考试成功", exam);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 捕获异常,打印异常信息,并创建一个ResultVO对象,将创建失败的考试信息返回
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
resultVO = new ResultVO<>(-1, "创建考试失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "创建考试失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回ResultVO对象
|
|
|
|
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.updateExam()获取数据,并将其包装在ResultVO对象中,用于更新考试
|
|
|
|
|
|
|
|
* @param examVo 前端传过来的参数
|
|
|
|
|
|
|
|
* @param request 获取用户id
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
@PostMapping("/update")
|
|
|
|
@PostMapping("/update")
|
|
|
|
@ApiOperation("更新考试")
|
|
|
|
@ApiOperation("更新考试")
|
|
|
|
ResultVO<Exam> updateExam(@RequestBody ExamVo examVo, HttpServletRequest request) {
|
|
|
|
ResultVO<Exam> updateExam(@RequestBody ExamVo examVo, HttpServletRequest request) {
|
|
|
|
// 从前端传参数过来,在这里完成考试的入库
|
|
|
|
// 从前端传参数过来,在这里完成考试的入库
|
|
|
|
ResultVO<Exam> resultVO;
|
|
|
|
ResultVO<Exam> resultVO;
|
|
|
|
// 获取当前用户id
|
|
|
|
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用service层更新考试
|
|
|
|
|
|
|
|
Exam exam = examService.update(examVo, userId);
|
|
|
|
Exam exam = examService.update(examVo, userId);
|
|
|
|
// 返回更新成功的resultVO
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "更新考试成功", exam);
|
|
|
|
resultVO = new ResultVO<>(0, "更新考试成功", exam);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 返回更新失败的resultVO
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(-1, "更新考试失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "更新考试失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 获取考试列表,适配前端卡片列表
|
|
|
|
|
|
|
|
* @return ResultVO<List<ExamCardVo>> 对象,包含考试列表卡片信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/card/list")
|
|
|
|
@GetMapping("/card/list")
|
|
|
|
@ApiOperation("获取考试列表,适配前端卡片列表")
|
|
|
|
@ApiOperation("获取考试列表,适配前端卡片列表")
|
|
|
|
ResultVO<List<ExamCardVo>> getExamCardList() {
|
|
|
|
ResultVO<List<ExamCardVo>> getExamCardList() {
|
|
|
|
// 获取考试列表卡片
|
|
|
|
// 获取考试列表卡片
|
|
|
|
ResultVO<List<ExamCardVo>> resultVO;
|
|
|
|
ResultVO<List<ExamCardVo>> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService的getExamCardList方法获取考试列表卡片
|
|
|
|
|
|
|
|
List<ExamCardVo> examCardVoList = examService.getExamCardList();
|
|
|
|
List<ExamCardVo> examCardVoList = examService.getExamCardList();
|
|
|
|
// 如果获取成功,则返回成功的结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取考试列表卡片成功", examCardVoList);
|
|
|
|
resultVO = new ResultVO<>(0, "获取考试列表卡片成功", examCardVoList);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 如果获取失败,则打印异常信息,并返回失败的结果
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
resultVO = new ResultVO<>(-1, "获取考试列表卡片失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "获取考试列表卡片失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回结果
|
|
|
|
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 根据考试的id,获取考试详情
|
|
|
|
|
|
|
|
* @param id 考试id
|
|
|
|
|
|
|
|
* @return ResultVO<ExamDetailVo> 对象,包含考试详情信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/detail/{id}")
|
|
|
|
@GetMapping("/detail/{id}")
|
|
|
|
@ApiOperation("根据考试的id,获取考试详情")
|
|
|
|
@ApiOperation("根据考试的id,获取考试详情")
|
|
|
|
ResultVO<ExamDetailVo> getExamDetail(@PathVariable String id) {
|
|
|
|
ResultVO<ExamDetailVo> getExamDetail(@PathVariable String id) {
|
|
|
@ -235,30 +243,37 @@ ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.finishExam获取数据,并将其包装在ResultVO对象中,用于考试判分
|
|
|
|
|
|
|
|
* @param examId 考试id
|
|
|
|
|
|
|
|
* @param answersMap 用户提交的答案
|
|
|
|
|
|
|
|
* @param request 获取用户id
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
@PostMapping("/finish/{examId}")
|
|
|
|
@PostMapping("/finish/{examId}")
|
|
|
|
@ApiOperation("根据用户提交的答案对指定id的考试判分")
|
|
|
|
@ApiOperation("根据用户提交的答案对指定id的考试判分")
|
|
|
|
// 完成考试
|
|
|
|
|
|
|
|
ResultVO<ExamRecord> finishExam(@PathVariable String examId, @RequestBody HashMap<String, List<String>> answersMap, HttpServletRequest request) {
|
|
|
|
ResultVO<ExamRecord> finishExam(@PathVariable String examId, @RequestBody HashMap<String, List<String>> answersMap, HttpServletRequest request) {
|
|
|
|
// 定义返回结果
|
|
|
|
|
|
|
|
ResultVO<ExamRecord> resultVO;
|
|
|
|
ResultVO<ExamRecord> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 拦截器里设置上的用户id
|
|
|
|
// 拦截器里设置上的用户id
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
// 下面根据用户提交的信息进行判分,返回用户的得分情况
|
|
|
|
// 下面根据用户提交的信息进行判分,返回用户的得分情况
|
|
|
|
ExamRecord examRecord = examService.judge(userId, examId, answersMap);
|
|
|
|
ExamRecord examRecord = examService.judge(userId, examId, answersMap);
|
|
|
|
// 返回结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "考卷提交成功", examRecord);
|
|
|
|
resultVO = new ResultVO<>(0, "考卷提交成功", examRecord);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 返回错误结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(-1, "考卷提交失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "考卷提交失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.getExamRecordList获取数据,并将其包装在ResultVO对象中,用于获取当前用户的考试记录
|
|
|
|
|
|
|
|
* @param request 获取用户id
|
|
|
|
|
|
|
|
* @return ResultVO<List<ExamRecordVo>> 返回一个包含考试记录列表的ResultVO对象,如果发生异常,则返回一个包含错误信息的ResultVO对象。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/record/list")
|
|
|
|
@GetMapping("/record/list")
|
|
|
|
@ApiOperation("获取当前用户的考试记录")
|
|
|
|
@ApiOperation("获取当前用户的考试记录")
|
|
|
|
// 获取考试记录列表
|
|
|
|
|
|
|
|
ResultVO<List<ExamRecordVo>> getExamRecordList(HttpServletRequest request) {
|
|
|
|
ResultVO<List<ExamRecordVo>> getExamRecordList(HttpServletRequest request) {
|
|
|
|
ResultVO<List<ExamRecordVo>> resultVO;
|
|
|
|
ResultVO<List<ExamRecordVo>> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -274,23 +289,22 @@ ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Description: 使用examService.getExamRecordDetail获取数据,并将其包装在ResultVO对象中,用于获取指定id的考试记录详情
|
|
|
|
|
|
|
|
* @param recordId 考试记录id
|
|
|
|
|
|
|
|
* @return ResultVO<RecordDetailVo> 返回一个包含考试记录详情的ResultVO对象,如果发生异常,则返回一个包含错误信息的ResultVO对象。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/record/detail/{recordId}")
|
|
|
|
@GetMapping("/record/detail/{recordId}")
|
|
|
|
@ApiOperation("根据考试记录id获取考试记录详情")
|
|
|
|
@ApiOperation("根据考试记录id获取考试记录详情")
|
|
|
|
ResultVO<RecordDetailVo> getExamRecordDetail(@PathVariable String recordId) {
|
|
|
|
ResultVO<RecordDetailVo> getExamRecordDetail(@PathVariable String recordId) {
|
|
|
|
// 定义返回结果
|
|
|
|
|
|
|
|
ResultVO<RecordDetailVo> resultVO;
|
|
|
|
ResultVO<RecordDetailVo> resultVO;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 调用examService获取考试记录详情
|
|
|
|
|
|
|
|
RecordDetailVo recordDetailVo = examService.getRecordDetail(recordId);
|
|
|
|
RecordDetailVo recordDetailVo = examService.getRecordDetail(recordId);
|
|
|
|
// 返回成功结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);
|
|
|
|
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// 返回失败结果
|
|
|
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取考试记录详情失败", null);
|
|
|
|
resultVO = new ResultVO<>(-1, "获取考试记录详情失败", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回结果
|
|
|
|
|
|
|
|
return resultVO;
|
|
|
|
return resultVO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|