|
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
@@ -103,6 +104,9 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
@Resource
|
|
|
TSyncExamStudentScoreService tSyncExamStudentScoreService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TOeExamRecordService tOeExamRecordService;
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public Long saveByPrepare(Long examId, Long examActivityId, Long examStudentId, Long paperId,
|
|
@@ -499,6 +503,113 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
return this.getOne(tOeExamRecordQueryWrapper);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据id更新预警数量
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void updateWarningCount(Long id) {
|
|
|
+ this.baseMapper.updateWarningCount(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新预警总数
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateWarningCountCache(Long id) {
|
|
|
+ boolean lock = false;
|
|
|
+ for (int i = 0; i < SystemConstant.MAX_EXAM_STATUS_COUNT; i++) {
|
|
|
+ lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_WARN_COUNT_PREFIX + id, SystemConstant.REDIS_LOCK_EXAM_WARN_COUNT_TIME_OUT);
|
|
|
+ if (lock) {
|
|
|
+ try {
|
|
|
+ Integer warningCount = ExamRecordCacheUtil.getWarningCount(id);
|
|
|
+ if (Objects.nonNull(warningCount)) {
|
|
|
+ warningCount++;
|
|
|
+ ExamRecordCacheUtil.setWarningCount(id, warningCount);
|
|
|
+ } else {
|
|
|
+ ExamRecordCacheUtil.setWarningCount(id, 1);
|
|
|
+ }
|
|
|
+ Integer warningUnread = ExamRecordCacheUtil.getWarningUnread(id);
|
|
|
+ if (Objects.nonNull(warningUnread)) {
|
|
|
+ warningUnread++;
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, warningUnread);
|
|
|
+ } else {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, 1);
|
|
|
+ }
|
|
|
+ this.sendExamRecordDataUpdateWarningCountMq(id, System.currentTimeMillis());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof BusinessException) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(id)) {
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_WARN_COUNT_PREFIX + id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!lock) {
|
|
|
+ tgErrorService.saveExamTgError(id, "updateWarningCountCache");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新预警未读数
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param number
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void updateWarningUnreadCache(Long id, Integer number) {
|
|
|
+ boolean lock = false;
|
|
|
+ for (int i = 0; i < SystemConstant.MAX_EXAM_STATUS_COUNT; i++) {
|
|
|
+ lock = redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_WARN_UNREAD_PREFIX + id, SystemConstant.REDIS_LOCK_EXAM_WARN_UNREAD_TIME_OUT);
|
|
|
+ if (lock) {
|
|
|
+ try {
|
|
|
+ Integer warningUnread = ExamRecordCacheUtil.getWarningUnread(id);
|
|
|
+ if (Objects.nonNull(warningUnread)) {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, number);
|
|
|
+ }
|
|
|
+ tOeExamRecordService.update(new UpdateWrapper<TOeExamRecord>().lambda().eq(TOeExamRecord::getId, id).set(TOeExamRecord::getWarningUnread, 0));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof BusinessException) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(id)) {
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_WARN_UNREAD_PREFIX + id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!lock) {
|
|
|
+ tgErrorService.saveExamTgError(id, "updateWarningUnreadCache");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void saveFaceVerify(ExamTypeEnum type, Long recordId, Long entryAuthenticationId,
|
|
|
VerifyExceptionEnum entryAuthenticationResult) {
|
|
@@ -557,6 +668,23 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送mq更新考试预警数量记录
|
|
|
+ *
|
|
|
+ * @param recordId
|
|
|
+ * @param timestamp
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void sendExamRecordDataUpdateWarningCountMq(Long recordId, Long timestamp) {
|
|
|
+ try {
|
|
|
+ ExamRecordCacheUtil.setUpdateTime(recordId, timestamp);
|
|
|
+ MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), SystemConstant.WARNING_COUNT_UPDATE, timestamp);
|
|
|
+ mqDtoService.assembleSendAsyncMsg(mqDto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送mq更新考试记录
|
|
|
*
|