xiatian 4 ani în urmă
părinte
comite
32203041b5

+ 41 - 16
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -63,6 +63,7 @@ import com.qmth.themis.business.entity.TBTaskHistory;
 import com.qmth.themis.business.entity.TEExam;
 import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.EntryAuthenticationPolicyEnum;
+import com.qmth.themis.business.enums.ExamModeEnum;
 import com.qmth.themis.business.enums.ExamRecordStatusEnum;
 import com.qmth.themis.business.enums.FinishExamResultEnum;
 import com.qmth.themis.business.enums.FinishTypeEnum;
@@ -251,20 +252,33 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (es.getLeftExamCount() == 0) {
             throw new BusinessException("没有剩余考试次数");
         }
+        ExamCacheBean exam = getExamCacheBean(es.getExamId());
         Long activityId = es.getExamActivityId();
         ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
         if (ac == null) {
             throw new BusinessException("未找到场次");
         }
         Date now = new Date();
-        Long start = ac.getStartTime().getTime() - (ac.getPrepareSeconds() * 1000);
-        Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
-        if (now.getTime() < start) {
-            throw new BusinessException("没有到允许开考的时间");
-        }
-        if (now.getTime() > end) {
-            throw new BusinessException("允许开考的时间已结束");
+        if(ExamModeEnum.ANYTIME.equals(exam.getMode())) {
+    		Long start = ac.getStartTime().getTime() - (ac.getPrepareSeconds() * 1000);
+    		Long end = ac.getFinishTime().getTime();
+    		if (now.getTime() < start) {
+    			throw new BusinessException("没有到允许开考的时间");
+    		}
+    		if (now.getTime() > end) {
+    			throw new BusinessException("允许开考的时间已结束");
+    		}
+        }else {
+            Long start = ac.getStartTime().getTime() - (ac.getPrepareSeconds() * 1000);
+            Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
+            if (now.getTime() < start) {
+                throw new BusinessException("没有到允许开考的时间");
+            }
+            if (now.getTime() > end) {
+                throw new BusinessException("允许开考的时间已结束");
+            }
         }
+        
         ExamCourseCacheBean ec = teExamCourseService.getExamCourseCacheBean(es.getExamId(), es.getCourseCode());
         if (ec == null) {
             throw new BusinessException("未找到考试科目");
@@ -316,7 +330,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         prepare.setMonitorUserId("s_" + tbSession.getId());
         prepare.setMonitorUserSig(tencentYunUtil.getSign(prepare.getMonitorUserId(), SystemConstant.TENCENT_EXPIRE_TIME));
 
-        ExamCacheBean exam = getExamCacheBean(es.getExamId());
+        
         Integer breakResumeCount = exam.getBreakResumeCount();
         // 更新考生缓存
         redisUtil.set(RedisKeyHelper.examStudentCacheKey(examStudentId), es);
@@ -368,20 +382,31 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (!studentId.equals(es.getStudentId())) {
             throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
         }
-
+        ExamCacheBean exam = getExamCacheBean(es.getExamId());
         Long activityId = es.getExamActivityId();
         ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
         if (ac == null) {
             throw new BusinessException("未找到场次");
         }
         Date now = new Date();
-        Long start = ac.getStartTime().getTime();
-        Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
-        if (now.getTime() < start) {
-            throw new BusinessException("没有到允许开考的时间");
-        }
-        if (now.getTime() > end) {
-            throw new BusinessException("允许开考的时间已结束");
+        if(ExamModeEnum.ANYTIME.equals(exam.getMode())) {
+    		Long start = ac.getStartTime().getTime();
+    		Long end = ac.getFinishTime().getTime();
+    		if (now.getTime() < start) {
+    			throw new BusinessException("没有到允许开考的时间");
+    		}
+    		if (now.getTime() > end) {
+    			throw new BusinessException("允许开考的时间已结束");
+    		}
+        }else {
+	        Long start = ac.getStartTime().getTime();
+	        Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
+	        if (now.getTime() < start) {
+	            throw new BusinessException("没有到允许开考的时间");
+	        }
+	        if (now.getTime() > end) {
+	            throw new BusinessException("允许开考的时间已结束");
+	        }
         }
         ExamRecordStatusEnum sta = ExamRecordCacheUtil.getStatus(recordId);
         if (ExamRecordStatusEnum.FINISHED.equals(sta) || ExamRecordStatusEnum.PERSISTED.equals(sta)) {

+ 18 - 13
themis-mq/src/main/java/com/qmth/themis/mq/templete/impl/ExamRecordPersistedConcurrentlyImpl.java

@@ -1,12 +1,11 @@
 package com.qmth.themis.mq.templete.impl;
 
-import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.dto.MqDto;
-import com.qmth.themis.business.util.JacksonUtil;
-import com.qmth.themis.business.util.RedisUtil;
-import com.qmth.themis.common.contanst.Constants;
-import com.qmth.themis.mq.service.MqLogicService;
-import com.qmth.themis.mq.templete.Concurrently;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.annotation.Resource;
+
 import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
 import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
 import org.apache.rocketmq.common.message.MessageExt;
@@ -14,9 +13,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.Resource;
-import java.util.List;
-import java.util.Objects;
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.dto.MqDto;
+import com.qmth.themis.business.util.RedisUtil;
+import com.qmth.themis.common.contanst.Constants;
+import com.qmth.themis.mq.service.MqLogicService;
+import com.qmth.themis.mq.templete.Concurrently;
 
 /**
  * 考试记录数据持久化
@@ -44,9 +47,11 @@ public class ExamRecordPersistedConcurrentlyImpl implements Concurrently {
             for (MessageExt messageExt : msgs) {
                 log.debug(":{}-:{} CalculateObjectiveScore 重试次数:{}", threadId, threadName,
                         messageExt.getReconsumeTimes());
-                mqDto = JacksonUtil.readJson(new String(messageExt.getBody(), Constants.CHARSET), MqDto.class);
-                log.debug(":{}-:{} CalculateObjectiveScore 接收到的消息:{}", threadId, threadName,
-                        JacksonUtil.parseJson(mqDto));
+                String body = new String(messageExt.getBody(), Constants.CHARSET_NAME);
+                log.debug("CalculateObjectiveScore 接收到的消息 body:{}", body);
+                JSONObject jsonObject = JSONObject.parseObject(body);
+                Map properties = (Map) jsonObject.get("properties");
+                mqDto = JSONObject.toJavaObject(JSONObject.parseObject(String.valueOf(properties.get(SystemConstant.MQDTO_OBJ))), MqDto.class);
                 int reconsumeTime = messageExt.getReconsumeTimes();
                 if (reconsumeTime >= SystemConstant.MAXRECONSUMETIMES) {
                     mqLogicService.execMqMaxReconsumeTime(mqDto, SystemConstant.MQ_TOPIC_BUFFER_LIST);