【删除线网测试数据推送逻辑】

This commit is contained in:
weizhihong 2023-07-25 16:51:59 +08:00
parent 7f21bb2281
commit 00c82d229e

View File

@ -1,9 +1,6 @@
package club.joylink.xiannccda.service; package club.joylink.xiannccda.service;
import club.joylink.xiannccda.ats.message.MessageData;
import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertorManager; import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertorManager;
import club.joylink.xiannccda.ats.message.collect.convertor.DeviceChangeStatusConvertor; import club.joylink.xiannccda.ats.message.collect.convertor.DeviceChangeStatusConvertor;
import club.joylink.xiannccda.ats.message.collect.convertor.DeviceInitConvertor; import club.joylink.xiannccda.ats.message.collect.convertor.DeviceInitConvertor;
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainInitConvertor; import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainInitConvertor;
@ -20,11 +17,6 @@ import club.joylink.xiannccda.ws.LineNetMessageServer;
import club.joylink.xiannccda.ws.LineTrainMessageServer; import club.joylink.xiannccda.ws.LineTrainMessageServer;
import club.joylink.xiannccda.ws.WsMessageServerManager; import club.joylink.xiannccda.ws.WsMessageServerManager;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -55,9 +47,6 @@ public class LineDeviceStatusService {
wsMessageServerManager.registerMessageServer(new LineNetMessageServer()); wsMessageServerManager.registerMessageServer(new LineNetMessageServer());
wsMessageServerManager.registerMessageServer(new LineTrainMessageServer()); wsMessageServerManager.registerMessageServer(new LineTrainMessageServer());
wsMessageServerManager.registerMessageServer(new LineDeviceMessageServer()); wsMessageServerManager.registerMessageServer(new LineDeviceMessageServer());
// 加载数据
refreshTestData();
} }
private void createDataConvertor() { private void createDataConvertor() {
@ -69,34 +58,4 @@ public class LineDeviceStatusService {
DeviceStatusConvertorManager.addStatusConvertor(new TrainRecordConvertor()); DeviceStatusConvertorManager.addStatusConvertor(new TrainRecordConvertor());
DeviceStatusConvertorManager.addStatusConvertor(new TrainUpdateConvertor()); DeviceStatusConvertorManager.addStatusConvertor(new TrainUpdateConvertor());
} }
public void refreshTestData() {
List<MessageData> allMockData = nccMockDataService.loadAllTrainInitData();
DeviceStatusConvertorManager.doConvertor(allMockData);
int frequency = 1500, stopTime = 30000;
AtomicLong id = new AtomicLong(0);
AtomicLong resetTimes = new AtomicLong(stopTime);
Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay(
() -> {
boolean isEmpty = true;
if (resetTimes.get() == stopTime) { // 代表还没有停顿不相等说明已经进入空循环
List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), 2);
DeviceStatusConvertorManager.doConvertor(updateMockData);
isEmpty = updateMockData.size() == 0;
}
if (isEmpty) { // 假数据已经用完了开始重复使用中间停顿30000ms
if (resetTimes.get() <= 0) {
id.set(0);
resetTimes.set(stopTime);
} else {
resetTimes.set(resetTimes.get() - frequency);
}
}
},
frequency,
frequency,
TimeUnit.MILLISECONDS);
}
} }