|
@@ -1,13 +1,22 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.api.controller;
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.support.Constants;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.ExamStudentCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamingSession;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamingStatus;
|
|
|
+import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
|
|
|
+import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -17,15 +26,46 @@ import io.swagger.annotations.ApiOperation;
|
|
|
@RequestMapping("${$rmp.ctr.oe}/examControl")
|
|
|
public class ExamControlController extends ControllerSupport {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
+
|
|
|
@ApiOperation(value = "准备考试")
|
|
|
@GetMapping("/prepare4Exam")
|
|
|
- public void startExam(@RequestParam Long studentId, @RequestParam Long examId,
|
|
|
- @RequestParam Long courseId) {
|
|
|
+ public void startExam(@RequestParam Long examStudentId) {
|
|
|
+
|
|
|
+ User user = getAccessUser();
|
|
|
+
|
|
|
+ String sequenceLockKey = Constants.START_EXAM_LOCK_PREFIX + user.getUserId();
|
|
|
+ // 开始考试上锁,分布式锁,系统在请求结束后会,自动释放锁,无需手动解锁
|
|
|
+ SequenceLockHelper.getLock(sequenceLockKey);
|
|
|
+
|
|
|
+ SysPropertyCacheBean stuClientLoginLimit = CacheHelper
|
|
|
+ .getSysProperty("STU_CLIENT_LOGIN_LIMIT");
|
|
|
+ Boolean stuClientLoginLimitBoolean = false;
|
|
|
+ if (stuClientLoginLimit.getHasValue()) {
|
|
|
+ stuClientLoginLimitBoolean = Boolean.valueOf(stuClientLoginLimit.getValue().toString());
|
|
|
+ }
|
|
|
+ if (stuClientLoginLimitBoolean) {
|
|
|
+ throw new StatusException("008001", "系统维护中... ...");
|
|
|
+ }
|
|
|
|
|
|
- ExamStudentCacheBean examStudent = CacheHelper.getExamStudent(studentId, examId, courseId);
|
|
|
+ ExamStudentCacheBean examStudent = CacheHelper.getExamStudent(examStudentId);
|
|
|
|
|
|
if (null == examStudent) {
|
|
|
- throw new StatusException("008001", "考生不存在");
|
|
|
+ throw new StatusException("008002", "考生不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!examStudent.getStudentId().equals(user.getUserId().longValue())) {
|
|
|
+ throw new StatusException("008003", "考生与当前用户不吻合");
|
|
|
+ }
|
|
|
+
|
|
|
+ String examingSessionKey = RedisKeyHelper.getBuilder().examingSessionKey(user.getUserId());
|
|
|
+
|
|
|
+ ExamingSession examingSession = redisClient.get(examingSessionKey, ExamingSession.class);
|
|
|
+
|
|
|
+ if (null != examingSession
|
|
|
+ && examingSession.getExamingStatus().equals(ExamingStatus.FORMAL)) {
|
|
|
+ throw new StatusException("008004", "已经有考试中的科目");
|
|
|
}
|
|
|
|
|
|
}
|