|
@@ -2,15 +2,16 @@ package com.qmth.themis.mq.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.themis.business.cache.ExamRecordCacheUtil;
|
|
|
import com.qmth.themis.business.cache.RedisKeyHelper;
|
|
|
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
|
|
|
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;
|
|
|
import com.qmth.themis.business.dto.WarningDto;
|
|
|
-import com.qmth.themis.business.dto.WebsocketDto;
|
|
|
import com.qmth.themis.business.entity.*;
|
|
|
import com.qmth.themis.business.enums.*;
|
|
|
import com.qmth.themis.business.service.*;
|
|
@@ -34,7 +35,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
|
* @Description: mq执行逻辑 impl
|
|
@@ -235,24 +235,47 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
Long l = (System.currentTimeMillis() - clientLastSyncTime.getTime()) / 1000;
|
|
|
if (l >= 2 && !Objects.equals(ExamRecordCacheUtil.getStatus(recordId), ExamRecordStatusEnum.FINISHED)) {
|
|
|
diff = l.intValue();
|
|
|
- //是否增加断点记录或者交卷处理统一放登录逻辑里处理,这里只更新考试记录状态为中断
|
|
|
ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.BREAK_OFF);
|
|
|
}
|
|
|
}
|
|
|
- //发送考试暂停mq消息 start
|
|
|
- MqDto mqDtoExamStop = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.EXAM_STOP.name(), recordId, MqTagEnum.EXAM_STOP, String.valueOf(recordId), String.valueOf(recordId));
|
|
|
- mqDtoService.assembleSendOneWayMsg(mqDtoExamStop);
|
|
|
- //发送考试暂停mq消息 end
|
|
|
-
|
|
|
- //增加异常日志
|
|
|
+ ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(recordId);
|
|
|
Long examId = ExamRecordCacheUtil.getExamId(recordId);
|
|
|
Long examActivityId = ExamRecordCacheUtil.getExamActivityId(recordId);
|
|
|
Long examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
|
|
|
ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
|
|
|
- TIeInvigilateExceptionInfo tIeInvigilateExceptionInfo = new TIeInvigilateExceptionInfo(examId, examActivityId, recordId, examStudentId, ExceptionEnum.NET_TIME_OUT.getCode(), ExceptionEnum.NET_TIME_OUT, diff);
|
|
|
- tIeInvigilateExceptionInfoService.saveOrUpdate(tIeInvigilateExceptionInfo);
|
|
|
- TEExamStudentLog teExamStudentLog = new TEExamStudentLog(SystemOperationEnum.BREAK_OFF.name(), SystemOperationEnum.BREAK_OFF.getCode(), SystemOperationEnum.BREAK_OFF.getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId);
|
|
|
- teExamStudentLogService.save(teExamStudentLog);
|
|
|
+ ExamCacheBean ec = teExamService.getExamCacheBean(examId);//考试缓存
|
|
|
+ Long breakId = null;
|
|
|
+ if (!Objects.equals(status, ExamRecordStatusEnum.FIRST_PREPARE)) {
|
|
|
+ //增加断点记录,获取剩余断点次数
|
|
|
+ Integer alreadyBreakCount = ExamRecordCacheUtil.getAlreadyBreakCount(recordId);
|
|
|
+ Integer leftBreakResumeCount = ec.getBreakResumeCount() - alreadyBreakCount;
|
|
|
+ leftBreakResumeCount = leftBreakResumeCount <= 0 ? 0 : leftBreakResumeCount;
|
|
|
+ if (leftBreakResumeCount <= 0) {
|
|
|
+ Integer durationSeconds = Objects.isNull(ExamRecordCacheUtil.getDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getDurationSeconds(recordId);
|
|
|
+ teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
|
|
|
+ } else {
|
|
|
+ alreadyBreakCount++;
|
|
|
+ breakId = Constants.idGen.next();
|
|
|
+ ExamRecordCacheUtil.setLastBreakId(recordId, breakId);
|
|
|
+ ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.BREAK_OFF);
|
|
|
+ ExamRecordCacheUtil.setLastBreakTime(recordId);
|
|
|
+ ExamRecordCacheUtil.setAlreadyBreakCount(recordId, alreadyBreakCount);
|
|
|
+ ExamRecordCacheUtil.setLastStartTime(recordId);
|
|
|
+ //考试断点异常原因 发送mq start
|
|
|
+ MqDto mqDtoBreak = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.EXAM_BREAK.name(), ExceptionEnum.NET_TIME_OUT, MqTagEnum.EXAM_BREAK, String.valueOf(recordId), String.valueOf(recordId));
|
|
|
+ mqDtoService.assembleSendOneWayMsg(mqDtoBreak);
|
|
|
+ //考试断点异常原因 发送mq end
|
|
|
+ }
|
|
|
+ //增加异常日志
|
|
|
+ TIeInvigilateExceptionInfo tIeInvigilateExceptionInfo = new TIeInvigilateExceptionInfo(examId, examActivityId, recordId, examStudentId, ExceptionEnum.NET_TIME_OUT.getCode(), ExceptionEnum.NET_TIME_OUT, diff);
|
|
|
+ tIeInvigilateExceptionInfoService.saveOrUpdate(tIeInvigilateExceptionInfo);
|
|
|
+ TEExamStudentLog teExamStudentLog = new TEExamStudentLog(SystemOperationEnum.BREAK_OFF.name(), SystemOperationEnum.BREAK_OFF.getCode(), SystemOperationEnum.BREAK_OFF.getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, breakId);
|
|
|
+ teExamStudentLogService.save(teExamStudentLog);
|
|
|
+ }
|
|
|
+ //发送移动端监考退出考试mq消息 start
|
|
|
+ MqDto mqDtoExamStop = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.EXAM_STOP.name(), recordId, MqTagEnum.EXAM_STOP, String.valueOf(recordId), String.valueOf(recordId));
|
|
|
+ mqDtoService.assembleSendOneWayMsg(mqDtoExamStop);
|
|
|
+ //发送移动端监考退出考试mq消息 end
|
|
|
}
|
|
|
TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
|
|
|
Map map = new HashMap();
|
|
@@ -481,25 +504,32 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(mqDto.getBody()));
|
|
|
ExceptionEnum exceptionEnum = ExceptionEnum.valueOf(ExceptionEnum.convertToName(String.valueOf(jsonObject.getJSONObject("reason").get("type"))));
|
|
|
Long recordId = Long.parseLong(mqDto.getObjId());
|
|
|
- //获取最近同步时间
|
|
|
- Date clientLastSyncTime = ExamRecordCacheUtil.getClientLastSyncTime(recordId);
|
|
|
- Integer diff = 0;
|
|
|
- if (Objects.nonNull(clientLastSyncTime)) {
|
|
|
- Long l = ((System.currentTimeMillis() - clientLastSyncTime.getTime()) / 1000);
|
|
|
- diff = l.intValue();
|
|
|
+ Long breakId = ExamRecordCacheUtil.getLastBreakId(recordId);
|
|
|
+ if (Objects.nonNull(breakId)) {
|
|
|
+ //获取断点时间
|
|
|
+ Date lastBreakTime = ExamRecordCacheUtil.getLastBreakTime(recordId);
|
|
|
+ Integer diff = 0;
|
|
|
+ if (Objects.nonNull(lastBreakTime)) {
|
|
|
+ Long l = ((System.currentTimeMillis() - lastBreakTime.getTime()) / 1000);
|
|
|
+ diff = l.intValue();
|
|
|
+ }
|
|
|
+ //修改异常日志
|
|
|
+ String reason = String.valueOf(jsonObject.getJSONObject("reason").get("reason"));
|
|
|
+ UpdateWrapper<TIeInvigilateExceptionInfo> tIeInvigilateExceptionInfoUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ tIeInvigilateExceptionInfoUpdateWrapper.lambda().set(TIeInvigilateExceptionInfo::getInfo, reason)
|
|
|
+ .set(TIeInvigilateExceptionInfo::getType, exceptionEnum)
|
|
|
+ .set(TIeInvigilateExceptionInfo::getDifference, diff)
|
|
|
+ .eq(TIeInvigilateExceptionInfo::getId, breakId);
|
|
|
+ tIeInvigilateExceptionInfoService.update(tIeInvigilateExceptionInfoUpdateWrapper);
|
|
|
+
|
|
|
+ //修改考生轨迹
|
|
|
+ UpdateWrapper<TEExamStudentLog> teExamStudentLogUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ teExamStudentLogUpdateWrapper.lambda().set(TEExamStudentLog::getType, exceptionEnum.name())
|
|
|
+ .set(TEExamStudentLog::getInfo, exceptionEnum.getCode())
|
|
|
+ .set(TEExamStudentLog::getRemark, reason)
|
|
|
+ .eq(TEExamStudentLog::getObjId, breakId);
|
|
|
+ teExamStudentLogService.update(teExamStudentLogUpdateWrapper);
|
|
|
}
|
|
|
- Long examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
|
|
|
- ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
|
|
|
-
|
|
|
- //增加异常日志
|
|
|
- Long examId = ExamRecordCacheUtil.getExamId(recordId);
|
|
|
- Long examActivityId = ExamRecordCacheUtil.getExamActivityId(recordId);
|
|
|
- String reason = String.valueOf(jsonObject.getJSONObject("reason").get("reason"));
|
|
|
- TIeInvigilateExceptionInfo tIeInvigilateExceptionInfo = new TIeInvigilateExceptionInfo(examId, examActivityId, recordId, examStudentId, reason, exceptionEnum, diff);
|
|
|
- tIeInvigilateExceptionInfoService.saveOrUpdate(tIeInvigilateExceptionInfo);
|
|
|
-
|
|
|
- TEExamStudentLog teExamStudentLog = new TEExamStudentLog(exceptionEnum.name(), exceptionEnum.getCode(), reason, examStudentCacheBean.getStudentId(), examStudentCacheBean.getId(), recordId);
|
|
|
- teExamStudentLogService.saveOrUpdate(teExamStudentLog);
|
|
|
} else if (tag.contains(MqTagEnum.WARNING_LOG.name())) {//考试预警日志
|
|
|
//todo 预警先预留
|
|
|
}
|
|
@@ -571,7 +601,7 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
}
|
|
|
//增加断点记录
|
|
|
TOeExamBreakHistory tOeExamBreakHistory = new TOeExamBreakHistory(ExamRecordCacheUtil.getLastBreakId(recordId), recordId, new Date(), exceptionEnum, exceptionEnum.name());
|
|
|
- tOeExamBreakHistoryService.save(tOeExamBreakHistory);
|
|
|
+ tOeExamBreakHistoryService.saveOrUpdate(tOeExamBreakHistory);
|
|
|
redisUtil.setForHash(RedisKeyHelper.examBreakCacheKey(tOeExamBreakHistory.getId()), SimpleBeanUtil.objectToMap(tOeExamBreakHistory));
|
|
|
|
|
|
Gson gson = new Gson();
|