|
@@ -1,19 +1,33 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.api.controller;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
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.enums.ExamSpecialSettingsType;
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.util.StringUtil;
|
|
|
import cn.com.qmth.examcloud.support.Constants;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamOrgSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.ExamStudentCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamStudentSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamBoss;
|
|
|
import cn.com.qmth.examcloud.support.examing.ExamingSession;
|
|
|
import cn.com.qmth.examcloud.support.examing.ExamingStatus;
|
|
|
+import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
@@ -35,8 +49,8 @@ public class ExamControlController extends ControllerSupport {
|
|
|
|
|
|
User user = getAccessUser();
|
|
|
|
|
|
- String sequenceLockKey = Constants.START_EXAM_LOCK_PREFIX + user.getUserId();
|
|
|
// 开始考试上锁,分布式锁,系统在请求结束后会,自动释放锁,无需手动解锁
|
|
|
+ String sequenceLockKey = Constants.START_EXAM_LOCK_PREFIX + user.getUserId();
|
|
|
SequenceLockHelper.getLock(sequenceLockKey);
|
|
|
|
|
|
SysPropertyCacheBean stuClientLoginLimit = CacheHelper
|
|
@@ -68,6 +82,121 @@ public class ExamControlController extends ControllerSupport {
|
|
|
throw new StatusException("008004", "已经有考试中的科目");
|
|
|
}
|
|
|
|
|
|
+ ExamSettingsCacheBean examSettingsCacheBean = ExamCacheTransferHelper
|
|
|
+ .getCachedExam(examStudent.getExamId(), examStudent.getStudentId());
|
|
|
+
|
|
|
+ StudentCacheBean studentCacheBean = CacheHelper.getStudent(examStudent.getStudentId());
|
|
|
+
|
|
|
+ CourseCacheBean courseCacheBean = CacheHelper.getCourse(examStudent.getCourseId());
|
|
|
+ if (!courseCacheBean.getEnable()) {
|
|
|
+ throw new StatusException("100020", "课程被禁用");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果启用了了特殊设置,并且无特殊设置时结束考试 配置 设置为true..且实际未设置特殊设置则不允许考试
|
|
|
+ ExamPropertyCacheBean limitedIfNoSpecialSettings = ExamCacheTransferHelper
|
|
|
+ .getDefaultCachedExamProperty(examSettingsCacheBean.getId(),
|
|
|
+ ExamProperties.LIMITED_IF_NO_SPECIAL_SETTINGS.toString());
|
|
|
+
|
|
|
+ if (examSettingsCacheBean.getSpecialSettingsEnabled()
|
|
|
+ && (limitedIfNoSpecialSettings.getHasValue()
|
|
|
+ && Boolean.valueOf(limitedIfNoSpecialSettings.getValue()))) {
|
|
|
+
|
|
|
+ // 学生特殊设置开启未配置,不允许考试
|
|
|
+ if (examSettingsCacheBean
|
|
|
+ .getSpecialSettingsType() == ExamSpecialSettingsType.STUDENT_BASED) {
|
|
|
+ ExamStudentSettingsCacheBean specialSettings = CacheHelper.getExamStudentSettings(
|
|
|
+ examSettingsCacheBean.getId(), examStudent.getStudentId());
|
|
|
+ if (!specialSettings.getHasValue()) {
|
|
|
+ throw new StatusException("100014", "考试配置未完成,不允许考试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 机构特殊设置开启未配置,不允许考试
|
|
|
+ if (examSettingsCacheBean
|
|
|
+ .getSpecialSettingsType() == ExamSpecialSettingsType.ORG_BASED) {
|
|
|
+ // 需求调整,所有的组织机构取学生表所关联的orgId
|
|
|
+ Long orgId = CacheHelper.getStudent(examStudent.getStudentId()).getOrgId();
|
|
|
+ ExamOrgSettingsCacheBean specialSettings = CacheHelper
|
|
|
+ .getExamOrgSettings(examSettingsCacheBean.getId(), orgId);
|
|
|
+ if (!specialSettings.getHasValue()) {
|
|
|
+ throw new StatusException("100015", "考试配置未完成,不允许考试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!examSettingsCacheBean.getEnable() || (examSettingsCacheBean.getExamLimit() != null
|
|
|
+ && examSettingsCacheBean.getExamLimit())) {
|
|
|
+ throw new StatusException("100016", "暂无考试资格,请与学校老师联系");
|
|
|
+ }
|
|
|
+ if (new Date().before(examSettingsCacheBean.getBeginTime())) {
|
|
|
+ throw new StatusException("100017", "考试未开始");
|
|
|
+ }
|
|
|
+ if (examSettingsCacheBean.getEndTime().before(new Date())) {
|
|
|
+ throw new StatusException("100018", "本次考试已结束");
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((!ExamType.ONLINE.name().equals(examSettingsCacheBean.getExamType()))
|
|
|
+ && (!ExamType.PRACTICE.name().equals(examSettingsCacheBean.getExamType()))) {
|
|
|
+ throw new StatusException("100019", "考试类型错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ int examTimes = examSettingsCacheBean.getExamTimes().intValue();
|
|
|
+ int usedNum = examStudent.getUsedNum();
|
|
|
+ int extraNum = examStudent.getExtraNum();
|
|
|
+
|
|
|
+ String examBossKey = RedisKeyHelper.getBuilder().examBossKey(examSettingsCacheBean.getId());
|
|
|
+ ExamBoss examBoss = redisClient.get(examBossKey, ExamBoss.class);
|
|
|
+
|
|
|
+ int asynchronousTimes = 0;
|
|
|
+ if (null != examBoss) {
|
|
|
+ asynchronousTimes = examBoss.getStartCount() - examBoss.getEndCount();
|
|
|
+ } else {
|
|
|
+ examBoss = new ExamBoss();
|
|
|
+ examBoss.setStartCount(0);
|
|
|
+ examBoss.setEndCount(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (examTimes + extraNum <= (usedNum + asynchronousTimes)) {
|
|
|
+ throw new StatusException("100021", "无剩余考试次数");
|
|
|
+ }
|
|
|
+
|
|
|
+ examingSession = new ExamingSession();
|
|
|
+ examingSession.setActiveTime(0L);
|
|
|
+ examingSession.setCost(0L);
|
|
|
+ examingSession.setCourseCode(courseCacheBean.getCode());
|
|
|
+ examingSession.setCourseId(courseCacheBean.getId());
|
|
|
+ examingSession.setCreationTime(new Date());
|
|
|
+ examingSession.setExamDuration((long) examSettingsCacheBean.getDuration());
|
|
|
+ examingSession.setExamId(examSettingsCacheBean.getId());
|
|
|
+ examingSession.setExamingStatus(ExamingStatus.INFORMAL);
|
|
|
+
|
|
|
+ ExamPropertyCacheBean examReconnectTime = ExamCacheTransferHelper
|
|
|
+ .getDefaultCachedExamProperty(examSettingsCacheBean.getId(),
|
|
|
+ ExamProperties.EXAM_RECONNECT_TIME.toString());
|
|
|
+ if (null == examReconnectTime || !examReconnectTime.getHasValue()) {
|
|
|
+ throw new StatusException("100022", "断点续考时间未配置");
|
|
|
+ }
|
|
|
+ examingSession.setExamReconnectTime(StringUtil.toInteger(examReconnectTime.getValue()));
|
|
|
+
|
|
|
+ examingSession.setExamRecordDataId(null);
|
|
|
+ examingSession.setExamStudentId(examStudent.getExamStudentId());
|
|
|
+ examingSession.setExamType(examSettingsCacheBean.getExamType());
|
|
|
+
|
|
|
+ ExamPropertyCacheBean freezeTime = ExamCacheTransferHelper.getDefaultCachedExamProperty(
|
|
|
+ examSettingsCacheBean.getId(), ExamProperties.FREEZE_TIME.toString());
|
|
|
+ if (null == freezeTime || !freezeTime.getHasValue()) {
|
|
|
+ throw new StatusException("100023", "交卷冻结时间未配置");
|
|
|
+ }
|
|
|
+ examingSession.setFreezeTime(StringUtil.toInteger(freezeTime.getValue()));
|
|
|
+ examingSession.setOrgId(studentCacheBean.getOrgId());
|
|
|
+ examingSession.setPaperType(examStudent.getPaperType());
|
|
|
+ examingSession.setRootOrgId(studentCacheBean.getRootOrgId());
|
|
|
+ examingSession.setStudentId(studentCacheBean.getId());
|
|
|
+
|
|
|
+ redisClient.set(examingSessionKey, examingSession, 10);
|
|
|
+ redisClient.set(examBossKey, examBoss);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|