Commit c30538f6 authored by duwei's avatar duwei

信号灯倒计时,加入下发控制,1秒1帧

parent 12a20911
......@@ -128,7 +128,7 @@ public class SignalStatusTask {
/**
* 消费孪生灯态kafka数据
*/
@KafkaListener(topics = {"WHSpatData"}, groupId = "utc-whspat-consumer-04")
@KafkaListener(topics = {"WHSpatData"}, groupId = "utc-whspat-consumer-05")
public void consumeTwinSpat(ConsumerRecord<Object, Object> record, Acknowledgment ack) {
try {
String lightStatusJson = String.valueOf(record.value());
......@@ -206,6 +206,10 @@ public class SignalStatusTask {
}
}
// 记录每个路口最后发送灯态的时间戳,单位毫秒
private static final Map<String, Long> lastSentTimestampMap = new ConcurrentHashMap<>();
/**
* 保存灯态数据并发送
*
......@@ -232,12 +236,25 @@ public class SignalStatusTask {
continue;
}
String json = mapper.writeValueAsString(listResult2);
// 新增:判断是否达到1秒间隔
long now = System.currentTimeMillis();
long lastSent = lastSentTimestampMap.getOrDefault(crossId, 0L);
if (now - lastSent < 1000) {
// 不足1秒,跳过本次推送
return;
}
for (Map.Entry<String, RealTimeDataWebSocket> socketEntry : value) {
String crossIdStr = socketEntry.getKey();
RealTimeDataWebSocket webSocket = socketEntry.getValue();
// 发送数据到websocket
webSocket.sendInfo(json, crossIdStr);
}
// 更新最后发送时间
lastSentTimestampMap.put(crossId, now);
insertIntoHist(crossId, json);
produceListMap.put(crossId, listResult2);
} catch (Exception e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment