Browse Source

Merge remote-tracking branch 'origin/dev' into dev

wangliang 4 years ago
parent
commit
07118eeee8

+ 13 - 3
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -35,6 +35,7 @@ import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentPaperStructCacheBean;
 import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.dao.TEExamMapper;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.dto.response.TEExamActivityDto;
 import com.qmth.themis.business.dto.response.TEExamDto;
 import com.qmth.themis.business.entity.TEExam;
@@ -150,19 +151,22 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     @Transactional
     @Override
     public ExamPrepareBean prepare(Long studentId, Long examStudentId) {
-        ExamPrepareBean ret = null;
         ExamStudentCacheBean es = null;
         es = (ExamStudentCacheBean) redisUtil.get(RedisKeyHelper.examStudentCacheKey(examStudentId));
         if (es == null) {
             es = teExamStudentService.getExamStudnetCacheBean(examStudentId);
         }
         if (es == null) {
-            throw new BusinessException("未找到考");
+            throw new BusinessException("未找到考");
         }
 
         if (!studentId.equals(es.getStudentId())) {
             throw new BusinessException("考生Id和当前登录用户不一致");
         }
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
+        if(teStudentCacheDto.getUnFinishedRecordId()!=null) {
+        	throw new BusinessException("有尚未完成的考试,不能再次开始候考");
+        }
         if (es.getLeftExamCount() == 0) {
             throw new BusinessException("没有剩余考试次数");
         }
@@ -232,7 +236,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         redisUtil.set(RedisKeyHelper.examStudentCacheKey(examStudentId), es);
         //更新场次-考试记录缓存
         ExamActivityRecordCacheUtil.setExamRecordStatus(activityId, recordId, ExamRecordCacheUtil.getStatus(recordId));
-        return ret;
+        teStudentCacheDto.setUnFinishedRecordId(recordId);
+        redisUtil.setStudent(studentId, teStudentCacheDto, null, null);
+        return prepare;
     }
 
     /**
@@ -586,6 +592,10 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.FINISHED);
         //更新场次-考试记录缓存
         ExamActivityRecordCacheUtil.setExamRecordStatus(es.getExamActivityId(), recordId, ExamRecordCacheUtil.getStatus(recordId));
+        //更新未完成考试记录id
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
+        teStudentCacheDto.setUnFinishedRecordId(null);
+        redisUtil.setStudent(studentId, teStudentCacheDto, null, null);
         return ret;
     }