|
|
|
@ -29,15 +29,22 @@ public class ExamController {
|
|
|
|
|
|
|
|
|
|
@GetMapping("/question/all")
|
|
|
|
|
@ApiOperation("获取所有问题的列表")
|
|
|
|
|
ResultVO<List<QuestionVo>> getQuestionAll() {
|
|
|
|
|
// 获取全部问题列表
|
|
|
|
|
ResultVO<List<QuestionVo>> getQuestionAll() {
|
|
|
|
|
// 定义返回值
|
|
|
|
|
ResultVO<List<QuestionVo>> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService获取全部问题列表
|
|
|
|
|
List<QuestionVo> questionAll = examService.getQuestionAll();
|
|
|
|
|
// 返回成功结果
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取全部问题列表成功", questionAll);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回失败结果
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取全部问题列表失败", null);
|
|
|
|
|
}
|
|
|
|
|
// 返回结果
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -47,10 +54,14 @@ public class ExamController {
|
|
|
|
|
// 完成问题的更新
|
|
|
|
|
System.out.println(questionVo);
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的updateQuestion方法,更新问题
|
|
|
|
|
QuestionVo questionVoResult = examService.updateQuestion(questionVo);
|
|
|
|
|
// 返回更新成功的结果
|
|
|
|
|
return new ResultVO<>(0, "更新问题成功", questionVoResult);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回更新失败的结果
|
|
|
|
|
return new ResultVO<>(-1, "更新问题失败", null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -58,6 +69,7 @@ public class ExamController {
|
|
|
|
|
@PostMapping("/question/create")
|
|
|
|
|
@ApiOperation("创建问题")
|
|
|
|
|
ResultVO<String> questionCreate(@RequestBody QuestionCreateSimplifyVo questionCreateSimplifyVo, HttpServletRequest request) {
|
|
|
|
|
// 创建一个QuestionCreateVo对象
|
|
|
|
|
QuestionCreateVo questionCreateVo = new QuestionCreateVo();
|
|
|
|
|
// 把能拷贝过来的属性都拷贝过来
|
|
|
|
|
BeanUtils.copyProperties(questionCreateSimplifyVo, questionCreateVo);
|
|
|
|
@ -66,25 +78,33 @@ public class ExamController {
|
|
|
|
|
questionCreateVo.setQuestionCreatorId(userId);
|
|
|
|
|
System.out.println(questionCreateVo);
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的questionCreate方法创建问题
|
|
|
|
|
examService.questionCreate(questionCreateVo);
|
|
|
|
|
// 返回问题创建成功的ResultVO
|
|
|
|
|
return new ResultVO<>(0, "问题创建成功", null);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回创建问题失败的ResultVO
|
|
|
|
|
return new ResultVO<>(-1, "创建问题失败", null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/question/selection")
|
|
|
|
|
@ApiOperation("获取问题分类的相关选项")
|
|
|
|
|
ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
|
// 获取问题分类选项
|
|
|
|
|
ResultVO<QuestionSelectionVo> getSelections() {
|
|
|
|
|
// 调用examService的getSelections方法获取问题分类选项
|
|
|
|
|
QuestionSelectionVo questionSelectionVo = examService.getSelections();
|
|
|
|
|
// 如果获取成功
|
|
|
|
|
if (questionSelectionVo != null) {
|
|
|
|
|
// 返回成功的结果
|
|
|
|
|
return new ResultVO<>(0, "获取问题分类选项成功", questionSelectionVo);
|
|
|
|
|
} else {
|
|
|
|
|
// 否则返回失败的结果
|
|
|
|
|
return new ResultVO<>(-1, "获取问题分类选项失败", null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/question/detail/{id}")
|
|
|
|
|
@ApiOperation("根据问题的id获取问题的详细信息")
|
|
|
|
|
ResultVO<QuestionDetailVo> getQuestionDetail(@PathVariable String id) {
|
|
|
|
@ -92,58 +112,72 @@ public class ExamController {
|
|
|
|
|
System.out.println(id);
|
|
|
|
|
ResultVO<QuestionDetailVo> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的getQuestionDetail方法,根据问题id获取问题的详细信息
|
|
|
|
|
QuestionDetailVo questionDetailVo = examService.getQuestionDetail(id);
|
|
|
|
|
// 如果获取成功,则返回ResultVO对象,状态码为0,提示信息为"获取问题详情成功",数据为questionDetailVo
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取问题详情成功", questionDetailVo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 如果获取失败,则打印异常信息,并返回ResultVO对象,状态码为-1,提示信息为"获取问题详情失败",数据为null
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取问题详情失败", null);
|
|
|
|
|
}
|
|
|
|
|
// 返回ResultVO对象
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/all")
|
|
|
|
|
@ApiOperation("获取全部考试的列表")
|
|
|
|
|
ResultVO<List<ExamVo>> getExamAll() {
|
|
|
|
|
// 需要拼接前端需要的考试列表对象
|
|
|
|
|
ResultVO<List<ExamVo>> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的getExamAll方法获取全部考试的列表
|
|
|
|
|
List<ExamVo> examVos = examService.getExamAll();
|
|
|
|
|
// 将获取到的考试列表封装到ResultVO对象中,并返回
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取全部考试的列表成功", examVos);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 捕获异常,并打印异常信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 将异常信息封装到ResultVO对象中,并返回
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取全部考试的列表失败", null);
|
|
|
|
|
}
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/question/type/list")
|
|
|
|
|
@ApiOperation("获取问题列表,按照单选、多选和判断题分类返回")
|
|
|
|
|
ResultVO<ExamQuestionTypeVo> getExamQuestionTypeList() {
|
|
|
|
|
// 获取问题的分类列表
|
|
|
|
|
ResultVO<ExamQuestionTypeVo> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的getExamQuestionType方法获取问题分类列表
|
|
|
|
|
ExamQuestionTypeVo examQuestionTypeVo = examService.getExamQuestionType();
|
|
|
|
|
// 如果获取成功,则返回成功的结果
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取问题列表成功", examQuestionTypeVo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 如果获取失败,则打印异常信息,并返回失败的结果
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取问题列表失败", null);
|
|
|
|
|
}
|
|
|
|
|
// 返回结果
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
|
|
@ApiOperation("创建考试")
|
|
|
|
|
ResultVO<Exam> createExam(@RequestBody ExamCreateVo examCreateVo, HttpServletRequest request) {
|
|
|
|
|
// 从前端传参数过来,在这里完成考试的入库
|
|
|
|
|
ResultVO<Exam> resultVO;
|
|
|
|
|
// 获取当前用户的id
|
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的create方法,将examCreateVo和userId作为参数传入,创建考试
|
|
|
|
|
Exam exam = examService.create(examCreateVo, userId);
|
|
|
|
|
// 创建一个ResultVO对象,将创建成功的考试信息返回
|
|
|
|
|
resultVO = new ResultVO<>(0, "创建考试成功", exam);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 捕获异常,打印异常信息,并创建一个ResultVO对象,将创建失败的考试信息返回
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultVO = new ResultVO<>(-1, "创建考试失败", null);
|
|
|
|
|
}
|
|
|
|
|
// 返回ResultVO对象
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -152,12 +186,17 @@ public class ExamController {
|
|
|
|
|
ResultVO<Exam> updateExam(@RequestBody ExamVo examVo, HttpServletRequest request) {
|
|
|
|
|
// 从前端传参数过来,在这里完成考试的入库
|
|
|
|
|
ResultVO<Exam> resultVO;
|
|
|
|
|
// 获取当前用户id
|
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
|
try {
|
|
|
|
|
// 调用service层更新考试
|
|
|
|
|
Exam exam = examService.update(examVo, userId);
|
|
|
|
|
// 返回更新成功的resultVO
|
|
|
|
|
resultVO = new ResultVO<>(0, "更新考试成功", exam);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回更新失败的resultVO
|
|
|
|
|
resultVO = new ResultVO<>(-1, "更新考试失败", null);
|
|
|
|
|
}
|
|
|
|
|
return resultVO;
|
|
|
|
@ -169,12 +208,16 @@ public class ExamController {
|
|
|
|
|
// 获取考试列表卡片
|
|
|
|
|
ResultVO<List<ExamCardVo>> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService的getExamCardList方法获取考试列表卡片
|
|
|
|
|
List<ExamCardVo> examCardVoList = examService.getExamCardList();
|
|
|
|
|
// 如果获取成功,则返回成功的结果
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取考试列表卡片成功", examCardVoList);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 如果获取失败,则打印异常信息,并返回失败的结果
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取考试列表卡片失败", null);
|
|
|
|
|
}
|
|
|
|
|
// 返回结果
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -194,16 +237,20 @@ public class ExamController {
|
|
|
|
|
|
|
|
|
|
@PostMapping("/finish/{examId}")
|
|
|
|
|
@ApiOperation("根据用户提交的答案对指定id的考试判分")
|
|
|
|
|
// 完成考试
|
|
|
|
|
ResultVO<ExamRecord> finishExam(@PathVariable String examId, @RequestBody HashMap<String, List<String>> answersMap, HttpServletRequest request) {
|
|
|
|
|
// 定义返回结果
|
|
|
|
|
ResultVO<ExamRecord> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 拦截器里设置上的用户id
|
|
|
|
|
String userId = (String) request.getAttribute("user_id");
|
|
|
|
|
// 下面根据用户提交的信息进行判分,返回用户的得分情况
|
|
|
|
|
ExamRecord examRecord = examService.judge(userId, examId, answersMap);
|
|
|
|
|
// 返回结果
|
|
|
|
|
resultVO = new ResultVO<>(0, "考卷提交成功", examRecord);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回错误结果
|
|
|
|
|
resultVO = new ResultVO<>(-1, "考卷提交失败", null);
|
|
|
|
|
}
|
|
|
|
|
return resultVO;
|
|
|
|
@ -211,6 +258,7 @@ public class ExamController {
|
|
|
|
|
|
|
|
|
|
@GetMapping("/record/list")
|
|
|
|
|
@ApiOperation("获取当前用户的考试记录")
|
|
|
|
|
// 获取考试记录列表
|
|
|
|
|
ResultVO<List<ExamRecordVo>> getExamRecordList(HttpServletRequest request) {
|
|
|
|
|
ResultVO<List<ExamRecordVo>> resultVO;
|
|
|
|
|
try {
|
|
|
|
@ -229,14 +277,20 @@ public class ExamController {
|
|
|
|
|
@GetMapping("/record/detail/{recordId}")
|
|
|
|
|
@ApiOperation("根据考试记录id获取考试记录详情")
|
|
|
|
|
ResultVO<RecordDetailVo> getExamRecordDetail(@PathVariable String recordId) {
|
|
|
|
|
// 定义返回结果
|
|
|
|
|
ResultVO<RecordDetailVo> resultVO;
|
|
|
|
|
try {
|
|
|
|
|
// 调用examService获取考试记录详情
|
|
|
|
|
RecordDetailVo recordDetailVo = examService.getRecordDetail(recordId);
|
|
|
|
|
// 返回成功结果
|
|
|
|
|
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回失败结果
|
|
|
|
|
resultVO = new ResultVO<>(-1, "获取考试记录详情失败", null);
|
|
|
|
|
}
|
|
|
|
|
// 返回结果
|
|
|
|
|
return resultVO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|