Browse Source

Merge remote-tracking branch 'origin/master'

lideyin 5 years ago
parent
commit
0c12deebbb

+ 11 - 196
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/ExamControlController.java

@@ -1,39 +1,15 @@
 package cn.com.qmth.examcloud.core.oe.admin.api.controller;
 
-import java.util.Date;
 import java.util.List;
 
 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.core.oe.admin.service.ExamStudentService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.OnHandExamInfo;
-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;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -44,178 +20,17 @@ import io.swagger.annotations.ApiOperation;
 public class ExamControlController extends ControllerSupport {
 
 	@Autowired
-	private RedisClient redisClient;
-	
-	@Autowired
-    private ExamStudentService examStudentService;
-	
-	
-	
-	@ApiOperation(value = "准备考试")
-	@GetMapping("/prepare4Exam")
-	public void prepare4Exam(@RequestParam Long examStudentId) {
-
+	private ExamStudentService examStudentService;
+
+	/**
+	 * 获取在线考试待考列表
+	 *
+	 * @return
+	 */
+	@ApiOperation(value = "获取在线考试待考列表")
+	@GetMapping("/queryExamList")
+	public List<OnHandExamInfo> queryExamList() {
 		User user = getAccessUser();
-
-		// 开始考试上锁,分布式锁,系统在请求结束后会,自动释放锁,无需手动解锁
-		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);
-
+		return examStudentService.queryOnlineExamList(user.getUserId());
 	}
-	
-    /**
-     * 获取在线考试待考列表
-     *
-     * @return
-     */
-    @ApiOperation(value = "获取在线考试待考列表")
-    @GetMapping("/queryExamList")
-    public List<OnHandExamInfo> queryExamList() {
-        User user = getAccessUser();
-        return examStudentService.queryOnlineExamList(user.getUserId());
-    }
 }