|
@@ -478,6 +478,12 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
if (Objects.nonNull(o) && o instanceof BreachStatusBean) {
|
|
|
record.put(ExamRecordFieldEnum.breach_status.getCode(), ((BreachStatusBean) o).getStatus());
|
|
|
}
|
|
|
+ if (Objects.nonNull(o) && o instanceof WarningCountBean) {
|
|
|
+ record.put(ExamRecordFieldEnum.warning_count.getCode(), ((WarningCountBean) o).getNumber());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(o) && o instanceof WarningUnreadBean) {
|
|
|
+ record.put(ExamRecordFieldEnum.warning_unread.getCode(), ((WarningUnreadBean) o).getNumber());
|
|
|
+ }
|
|
|
er = GsonUtil.fromJson(GsonUtil.toJson(record), TOeExamRecord.class);
|
|
|
}
|
|
|
return er;
|
|
@@ -513,6 +519,17 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
this.baseMapper.updateWarningCount(id);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据id更新预警未读数量
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param number
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateWarningUnread(Long id, Integer number) {
|
|
|
+ this.baseMapper.updateWarningUnread(id, number);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新预警总数
|
|
|
*
|
|
@@ -520,47 +537,20 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
*/
|
|
|
@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)) {
|
|
|
- ExamRecordCacheUtil.setWarningCount(id, warningCount + 1);
|
|
|
- } else {
|
|
|
- ExamRecordCacheUtil.setWarningCount(id, 1);
|
|
|
- }
|
|
|
- Integer warningUnread = ExamRecordCacheUtil.getWarningUnread(id);
|
|
|
- if (Objects.nonNull(warningUnread)) {
|
|
|
- ExamRecordCacheUtil.setWarningUnread(id, warningUnread + 1);
|
|
|
- } 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();
|
|
|
- }
|
|
|
- }
|
|
|
+ Integer warningCount = ExamRecordCacheUtil.getWarningCount(id);
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ if (Objects.nonNull(warningCount)) {
|
|
|
+ ExamRecordCacheUtil.setWarningCount(id, warningCount + 1, timestamp);
|
|
|
+ } else {
|
|
|
+ ExamRecordCacheUtil.setWarningCount(id, 1, timestamp);
|
|
|
}
|
|
|
- if (!lock) {
|
|
|
- tgErrorService.saveExamTgError(id, "updateWarningCountCache");
|
|
|
+ Integer warningUnread = ExamRecordCacheUtil.getWarningUnread(id);
|
|
|
+ if (Objects.nonNull(warningUnread)) {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, warningUnread + 1, timestamp);
|
|
|
+ } else {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, 1, timestamp);
|
|
|
}
|
|
|
+ this.sendExamRecordDataUpdateWarningCountMq(id, System.currentTimeMillis());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -572,42 +562,16 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
@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) && warningUnread.intValue() == 0) {
|
|
|
- ExamRecordCacheUtil.setWarningUnread(id, number);
|
|
|
- } else if (Objects.nonNull(warningUnread) && warningUnread.intValue() > 0) {
|
|
|
- Integer warningCount = warningUnread - number;
|
|
|
- ExamRecordCacheUtil.setWarningUnread(id, warningCount.intValue() < 0 ? 0 : warningCount);
|
|
|
- }
|
|
|
- this.baseMapper.updateWarningUnread(id, number);
|
|
|
- } 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");
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ Integer warningUnread = ExamRecordCacheUtil.getWarningUnread(id);
|
|
|
+ if (Objects.nonNull(warningUnread) && warningUnread.intValue() == 0) {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, number, timestamp);
|
|
|
+ } else if (Objects.nonNull(warningUnread) && warningUnread.intValue() > 0) {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, warningUnread - number, timestamp);
|
|
|
+ } else {
|
|
|
+ ExamRecordCacheUtil.setWarningUnread(id, 0, timestamp);
|
|
|
}
|
|
|
+ this.sendExamRecordDataUpdateWarningUnreadMq(id, System.currentTimeMillis(), number);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -685,6 +649,27 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送mq更新考试预警未读数量
|
|
|
+ *
|
|
|
+ * @param recordId
|
|
|
+ * @param timestamp
|
|
|
+ * @param number
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void sendExamRecordDataUpdateWarningUnreadMq(Long recordId, Long timestamp, Integer number) {
|
|
|
+ try {
|
|
|
+ ExamRecordCacheUtil.setUpdateTime(recordId, timestamp);
|
|
|
+ Map<String, Object> properties = new HashMap<>();
|
|
|
+ properties.put(SystemConstant.NUMBER, number);
|
|
|
+ MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), SystemConstant.WARNING_UNREAD_UPDATE, timestamp);
|
|
|
+ mqDto.setProperties(properties);
|
|
|
+ mqDtoService.assembleSendAsyncMsg(mqDto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送mq更新考试记录
|
|
|
*
|