Bladeren bron

监考端接口

wangliang 4 jaren geleden
bovenliggende
commit
7633197b98
1 gewijzigde bestanden met toevoegingen van 32 en 13 verwijderingen
  1. 32 13
      themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

+ 32 - 13
themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

@@ -6,6 +6,7 @@ import com.google.gson.Gson;
 import com.qmth.themis.business.bean.exam.ExamStartParamBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.RedisKeyHelper;
+import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
@@ -83,6 +84,12 @@ public class MqLogicServiceImpl implements MqLogicService {
     @Resource
     TIeInvigilateExceptionInfoService tIeInvigilateExceptionInfoService;
 
+    @Resource
+    TEExamService teExamService;
+
+    @Resource
+    TEExamStudentService teExamStudentService;
+
     /**
      * mq最大重试次数逻辑
      *
@@ -427,15 +434,16 @@ public class MqLogicServiceImpl implements MqLogicService {
             tIeExamInvigilateCallService.saveOrUpdate(tIeExamInvigilateCall);
             tIeExamInvigilateCallLogService.saveOrUpdate(tIeExamInvigilateCallLog);
         } else if (tag.contains(MqTagEnum.EXCEPTION_LOG.name())) {//考试断点异常日志
-            ExamStartParamBean examStartParamBean = JacksonUtil.readJson(JacksonUtil.parseJson(mqDto.getBody()), ExamStartParamBean.class);
+            JSONObject jsonObject = JSONObject.parseObject(String.valueOf(mqDto.getBody()));
             //更新考试记录
             Long recordId = Long.parseLong(mqDto.getObjId());
             Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
             //获取最近断点时间
             Date lastBreakTime = (Date) objectMap.get("lastBreakTime");
-            Long diff = null;
+            Integer diff = null;
             if (Objects.nonNull(lastBreakTime)) {
-                diff = (System.currentTimeMillis() - lastBreakTime.getTime()) / 1000 * 60;
+                Long l = ((System.currentTimeMillis() - lastBreakTime.getTime()) / 1000 / 60);
+                diff = l.intValue();
             }
             //先查询之前的断点记录
             QueryWrapper<TOeExamBreakHistory> tOeExamBreakHistoryQueryWrapper = new QueryWrapper<>();
@@ -452,22 +460,33 @@ public class MqLogicServiceImpl implements MqLogicService {
             tOeExamBreakHistoryService.save(tOeExamBreakHistory);
             redisUtil.setForHash(RedisKeyHelper.examBreakCacheKey(tOeExamBreakHistory.getId()), SimpleBeanUtil.objectToMap(tOeExamBreakHistory));
 
+            Long examStudentId = Long.parseLong(String.valueOf(objectMap.get("examStudentId")));
             Integer leftBreakResumeCount = Objects.isNull(ExamRecordCacheUtil.getLeftBreakResumeCount(recordId)) ? 0 : ExamRecordCacheUtil.getLeftBreakResumeCount(recordId);
-            objectMap.put("lastBreakId", tOeExamBreakHistory.getId());
-            objectMap.put("status", ExamRecordStatusEnum.RESUME_PREPARE);
-            objectMap.put("lastBreakTime", new Date());
-            objectMap.put("leftBreakResumeCount", leftBreakResumeCount--);
-            objectMap.put("lastStartTime", new Date());
-            redisUtil.setForHash(RedisKeyHelper.examRecordCacheKey(recordId), objectMap);
+            leftBreakResumeCount--;
+            leftBreakResumeCount = leftBreakResumeCount <= 0 ? 0 : leftBreakResumeCount;
+            if (leftBreakResumeCount <= 0) {
+                Integer durationSeconds = null;
+                if (Objects.isNull(objectMap.get("durationSeconds"))) {
+                    durationSeconds = 0;
+                } else {
+                    durationSeconds = Integer.parseInt(String.valueOf(objectMap.get("durationSeconds")));
+                }
+                ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
+                teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+            } else {
+                objectMap.put("lastBreakId", tOeExamBreakHistory.getId());
+                objectMap.put("status", ExamRecordStatusEnum.RESUME_PREPARE);
+                objectMap.put("lastBreakTime", new Date());
+                objectMap.put("leftBreakResumeCount", leftBreakResumeCount);
+                objectMap.put("lastStartTime", new Date());
+                redisUtil.setForHash(RedisKeyHelper.examRecordCacheKey(recordId), objectMap);
+            }
 
             //增加异常日志
-            JSONObject jsonObject = (JSONObject) JSONObject.parse(examStartParamBean.getReason());
             Long examId = Long.parseLong(String.valueOf(objectMap.get("examId")));
-            Long examStudentId = Long.parseLong(String.valueOf(objectMap.get("examStudentId")));
             Long examActivityId = Long.parseLong(String.valueOf(objectMap.get("examActivityId")));
-            TIeInvigilateExceptionInfo tIeInvigilateExceptionInfo = new TIeInvigilateExceptionInfo(examId, examActivityId, recordId, examStudentId, String.valueOf(jsonObject.get("reason")), ExceptionEnum.valueOf(String.valueOf(jsonObject.get("type"))), String.valueOf(diff));
+            TIeInvigilateExceptionInfo tIeInvigilateExceptionInfo = new TIeInvigilateExceptionInfo(examId, examActivityId, recordId, examStudentId, String.valueOf(jsonObject.getJSONObject("reason").get("reason")), ExceptionEnum.valueOf(ExceptionEnum.convertToName(String.valueOf(jsonObject.getJSONObject("reason").get("type")))), String.valueOf(diff));
             tIeInvigilateExceptionInfoService.saveOrUpdate(tIeInvigilateExceptionInfo);
-            teExamStudentLogService.saveStudentLogInfo(mqDto.getTimestamp(), MqTagEnum.valueOf(String.valueOf(mqDto.getType())).getId(), SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode(), JacksonUtil.parseJson(mqDto));
         } else if (tag.contains(MqTagEnum.WARNING_LOG.name())) {//考试预警日志
 
         }