|
@@ -1,48 +1,78 @@
|
|
package com.qmth.themis.exam.api;
|
|
package com.qmth.themis.exam.api;
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.qmth.themis.business.bean.exam.ExamPrepareBean;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
|
|
+import com.qmth.themis.business.entity.TEStudent;
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
|
|
+import com.qmth.themis.business.util.RedisUtil;
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
-import io.swagger.annotations.*;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import com.qmth.themis.exam.util.ServletUtil;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
|
+import io.swagger.annotations.ApiResponse;
|
|
|
|
+import io.swagger.annotations.ApiResponses;
|
|
|
|
|
|
@Api(tags = "考试Controller")
|
|
@Api(tags = "考试Controller")
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/${prefix.url.exam}/exam")
|
|
@RequestMapping("/${prefix.url.exam}/exam")
|
|
public class TEExamController {
|
|
public class TEExamController {
|
|
|
|
|
|
- @Resource
|
|
|
|
- TEExamService teExamService;
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "验证考试口令接口")
|
|
|
|
- @RequestMapping(value = "/shortCode", method = RequestMethod.GET)
|
|
|
|
- @ApiResponses({@ApiResponse(code = 200, message = "考试信息", response = TEExam.class)})
|
|
|
|
- public Result shortCode(@ApiParam(value = "考试口令", required = true) @RequestParam String shortCode) {
|
|
|
|
- if (Objects.isNull(shortCode) || Objects.equals(shortCode, "")) {
|
|
|
|
- throw new BusinessException(ExceptionResultEnum.SHORT_CODE_IS_NULL);
|
|
|
|
- }
|
|
|
|
- QueryWrapper<TEExam> teExamQueryWrapper = new QueryWrapper<>();
|
|
|
|
- teExamQueryWrapper.lambda().eq(TEExam::getShortCode, shortCode);
|
|
|
|
- TEExam teExam = teExamService.getOne(teExamQueryWrapper);
|
|
|
|
- if (Objects.isNull(teExam)) {
|
|
|
|
- throw new BusinessException(ExceptionResultEnum.EXAM_NO);
|
|
|
|
- }
|
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- map.put(SystemConstant.ID, teExam.getId());
|
|
|
|
- map.put(SystemConstant.NAME, teExam.getName());
|
|
|
|
- return ResultUtil.ok(map);
|
|
|
|
- }
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ TEExamService teExamService;
|
|
|
|
+ @Resource
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "验证考试口令接口")
|
|
|
|
+ @RequestMapping(value = "/shortCode", method = RequestMethod.GET)
|
|
|
|
+ @ApiResponses({ @ApiResponse(code = 200, message = "考试信息", response = TEExam.class) })
|
|
|
|
+ public Result shortCode(@ApiParam(value = "考试口令", required = true) @RequestParam String shortCode) {
|
|
|
|
+ if (Objects.isNull(shortCode) || Objects.equals(shortCode, "")) {
|
|
|
|
+ throw new BusinessException(ExceptionResultEnum.SHORT_CODE_IS_NULL);
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<TEExam> teExamQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ teExamQueryWrapper.lambda().eq(TEExam::getShortCode, shortCode);
|
|
|
|
+ TEExam teExam = teExamService.getOne(teExamQueryWrapper);
|
|
|
|
+ if (Objects.isNull(teExam)) {
|
|
|
|
+ throw new BusinessException(ExceptionResultEnum.EXAM_NO);
|
|
|
|
+ }
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put(SystemConstant.ID, teExam.getId());
|
|
|
|
+ map.put(SystemConstant.NAME, teExam.getName());
|
|
|
|
+ return ResultUtil.ok(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "开始候考")
|
|
|
|
+ @RequestMapping(value = "/prepare", method = RequestMethod.POST)
|
|
|
|
+ @ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
|
|
|
|
+ public ExamPrepareBean prepare(@ApiParam(value = "考试场次ID", required = true) @RequestParam Long activityId) {
|
|
|
|
+ TEStudent teStudent = (TEStudent) ServletUtil.getRequestStudentAccount();
|
|
|
|
+ String lockKey=SystemConstant.REDIS_LOCK_STUDENT_PREFIX+teStudent.getId();
|
|
|
|
+ Boolean lock=redisUtil.lock(lockKey, SystemConstant.REDIS_CACHE_TIME_OUT);
|
|
|
|
+ if(!lock) {
|
|
|
|
+ throw new BusinessException(ExceptionResultEnum.REQUEST_AWAIT);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ return teExamService.prepare(teStudent.getId(), activityId);
|
|
|
|
+ } finally {
|
|
|
|
+ redisUtil.releaseLock(lockKey);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|