|
@@ -20,10 +20,7 @@ import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
|
|
import com.qmth.themis.business.dto.response.TEExamActivityDto;
|
|
import com.qmth.themis.business.dto.response.TEExamActivityDto;
|
|
import com.qmth.themis.business.dto.response.TEExamDto;
|
|
import com.qmth.themis.business.dto.response.TEExamDto;
|
|
import com.qmth.themis.business.dto.response.TEExamQueryDto;
|
|
import com.qmth.themis.business.dto.response.TEExamQueryDto;
|
|
-import com.qmth.themis.business.entity.TBSession;
|
|
|
|
-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.entity.*;
|
|
import com.qmth.themis.business.enums.*;
|
|
import com.qmth.themis.business.enums.*;
|
|
import com.qmth.themis.business.service.*;
|
|
import com.qmth.themis.business.service.*;
|
|
import com.qmth.themis.business.util.*;
|
|
import com.qmth.themis.business.util.*;
|
|
@@ -103,6 +100,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
|
|
@Resource
|
|
@Resource
|
|
MqUtil mqUtil;
|
|
MqUtil mqUtil;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ TGErrorService tgErrorService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询考试批次
|
|
* 查询考试批次
|
|
*
|
|
*
|
|
@@ -511,30 +511,47 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
|
|
ret.setPaperDecryptSecret(ep.getDecryptSecret());
|
|
ret.setPaperDecryptSecret(ep.getDecryptSecret());
|
|
ret.setPaperDecryptVector(ep.getDecryptVector());
|
|
ret.setPaperDecryptVector(ep.getDecryptVector());
|
|
|
|
|
|
- boolean lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId,
|
|
|
|
- SystemConstant.REDIS_LOCK_EXAM_STATUS_TIME_OUT);
|
|
|
|
- if (lock) {
|
|
|
|
- try {
|
|
|
|
- // 更新考试记录缓存
|
|
|
|
- Long firstStartTime = System.currentTimeMillis();
|
|
|
|
- ExamRecordCacheUtil.setFirstStartTime(recordId, firstStartTime, false);
|
|
|
|
- ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.ANSWERING, false);
|
|
|
|
- Long lastStartTime = System.currentTimeMillis();
|
|
|
|
- ExamRecordCacheUtil.setLastStartTime(recordId, lastStartTime, false);
|
|
|
|
- String[] columns = new String[]{ExamRecordFieldEnum.first_start_time.name(),
|
|
|
|
- ExamRecordFieldEnum.status.name(), ExamRecordFieldEnum.last_start_time.name()};
|
|
|
|
- Object[] values = new Object[]{firstStartTime, ExamRecordStatusEnum.ANSWERING, lastStartTime};
|
|
|
|
- toeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
|
- //更新场次-考试记录缓存
|
|
|
|
- ExamActivityRecordCacheUtil.setExamRecordStatus(activityId, recordId,
|
|
|
|
- new ExamActivityRecordCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId),
|
|
|
|
- ExamRecordCacheUtil.getStatus(recordId)));
|
|
|
|
- } finally {
|
|
|
|
- if (Objects.nonNull(recordId)) {
|
|
|
|
- redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId);
|
|
|
|
|
|
+ boolean lock = false;
|
|
|
|
+ for (int i = 0; i < SystemConstant.MAX_EXAM_STATUS_COUNT; i++) {
|
|
|
|
+ lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId,
|
|
|
|
+ SystemConstant.REDIS_LOCK_EXAM_STATUS_TIME_OUT);
|
|
|
|
+ if (lock) {
|
|
|
|
+ try {
|
|
|
|
+ // 更新考试记录缓存
|
|
|
|
+ Long firstStartTime = System.currentTimeMillis();
|
|
|
|
+ ExamRecordCacheUtil.setFirstStartTime(recordId, firstStartTime, false);
|
|
|
|
+ ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.ANSWERING, false);
|
|
|
|
+ Long lastStartTime = System.currentTimeMillis();
|
|
|
|
+ ExamRecordCacheUtil.setLastStartTime(recordId, lastStartTime, false);
|
|
|
|
+ String[] columns = new String[]{ExamRecordFieldEnum.first_start_time.name(),
|
|
|
|
+ ExamRecordFieldEnum.status.name(), ExamRecordFieldEnum.last_start_time.name()};
|
|
|
|
+ Object[] values = new Object[]{firstStartTime, ExamRecordStatusEnum.ANSWERING, lastStartTime};
|
|
|
|
+ toeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
|
+ //更新场次-考试记录缓存
|
|
|
|
+ ExamActivityRecordCacheUtil.setExamRecordStatus(activityId, recordId,
|
|
|
|
+ new ExamActivityRecordCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId),
|
|
|
|
+ ExamRecordCacheUtil.getStatus(recordId)));
|
|
|
|
+ break;
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(recordId)) {
|
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!lock) {
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("recordId", recordId);
|
|
|
|
+ jsonObject.put("method", "start");
|
|
|
|
+ jsonObject.put("examStatus", ExamRecordCacheUtil.getStatus(recordId));
|
|
|
|
+ TGError tgError = new TGError(jsonObject.toJSONString(), System.currentTimeMillis());
|
|
|
|
+ tgErrorService.save(tgError);
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -867,27 +884,44 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
|
|
ret.setAudioLeftPlayCount(audioLeftPlayCounts);
|
|
ret.setAudioLeftPlayCount(audioLeftPlayCounts);
|
|
}
|
|
}
|
|
|
|
|
|
- boolean lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId,
|
|
|
|
- SystemConstant.REDIS_LOCK_EXAM_STATUS_TIME_OUT);
|
|
|
|
- if (lock) {
|
|
|
|
- try {
|
|
|
|
- Long lastPrepareTime = System.currentTimeMillis();
|
|
|
|
- ExamRecordCacheUtil.setLastPrepareTime(recordId, lastPrepareTime, false);
|
|
|
|
- ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.RESUME_PREPARE, false);
|
|
|
|
- String[] columns = new String[]{ExamRecordFieldEnum.last_prepare_time.name(),
|
|
|
|
- ExamRecordFieldEnum.status.name()};
|
|
|
|
- Object[] values = new Object[]{lastPrepareTime, ExamRecordStatusEnum.RESUME_PREPARE};
|
|
|
|
- toeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
|
- //更新场次-考试记录缓存
|
|
|
|
- ExamActivityRecordCacheUtil.setExamRecordStatus(es.getExamActivityId(), recordId,
|
|
|
|
- new ExamActivityRecordCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId),
|
|
|
|
- ExamRecordCacheUtil.getStatus(recordId)));
|
|
|
|
- } finally {
|
|
|
|
- if (Objects.nonNull(recordId)) {
|
|
|
|
- redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId);
|
|
|
|
|
|
+ boolean lock = false;
|
|
|
|
+ for (int i = 0; i < SystemConstant.MAX_EXAM_STATUS_COUNT; i++) {
|
|
|
|
+ lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId,
|
|
|
|
+ SystemConstant.REDIS_LOCK_EXAM_STATUS_TIME_OUT);
|
|
|
|
+ if (lock) {
|
|
|
|
+ try {
|
|
|
|
+ Long lastPrepareTime = System.currentTimeMillis();
|
|
|
|
+ ExamRecordCacheUtil.setLastPrepareTime(recordId, lastPrepareTime, false);
|
|
|
|
+ ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.RESUME_PREPARE, false);
|
|
|
|
+ String[] columns = new String[]{ExamRecordFieldEnum.last_prepare_time.name(),
|
|
|
|
+ ExamRecordFieldEnum.status.name()};
|
|
|
|
+ Object[] values = new Object[]{lastPrepareTime, ExamRecordStatusEnum.RESUME_PREPARE};
|
|
|
|
+ toeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
|
+ //更新场次-考试记录缓存
|
|
|
|
+ ExamActivityRecordCacheUtil.setExamRecordStatus(es.getExamActivityId(), recordId,
|
|
|
|
+ new ExamActivityRecordCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId),
|
|
|
|
+ ExamRecordCacheUtil.getStatus(recordId)));
|
|
|
|
+ break;
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(recordId)) {
|
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!lock) {
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("recordId", recordId);
|
|
|
|
+ jsonObject.put("method", "resume");
|
|
|
|
+ jsonObject.put("examStatus", ExamRecordCacheUtil.getStatus(recordId));
|
|
|
|
+ TGError tgError = new TGError(jsonObject.toJSONString(), System.currentTimeMillis());
|
|
|
|
+ tgErrorService.save(tgError);
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
|
|
}
|
|
}
|
|
return ret;
|
|
return ret;
|
|
@@ -1029,31 +1063,48 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
|
|
} else {
|
|
} else {
|
|
ret.setStatus(FinishExamResultEnum.NORMAL);
|
|
ret.setStatus(FinishExamResultEnum.NORMAL);
|
|
}
|
|
}
|
|
- boolean lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId,
|
|
|
|
- SystemConstant.REDIS_LOCK_EXAM_STATUS_TIME_OUT);
|
|
|
|
- if (lock) {
|
|
|
|
- try {
|
|
|
|
- Long finishTime = System.currentTimeMillis();
|
|
|
|
- ExamRecordCacheUtil.setFinishTime(recordId, finishTime, false);
|
|
|
|
- ExamRecordCacheUtil.setDurationSeconds(recordId, durationSeconds, false);
|
|
|
|
- ExamRecordCacheUtil.setFinishType(recordId, FinishTypeEnum.valueOf(type), false);
|
|
|
|
- ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.FINISHED, false);
|
|
|
|
- String[] columns = new String[]{ExamRecordFieldEnum.finish_time.name(),
|
|
|
|
- ExamRecordFieldEnum.duration_seconds.name(), ExamRecordFieldEnum.finish_type.name(),
|
|
|
|
- ExamRecordFieldEnum.status.name()};
|
|
|
|
- Object[] values = new Object[]{finishTime, durationSeconds, FinishTypeEnum.valueOf(type),
|
|
|
|
- ExamRecordStatusEnum.FINISHED};
|
|
|
|
- toeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
|
- //更新场次-考试记录缓存
|
|
|
|
- ExamActivityRecordCacheUtil.setExamRecordStatus(es.getExamActivityId(), recordId,
|
|
|
|
- new ExamActivityRecordCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId),
|
|
|
|
- ExamRecordCacheUtil.getStatus(recordId)));
|
|
|
|
- } finally {
|
|
|
|
- if (Objects.nonNull(recordId)) {
|
|
|
|
- redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId);
|
|
|
|
|
|
+ boolean lock = false;
|
|
|
|
+ for (int i = 0; i < SystemConstant.MAX_EXAM_STATUS_COUNT; i++) {
|
|
|
|
+ lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId,
|
|
|
|
+ SystemConstant.REDIS_LOCK_EXAM_STATUS_TIME_OUT);
|
|
|
|
+ if (lock) {
|
|
|
|
+ try {
|
|
|
|
+ Long finishTime = System.currentTimeMillis();
|
|
|
|
+ ExamRecordCacheUtil.setFinishTime(recordId, finishTime, false);
|
|
|
|
+ ExamRecordCacheUtil.setDurationSeconds(recordId, durationSeconds, false);
|
|
|
|
+ ExamRecordCacheUtil.setFinishType(recordId, FinishTypeEnum.valueOf(type), false);
|
|
|
|
+ ExamRecordCacheUtil.setStatus(recordId, ExamRecordStatusEnum.FINISHED, false);
|
|
|
|
+ String[] columns = new String[]{ExamRecordFieldEnum.finish_time.name(),
|
|
|
|
+ ExamRecordFieldEnum.duration_seconds.name(), ExamRecordFieldEnum.finish_type.name(),
|
|
|
|
+ ExamRecordFieldEnum.status.name()};
|
|
|
|
+ Object[] values = new Object[]{finishTime, durationSeconds, FinishTypeEnum.valueOf(type),
|
|
|
|
+ ExamRecordStatusEnum.FINISHED};
|
|
|
|
+ toeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
|
+ //更新场次-考试记录缓存
|
|
|
|
+ ExamActivityRecordCacheUtil.setExamRecordStatus(es.getExamActivityId(), recordId,
|
|
|
|
+ new ExamActivityRecordCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId),
|
|
|
|
+ ExamRecordCacheUtil.getStatus(recordId)));
|
|
|
|
+ break;
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(recordId)) {
|
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_STATUS_PREFIX + recordId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!lock) {
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("recordId", recordId);
|
|
|
|
+ jsonObject.put("method", "diposeFinish");
|
|
|
|
+ jsonObject.put("examStatus", ExamRecordCacheUtil.getStatus(recordId));
|
|
|
|
+ TGError tgError = new TGError(jsonObject.toJSONString(), System.currentTimeMillis());
|
|
|
|
+ tgErrorService.save(tgError);
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
|
|
}
|
|
}
|
|
//更新未完成考试记录id
|
|
//更新未完成考试记录id
|