This commit is contained in:
2026-06-17 10:07:59 +08:00
parent a68a670ecb
commit caf4e2c415

View File

@@ -55,7 +55,9 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
@Autowired @Autowired
private WebsocketMesDispather websocketMesDispather; private WebsocketMesDispather websocketMesDispather;
private static final Long interval = 5000L; private static final Long recordInterval = 5000L; // 5秒记录一次
// private static final Long pushInterval = 500L; // 0.5秒推送一次
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
@@ -78,13 +80,11 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
} else { } else {
long lastRecordTime = recordDTO.getLastRecordTime(); long lastRecordTime = recordDTO.getLastRecordTime();
histories = recordDTO.getHistories(); histories = recordDTO.getHistories();
if (System.currentTimeMillis() - lastRecordTime >= interval) { if (System.currentTimeMillis() - lastRecordTime >= recordInterval) {
record = true; record = true;
} }
} }
if (record) {
// 推送websocket实时消息给前端 todo mqtt推送 // 推送websocket实时消息给前端 todo mqtt推送
String deviceStatus = new String(bytes, 2, bytes.length - 4, StandardCharsets.UTF_8).trim(); String deviceStatus = new String(bytes, 2, bytes.length - 4, StandardCharsets.UTF_8).trim();
String[] split = deviceStatus.split(","); String[] split = deviceStatus.split(",");
WebStatusMessageDTO dto = createWebDeviceStatusMessage(split); WebStatusMessageDTO dto = createWebDeviceStatusMessage(split);
@@ -102,6 +102,7 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(dto)); websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(dto));
}); });
} }
if (record) {
DeviceRunningStatusHistory deviceRunningStatus = getDeviceRunningStatusHistory(deviceID, split); DeviceRunningStatusHistory deviceRunningStatus = getDeviceRunningStatusHistory(deviceID, split);
if (histories == null) { if (histories == null) {
histories = new ArrayList<>(); histories = new ArrayList<>();