增加历史消息消费接口

This commit is contained in:
gaoyutao
2026-02-03 14:07:55 +08:00
parent 180986ba16
commit 180c522ca3
5 changed files with 926 additions and 17 deletions
@@ -115,8 +115,6 @@ public class MessageHandler {
@Autowired
private IRmAlarmLogService rmAlarmLogService;
@Autowired
private IRmAlarmPushConfigService rmAlarmPushConfigService;
@Autowired
private IRmFrpcConfigManageService rmFrpcConfigManageService;
@Autowired
private IRmPppoeConfigSubService rmPppoeConfigSubService;
@@ -740,9 +738,9 @@ public class MessageHandler {
// 尝试获取锁
locked = lock.tryLock(0, 20, TimeUnit.SECONDS);
if (locked) {
log.info("设备{}获取锁成功,开始处理消息", clientId);
// log.info("设备{}获取锁成功,开始处理消息", clientId);
processNetRecoverMessageInternal(message);
log.info("设备{}消息处理完成", clientId);
// log.info("设备{}消息处理完成", clientId);
} else {
log.warn("设备{}获取锁失败,消息处理繁忙", clientId);
throw new RuntimeException("设备处理繁忙,请重试");
@@ -755,7 +753,7 @@ public class MessageHandler {
if (locked && lock.isHeldByCurrentThread()) {
try {
lock.unlock();
log.debug("设备{}锁已释放", clientId);
// log.debug("设备{}锁已释放", clientId);
} catch (IllegalMonitorStateException e) {
log.warn("设备{}锁释放异常,可能已自动超时", clientId);
}
@@ -775,10 +773,6 @@ public class MessageHandler {
boolean lasttrafficFlag = interfaces.get(0).isLastTrafficFlag();
// 时间戳存储到redis
storeTimestampToRedis(clientId, timestamp);
if(lasttrafficFlag){
// 把redis中存储的时间戳提取出来,删除redis中的时间戳
processExitsTraffic(clientId);
}
long millis = timestamp * 1000;
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
String timeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",createTime);
@@ -790,13 +784,6 @@ public class MessageHandler {
countQuery.setStartTime(timeStr);
int exitsCount = initialBandwidthTrafficService.countByClientIdAndTime(countQuery);
// 即使数据已存在,也需要处理临时表逻辑,确保后续计算正确
if(exitsCount > 0){
// 不直接返回,继续执行临时表处理逻辑
// 但跳过最终的数据入库操作
System.out.println("数据已存在,跳过入库操作,但继续处理临时表逻辑");
}
// 创建比timestamp少5分钟的时间
long fiveMinutesEarlier = millis - (5 * 60 * 1000); // 减去5分钟的毫秒数
Date fiveMinutesEarlierDate = new Date(fiveMinutesEarlier / 1000 * 1000); // 同样去除毫秒
@@ -943,6 +930,10 @@ public class MessageHandler {
// 数据已存在时,只更新临时表,确保后续计算正确
initialBandwidthTrafficTempService.batchInsertServerRecoverTemp(interfaces);
}
if(lasttrafficFlag){
// 把redis中存储的时间戳提取出来,删除redis中的时间戳
processExitsTraffic(clientId);
}
} else {
throw new RuntimeException("NET流量data数据为空");
}