|
@@ -40,6 +40,7 @@ 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.helper.FaceBiopsyHelper;
|
|
|
+import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
import cn.com.qmth.examcloud.web.exception.SequenceLockException;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
@@ -65,6 +66,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLEncoder;
|
|
@@ -130,6 +132,9 @@ public class ExamControlServiceImpl implements ExamControlService {
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public StartExamInfo startExam(Long examStudentId, User user) {
|
|
|
+ //开考预处理
|
|
|
+ prepare4Exam(examStudentId, user);
|
|
|
+
|
|
|
Long studentId = user.getUserId();
|
|
|
long st = System.currentTimeMillis();
|
|
|
|
|
@@ -255,6 +260,164 @@ public class ExamControlServiceImpl implements ExamControlService {
|
|
|
return startExamInfo;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *开考预处理
|
|
|
+ *
|
|
|
+ * @param examStudentId
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ private void prepare4Exam(Long examStudentId,User user ) {
|
|
|
+
|
|
|
+ // 开始考试上锁,分布式锁,系统在请求结束后会,自动释放锁,无需手动解锁
|
|
|
+ String sequenceLockKey = Constants.EXAM_CONTROL_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(examStudentId);
|
|
|
+
|
|
|
+ if (null == examStudent) {
|
|
|
+ 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", "已经有考试中的科目");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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, 60);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|