update finalize ykc offline fix baseline

This commit is contained in:
Guoqs
2026-03-21 11:15:33 +08:00
parent 4aafe089ff
commit b0cfcf40fa
4 changed files with 106 additions and 18 deletions

View File

@@ -64,19 +64,16 @@ public class HeartbeatRequestHandler extends AbstractYkcHandler {
String connectorStatus = BytesUtil.binary(connectorStatusByte, 16);
// log.info("桩号:{}, 枪号:{}, 枪状态:{}", pileSn, pileConnectorNum, connectorStatus);
// 优化:先构建并返回心跳应答,不阻塞心跳回复
// 先构建心跳应答,再同步刷新最后通信时间和连接映射,保证离线确认链路及时收敛
byte[] flag = Constants.zeroByteArray;
byte[] messageBody = Bytes.concat(pileSnByte, pileConnectorNumByte, flag);
byte[] response = getResult(ykcDataProtocol, messageBody);
// 优化所有其他操作Redis、数据库完全异步化不阻塞心跳回复
// 将 saveLastTimeAndCheckChannel 和 updateStatus 都改为异步执行
saveLastTimeAndCheckChannel(pileSn, channel);
// 数据库状态更新继续异步,避免把心跳回包链路拖长
CompletableFuture.runAsync(() -> {
try {
// 异步保存连接时间并检查通道Redis 操作)
saveLastTimeAndCheckChannel(pileSn, channel);
// 异步更新状态(数据库操作)
String frameType = BytesUtil.bcd2Str(ykcDataProtocol.getFrameType());
pileBasicInfoService.updateStatus(frameType, pileSn, pileConnectorNum, connectorStatus, null);
} catch (Exception e) {