|
@@ -1,26 +1,19 @@
|
|
|
package com.qmth.themis.mq.service.impl;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-
|
|
|
-import com.qmth.themis.business.enums.*;
|
|
|
-import com.qmth.themis.business.service.*;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.themis.business.cache.ExamRecordCacheUtil;
|
|
|
+import com.qmth.themis.business.cache.RedisKeyHelper;
|
|
|
import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.entity.TBSession;
|
|
|
import com.qmth.themis.business.entity.TMRocketMessage;
|
|
|
import com.qmth.themis.business.entity.TOeExamBreakHistory;
|
|
|
-import com.qmth.themis.business.entity.TOeExamRecord;
|
|
|
+import com.qmth.themis.business.enums.BreakReasonEnum;
|
|
|
+import com.qmth.themis.business.enums.FinishTypeEnum;
|
|
|
+import com.qmth.themis.business.enums.MqEnum;
|
|
|
+import com.qmth.themis.business.enums.SystemOperationEnum;
|
|
|
+import com.qmth.themis.business.service.*;
|
|
|
import com.qmth.themis.business.templete.TaskExportTemplete;
|
|
|
import com.qmth.themis.business.templete.TaskImportTemplete;
|
|
|
import com.qmth.themis.business.templete.impl.TaskExamPaperImportTemplete;
|
|
@@ -32,6 +25,12 @@ import com.qmth.themis.business.util.JacksonUtil;
|
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.mq.dto.MqDto;
|
|
|
import com.qmth.themis.mq.service.MqLogicService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: mq执行逻辑 impl
|
|
@@ -75,12 +74,10 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
|
|
|
@Resource
|
|
|
TOeLivenessVerifyHistoryService livenessVerifyHistoryService;
|
|
|
-
|
|
|
@Resource
|
|
|
TEExamService teExamService;
|
|
|
|
|
|
- /**
|
|
|
- * mq最大重试次数逻辑
|
|
|
+ /*** mq最大重试次数逻辑
|
|
|
*
|
|
|
* @param mqDto
|
|
|
* @param key
|
|
@@ -205,28 +202,51 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
Long updateTime = Long.parseLong(String.valueOf(tranMap.get("updateTime")));
|
|
|
Date date = new Date();
|
|
|
date.setTime(updateTime);
|
|
|
- TOeExamRecord tOeExamRecord = tOeExamRecordService.getById(recordId);
|
|
|
- Integer breakCount = tOeExamRecord.getLeftBreakResumeCount();
|
|
|
- if (Objects.isNull(breakCount) || breakCount <= 0) {
|
|
|
- tOeExamRecord.setStatus(ExamRecordStatusEnum.FINISHED);
|
|
|
- tOeExamRecordService.updateById(tOeExamRecord);
|
|
|
- teExamService.finish(tOeExamRecord.getExamStudentId(), tOeExamRecord.getId(), FinishTypeEnum.AUTO.name(), (int) (((System.currentTimeMillis() - tOeExamRecord.getClientLastSyncTime().getTime()) / 1000) + tOeExamRecord.getDurationSeconds()));
|
|
|
- } else {
|
|
|
- breakCount--;
|
|
|
- //增加断点记录
|
|
|
- TOeExamBreakHistory tOeExamBreakHistory = new TOeExamBreakHistory(recordId, new Date(), BreakReasonEnum.NET_TIME_OUT, BreakReasonEnum.NET_TIME_OUT.name());
|
|
|
- tOeExamBreakHistoryService.save(tOeExamBreakHistory);
|
|
|
- //更新考试记录状态
|
|
|
- tOeExamRecord.setClientCurrentIp(ip);
|
|
|
- tOeExamRecord.setClientWebsocketId(deviceId);
|
|
|
- tOeExamRecord.setClientWebsocketStatus(WebsocketStatusEnum.UN_ONLINE.ordinal());
|
|
|
- tOeExamRecord.setClientLastSyncTime(date);
|
|
|
- tOeExamRecord.setLastBreakId(tOeExamBreakHistory.getId());
|
|
|
- tOeExamRecord.setLastBreakTime(tOeExamBreakHistory.getBreakTime());
|
|
|
- tOeExamRecord.setLeftBreakResumeCount(breakCount);
|
|
|
- tOeExamRecord.setStatus(ExamRecordStatusEnum.bREAK_OFF);
|
|
|
- tOeExamRecordService.updateById(tOeExamRecord);
|
|
|
+// TOeExamRecord tOeExamRecord = tOeExamRecordService.getById(recordId);
|
|
|
+ Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
+// Integer breakCount = tOeExamRecord.getLeftBreakResumeCount();
|
|
|
+ Integer leftBreakResumeCount = ExamRecordCacheUtil.getLeftBreakResumeCount(recordId);
|
|
|
+ Long examId = Long.parseLong(String.valueOf(objectMap.get("examId")));
|
|
|
+ Long examStudentId = Long.parseLong(String.valueOf(objectMap.get("examStudentId")));
|
|
|
+ Integer durationSeconds = Integer.parseInt(String.valueOf(objectMap.get("durationSeconds")));
|
|
|
+// 获取考试缓存
|
|
|
+// ExamCacheBean ec = teExamService.getExamCacheBean(examId);
|
|
|
+ if (Objects.isNull(leftBreakResumeCount) || leftBreakResumeCount <= 0) {
|
|
|
+// tOeExamRecordService.updateById(tOeExamRecord);
|
|
|
+ teExamService.finish(examStudentId, recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
|
|
|
}
|
|
|
+// else {//否则断点次数减1
|
|
|
+// leftBreakResumeCount--;
|
|
|
+// //如果断点次数超过了考试整体断点次数,也强制交卷
|
|
|
+// if (leftBreakResumeCount > ec.getBreakResumeCount()) {
|
|
|
+// teExamService.finish(examStudentId, recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
|
|
|
+// } else {
|
|
|
+// //先查询之前的断点记录
|
|
|
+// QueryWrapper<TOeExamBreakHistory> tOeExamBreakHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
+// tOeExamBreakHistoryQueryWrapper.lambda().eq(TOeExamBreakHistory::getExamRecordId, recordId);
|
|
|
+// List<TOeExamBreakHistory> tOeExamBreakHistoryList = tOeExamBreakHistoryService.list(tOeExamBreakHistoryQueryWrapper);
|
|
|
+// //删除历史断点缓存
|
|
|
+// if (Objects.nonNull(tOeExamBreakHistoryList) && tOeExamBreakHistoryList.size() > 0) {
|
|
|
+// tOeExamBreakHistoryList.forEach(s -> {
|
|
|
+// redisUtil.delete(SystemConstant.EXAM_BREAK + String.valueOf(s.getId()));
|
|
|
+// });
|
|
|
+// }
|
|
|
+// //增加断点记录
|
|
|
+// TOeExamBreakHistory tOeExamBreakHistory = new TOeExamBreakHistory(recordId, new Date(), BreakReasonEnum.NET_TIME_OUT, BreakReasonEnum.NET_TIME_OUT.name());
|
|
|
+// tOeExamBreakHistoryService.save(tOeExamBreakHistory);
|
|
|
+// redisUtil.set(SystemConstant.EXAM_BREAK + String.valueOf(tOeExamBreakHistory.getId()), tOeExamBreakHistory);
|
|
|
+// //更新考试记录状态
|
|
|
+//// tOeExamRecord.setClientCurrentIp(ip);
|
|
|
+//// tOeExamRecord.setClientWebsocketId(deviceId);
|
|
|
+//// tOeExamRecord.setClientWebsocketStatus(WebsocketStatusEnum.UN_ONLINE.ordinal());
|
|
|
+//// tOeExamRecord.setClientLastSyncTime(date);
|
|
|
+//// tOeExamRecord.setLastBreakId(tOeExamBreakHistory.getId());
|
|
|
+//// tOeExamRecord.setLastBreakTime(tOeExamBreakHistory.getBreakTime());
|
|
|
+//// tOeExamRecord.setLeftBreakResumeCount(breakCount);
|
|
|
+//// tOeExamRecord.setStatus(ExamRecordStatusEnum.bREAK_OFF);
|
|
|
+// }
|
|
|
+//// tOeExamRecordService.updateById(tOeExamRecord);
|
|
|
+// }
|
|
|
}
|
|
|
teExamStudentLogService.saveStudentLogInfo(mqDto.getTimestamp(), MqEnum.valueOf(String.valueOf(mqDto.getType())).getId(), SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode(), JacksonUtil.parseJson(mqDto));
|
|
|
TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
|
|
@@ -259,6 +279,9 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
|
|
|
/**
|
|
|
* 人脸验证保存
|
|
|
+ *
|
|
|
+ * @param mqDto
|
|
|
+ * @param key
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
@@ -283,9 +306,13 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *活体验证
|
|
|
+ * 活体验证
|
|
|
+ *
|
|
|
+ * @param mqDto
|
|
|
+ * @param key
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void execMqLivenessVerifySaveLogic(MqDto mqDto, String key) {
|
|
|
Gson gson = new Gson();
|
|
|
Map<String, Object> param = (Map<String, Object>) mqDto.getBody();
|
|
@@ -304,11 +331,15 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
tmRocketMessageService.saveOrUpdate(tmRocketMessage);
|
|
|
redisUtil.delete(key, mqDto.getId());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- *考试记录数据持久化
|
|
|
+ * 考试记录数据持久化
|
|
|
+ *
|
|
|
+ * @param mqDto
|
|
|
+ * @param key
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void execMqExamRecordPersistedLogic(MqDto mqDto, String key) {
|
|
|
Gson gson = new Gson();
|
|
|
Map<String, Object> param = (Map<String, Object>) mqDto.getBody();
|
|
@@ -320,4 +351,44 @@ public class MqLogicServiceImpl implements MqLogicService {
|
|
|
tmRocketMessageService.saveOrUpdate(tmRocketMessage);
|
|
|
redisUtil.delete(key, mqDto.getId());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加考试断点记录
|
|
|
+ *
|
|
|
+ * @param mqDto
|
|
|
+ * @param key
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void execMqExamBreakHistoryLogic(MqDto mqDto, String key) {
|
|
|
+ //更新考试记录
|
|
|
+ Map<String, Object> objectMap = JacksonUtil.readJson(String.valueOf(mqDto.getBody()), Map.class);
|
|
|
+ Long recordId = Long.parseLong(mqDto.getObjId());
|
|
|
+
|
|
|
+ //先查询之前的断点记录
|
|
|
+ QueryWrapper<TOeExamBreakHistory> tOeExamBreakHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
+ tOeExamBreakHistoryQueryWrapper.lambda().eq(TOeExamBreakHistory::getExamRecordId, recordId);
|
|
|
+ List<TOeExamBreakHistory> tOeExamBreakHistoryList = tOeExamBreakHistoryService.list(tOeExamBreakHistoryQueryWrapper);
|
|
|
+ //删除历史断点缓存
|
|
|
+ if (Objects.nonNull(tOeExamBreakHistoryList) && tOeExamBreakHistoryList.size() > 0) {
|
|
|
+ tOeExamBreakHistoryList.forEach(s -> {
|
|
|
+ redisUtil.delete(SystemConstant.EXAM_BREAK + String.valueOf(s.getId()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //增加断点记录
|
|
|
+ TOeExamBreakHistory tOeExamBreakHistory = new TOeExamBreakHistory(recordId, new Date(), BreakReasonEnum.NET_TIME_OUT, BreakReasonEnum.NET_TIME_OUT.name());
|
|
|
+ tOeExamBreakHistoryService.save(tOeExamBreakHistory);
|
|
|
+ redisUtil.set(SystemConstant.EXAM_BREAK + String.valueOf(tOeExamBreakHistory.getId()), tOeExamBreakHistory);
|
|
|
+
|
|
|
+ objectMap.put("lastBreakId", tOeExamBreakHistory.getId());
|
|
|
+ redisUtil.setForHash(RedisKeyHelper.examRecordCacheKey(recordId), objectMap);
|
|
|
+
|
|
|
+ Gson gson = new Gson();
|
|
|
+ teExamStudentLogService.saveStudentLogInfo(mqDto.getTimestamp(), MqEnum.valueOf(String.valueOf(mqDto.getType())).getId(), SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode(), JacksonUtil.parseJson(mqDto));
|
|
|
+ mqDto.setAck(SystemConstant.STANDARD_ACK_TYPE);
|
|
|
+ TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
|
|
|
+ tmRocketMessage.setBody(JacksonUtil.parseJson(tmRocketMessage.getBody()));
|
|
|
+ tmRocketMessageService.saveOrUpdate(tmRocketMessage);
|
|
|
+ redisUtil.delete(key, mqDto.getId());
|
|
|
+ }
|
|
|
}
|