Compare commits

..

3 Commits

@ -10,4 +10,9 @@
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="exam" options="-parameters" />
</option>
</component>
</project>

@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -8,114 +8,130 @@ package lsgwr.exam.controller;
import lsgwr.exam.entity.Exam;
import lsgwr.exam.entity.ExamRecord;
import lsgwr.exam.service.ExamService;
import lsgwr.exam.service.ExamService;//导入考试的一些包
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lsgwr.exam.vo.*;
import org.springframework.beans.BeanUtils;
import io.swagger.annotations.ApiOperation;//Swagger注解
import lsgwr.exam.vo.*;// 引入所有视图对象VO
import org.springframework.beans.BeanUtils;// Bean 属性拷贝工具类
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;//添加注解
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest;// HTTP 请求对象
import java.util.HashMap;
import java.util.List;
// 控制器注解,表示这是一个 RESTful 控制器
@RestController
@Api(tags = "Exam APIs")
@RequestMapping("/api/exam")
@Api(tags = "Exam APIs")// 为 Swagger 文档定义标签用于分组API接口
@RequestMapping("/api/exam")// 定义基础路径为 /api/exam 的请求映射
public class ExamController {
@Autowired
private ExamService examService;
private ExamService examService;// 自动注入 ExamService 服务
/**
*
*/
@GetMapping("/question/all")
@ApiOperation("获取所有问题的列表")
ResultVO<List<QuestionVo>> getQuestionAll() {
ResultVO<List<QuestionVo>> resultVO;
try {
List<QuestionVo> questionAll = examService.getQuestionAll();
resultVO = new ResultVO<>(0, "获取全部问题列表成功", questionAll);
List<QuestionVo> questionAll = examService.getQuestionAll();// 调用服务层获取所有问题
resultVO = new ResultVO<>(0, "获取全部问题列表成功", questionAll);// 返回成功结果
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取全部问题列表失败", null);
resultVO = new ResultVO<>(-1, "获取全部问题列表失败", null);// 返回失败结果
}
return resultVO;
}
/**
*
*/
@PostMapping("/question/update")
@ApiOperation("更新问题")
ResultVO<QuestionVo> questionUpdate(@RequestBody QuestionVo questionVo) {
// 完成问题的更新
System.out.println(questionVo);
System.out.println(questionVo);// 打印接收到的问题信息以供调试
try {
QuestionVo questionVoResult = examService.updateQuestion(questionVo);
return new ResultVO<>(0, "更新问题成功", questionVoResult);
QuestionVo questionVoResult = examService.updateQuestion(questionVo);// 调用服务层更新问题
return new ResultVO<>(0, "更新问题成功", questionVoResult);// 返回成功结果
} catch (Exception e) {
e.printStackTrace();
return new ResultVO<>(-1, "更新问题失败", null);
return new ResultVO<>(-1, "更新问题失败", null);// 返回失败结果
}
}
/**
*
*/
@PostMapping("/question/create")
@ApiOperation("创建问题")
ResultVO<String> questionCreate(@RequestBody QuestionCreateSimplifyVo questionCreateSimplifyVo, HttpServletRequest request) {
QuestionCreateVo questionCreateVo = new QuestionCreateVo();
// 把能拷贝过来的属性都拷贝过来
BeanUtils.copyProperties(questionCreateSimplifyVo, questionCreateVo);
BeanUtils.copyProperties(questionCreateSimplifyVo, questionCreateVo);// 拷贝属性到新的对象
// 设置创建者信息
String userId = (String) request.getAttribute("user_id");
questionCreateVo.setQuestionCreatorId(userId);
String userId = (String) request.getAttribute("user_id");// 从请求中获取用户ID
questionCreateVo.setQuestionCreatorId(userId);// 设置创建者ID
System.out.println(questionCreateVo);
try {
examService.questionCreate(questionCreateVo);
return new ResultVO<>(0, "问题创建成功", null);
examService.questionCreate(questionCreateVo);// 调用服务层创建新问题
return new ResultVO<>(0, "问题创建成功", null);// 返回成功结果
} catch (Exception e) {
e.printStackTrace();
return new ResultVO<>(-1, "创建问题失败", null);
return new ResultVO<>(-1, "创建问题失败", null);// 返回失败结果
}
}
/**
*
*/
@GetMapping("/question/selection")
@ApiOperation("获取问题分类的相关选项")
ResultVO<QuestionSelectionVo> getSelections() {
QuestionSelectionVo questionSelectionVo = examService.getSelections();
if (questionSelectionVo != null) {
return new ResultVO<>(0, "获取问题分类选项成功", questionSelectionVo);
return new ResultVO<>(0, "获取问题分类选项成功", questionSelectionVo);// 成功返回分类选项
} else {
return new ResultVO<>(-1, "获取问题分类选项失败", null);
return new ResultVO<>(-1, "获取问题分类选项失败", null);// 分类选项为空时返回失败信息
}
}
/**
* ID
*/
@GetMapping("/question/detail/{id}")
@ApiOperation("根据问题的id获取问题的详细信息")
ResultVO<QuestionDetailVo> getQuestionDetail(@PathVariable String id) {
// 根据问题id获取问题的详细信息
System.out.println(id);
System.out.println(id);// 打印出请求的问题ID便于调试和日志记录
ResultVO<QuestionDetailVo> resultVO;
try {
QuestionDetailVo questionDetailVo = examService.getQuestionDetail(id);
resultVO = new ResultVO<>(0, "获取问题详情成功", questionDetailVo);
resultVO = new ResultVO<>(0, "获取问题详情成功", questionDetailVo);// 构造成功响应对象状态码为0表示成功
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取问题详情失败", null);
e.printStackTrace();// 打印异常堆栈以供调试
resultVO = new ResultVO<>(-1, "获取问题详情失败", null);// 构造失败响应对象,状态码为-1表示失败
}
return resultVO;
return resultVO;// 返回结果对象
}
/**
*
*/
@GetMapping("/all")
@ApiOperation("获取全部考试的列表")
ResultVO<List<ExamVo>> getExamAll() {
// 需要拼接前端需要的考试列表对象
// 需要拼接前端需要的考试列表对象s
ResultVO<List<ExamVo>> resultVO;
try {
List<ExamVo> examVos = examService.getExamAll();
resultVO = new ResultVO<>(0, "获取全部考试的列表成功", examVos);
List<ExamVo> examVos = examService.getExamAll(); // 调用服务层获取所有考试信息
resultVO = new ResultVO<>(0, "获取全部考试的列表成功", examVos);// 构造成功响应对象状态码为0表示成功
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取全部考试的列表失败", null);
e.printStackTrace();// 打印异常堆栈以供调试
resultVO = new ResultVO<>(-1, "获取全部考试的列表失败", null);// 构造失败响应对象,状态码为-1表示失败
}
return resultVO;
return resultVO;// 返回结果对象
}
/**
*
*
* @return ResultVO
*/
@GetMapping("/question/type/list")
@ApiOperation("获取问题列表,按照单选、多选和判断题分类返回")
ResultVO<ExamQuestionTypeVo> getExamQuestionTypeList() {
@ -130,7 +146,13 @@ public class ExamController {
}
return resultVO;
}
/**
*
*
* @param examCreateVo
* @param request HTTP ID
* @return Result VO
*/
@PostMapping("/create")
@ApiOperation("创建考试")
ResultVO<Exam> createExam(@RequestBody ExamCreateVo examCreateVo, HttpServletRequest request) {
@ -146,7 +168,13 @@ public class ExamController {
}
return resultVO;
}
/**
*
*
* @param examVo
* @param request HTTP ID
* @return
*/
@PostMapping("/update")
@ApiOperation("更新考试")
ResultVO<Exam> updateExam(@RequestBody ExamVo examVo, HttpServletRequest request) {
@ -162,7 +190,11 @@ public class ExamController {
}
return resultVO;
}
/**
*
*
* @return Resultsvo
*/
@GetMapping("/card/list")
@ApiOperation("获取考试列表,适配前端卡片列表")
ResultVO<List<ExamCardVo>> getExamCardList() {
@ -177,7 +209,12 @@ public class ExamController {
}
return resultVO;
}
/**
* ID
*
* @param id
* @return Resultsvo
*/
@GetMapping("/detail/{id}")
@ApiOperation("根据考试的id获取考试详情")
ResultVO<ExamDetailVo> getExamDetail(@PathVariable String id) {
@ -191,52 +228,71 @@ public class ExamController {
}
return resultVO;
}
/**
* &nbsp;&nbsp;*
*&nbsp;@param&nbsp;examId&nbsp; &nbsp;&nbsp;*
*&nbsp;@param&nbsp;answersMap &nbsp;&nbsp;*
*&nbsp;@param request ID HTTP &nbsp;&nbsp;&nbsp; *
*&nbsp;@return &nbsp;&nbsp;&nbsp; *
*/
@PostMapping("/finish/{examId}")
@ApiOperation("根据用户提交的答案对指定id的考试判分")
ResultVO<ExamRecord> finishExam(@PathVariable String examId, @RequestBody HashMap<String, List<String>> answersMap, HttpServletRequest request) {
ResultVO<ExamRecord> resultVO;
ResultVO<ExamRecord> resultVO;// 定义一个用于存放结果的数据结构
try {
// 拦截器里设置上的用户id
String userId = (String) request.getAttribute("user_id");
// 下面根据用户提交的信息进行判分,返回用户的得分情况
ExamRecord examRecord = examService.judge(userId, examId, answersMap);
resultVO = new ResultVO<>(0, "考卷提交成功", examRecord);
resultVO = new ResultVO<>(0, "考卷提交成功", examRecord);// 封装成绩记录到最终结果中
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "考卷提交失败", null);
}
return resultVO;
}
/**
* &nbsp;&nbsp;&nbsp; *
*&nbsp; &nbsp; *@ param request ID &nbsp;&nbsp;&nbsp; *
*&nbsp; &nbsp; *@ return Resultsvo &nbsp;&nbsp;&nbsp;&nbsp; *
*/
@GetMapping("/record/list")
@ApiOperation("获取当前用户的考试记录")
ResultVO<List<ExamRecordVo>> getExamRecordList(HttpServletRequest request) {
ResultVO<List<ExamRecordVo>> resultVO;
ResultVO<List<ExamRecordVo>> resultVO;//定义一个用于存放结果的数据结构
try {
// 拦截器里设置上的用户id
String userId = (String) request.getAttribute("user_id");
// 下面根据用户账号拿到他(她所有的考试信息)注意要用VO封装下
List<ExamRecordVo> examRecordVoList = examService.getExamRecordList(userId);
resultVO = new ResultVO<>(0, "获取考试记录成功", examRecordVoList);
resultVO = new ResultVO<>(0, "获取考试记录成功", examRecordVoList);//封装查询得到的信息到最终结果中;
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取考试记录失败", null);
}
return resultVO;
return resultVO;//返回封装好的 数据结构
}
/**
recordId
*@ param recordId
*@ return Resulsvolumne
*/
@GetMapping("/record/detail/{recordId}")
@ApiOperation("根据考试记录id获取考试记录详情")
ResultVO<RecordDetailVo> getExamRecordDetail(@PathVariable String recordId) {
ResultVO<RecordDetailVo> resultVO;
ResultVO<RecordDetailVo> resultVO;//定义一个用于存放结果的数据结构;
try {
RecordDetailVo recordDetailVo = examService.getRecordDetail(recordId);
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);//封装查询得到的信息到最终结果中;
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取考试记录详情失败", null);
}
return resultVO;
return resultVO;//返回封装好的 数据结构
}
}

Loading…
Cancel
Save