Merge remote-tracking branch 'origin/master'

# Conflicts:
#	xian-ncc-da-message
This commit is contained in:
joylink_zhangsai 2023-06-30 17:55:00 +08:00
commit e5ff8453c6
5 changed files with 59 additions and 54 deletions

View File

@ -43,6 +43,7 @@ public class LineGraphicDataRepository {
*/ */
public static void putLineGraph(PublishedGi publishGi) { public static void putLineGraph(PublishedGi publishGi) {
try { try {
if (publishGi.getLineId() != null) {
LayoutGraphicsProto.RtssGraphicStorage storage = LayoutGraphicsProto.RtssGraphicStorage storage =
LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto()); LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto());
Map<String, Map<String, ? extends Builder>> lineDataMap = new HashMap<>(); Map<String, Map<String, ? extends Builder>> lineDataMap = new HashMap<>();
@ -53,6 +54,7 @@ public class LineGraphicDataRepository {
// 设置公里标 // 设置公里标
setUpKilometerCode(lineDataMap, storage); setUpKilometerCode(lineDataMap, storage);
lineGraphMap.put(publishGi.getLineId(), lineDataMap); lineGraphMap.put(publishGi.getLineId(), lineDataMap);
}
} catch (InvalidProtocolBufferException e) { } catch (InvalidProtocolBufferException e) {
log.error("反序列化信息失败", e); log.error("反序列化信息失败", e);
} }

View File

@ -25,9 +25,7 @@ import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /** 线路设备信息更新 */
* 线路设备信息更新
*/
@Slf4j @Slf4j
@Service @Service
public class LineDeviceStatusService { public class LineDeviceStatusService {
@ -73,17 +71,31 @@ public class LineDeviceStatusService {
public void refreshTestData() { public void refreshTestData() {
List<MessageData> allMockData = nccMockDataService.loadAllTrainInitData(); List<MessageData> allMockData = nccMockDataService.loadAllTrainInitData();
DeviceStatusConvertorManager.doConvertor(allMockData); DeviceStatusConvertorManager.doConvertor(allMockData);
int frequency = 1500, stopTime = 30000;
AtomicLong id = new AtomicLong(0); AtomicLong id = new AtomicLong(0);
AtomicLong resetTimes = new AtomicLong(stopTime);
Executors.newSingleThreadScheduledExecutor() Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay( .scheduleWithFixedDelay(
() -> { () -> {
boolean isEmpty = true;
if (resetTimes.get() == stopTime) { // 代表还没有停顿不相等说明已经进入空循环
int count = (int) (Math.random() * 12); int count = (int) (Math.random() * 12);
List<MessageData> updateMockData = List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count); nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count);
DeviceStatusConvertorManager.doConvertor(updateMockData); 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);
}
}
}, },
1500, frequency,
1500, frequency,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} }
} }

View File

@ -70,22 +70,21 @@ public class LineDeviceMessageServer implements IMessageServer {
@Override @Override
public List<TopicMessage> onTick() { public List<TopicMessage> onTick() {
if (this.lineIdSet.isEmpty()) { if (this.lineIdSet.isEmpty()) {
return null; return Collections.emptyList();
} }
List<TopicMessage> messages = Lists.newArrayList(); List<TopicMessage> messages = Lists.newArrayList();
for (String lineId : this.lineIdSet) { for (String lineId : this.lineIdSet) {
DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE); DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE);
if (!deviceDataSource.isStatusVOEmpty()) { String destination = this.createPlace("lineId", lineId);
if (deviceDataSource.isStatusVOEmpty()) {
messages.add(new TopicMessage(destination, null));
continue;
}
WsLineMessage.Builder msg = WsLineMessage.newBuilder(); WsLineMessage.Builder msg = WsLineMessage.newBuilder();
fillBuilderFunction((field) -> deviceDataSource.getStatusVOMap().get(field), msg); fillBuilderFunction((field) -> deviceDataSource.getStatusVOMap().get(field), msg);
DeviceStatusDataOperate.clearStatusVOMap(DeviceStatusDataRepository.getDeviceStatusData(lineId)); DeviceStatusDataOperate.clearStatusVOMap(DeviceStatusDataRepository.getDeviceStatusData(lineId));
String destination = this.createPlace("lineId", lineId);
messages.add(new TopicMessage(destination, msg.build().toByteArray())); messages.add(new TopicMessage(destination, msg.build().toByteArray()));
} }
}
if (CollectionUtils.isEmpty(messages)) {
return null;
}
return messages; return messages;
} }

View File

@ -53,13 +53,17 @@ public class LineTrainMessageServer implements IMessageServer {
@Override @Override
public List<TopicMessage> onTick() { public List<TopicMessage> onTick() {
if (this.lineIdSet.isEmpty()) { if (this.lineIdSet.isEmpty()) {
return null; return Collections.emptyList();
} }
List<TopicMessage> messages = Lists.newArrayList(); List<TopicMessage> messages = Lists.newArrayList();
for (String lineId : this.lineIdSet) { for (String lineId : this.lineIdSet) {
String destination = this.createPlace("lineId", lineId);
TrainDataSource trainInfoData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN); TrainDataSource trainInfoData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN);
if (CollectionUtils.isEmpty(trainInfoData.getAllTrain())) {
messages.add(new TopicMessage(destination, null));
continue;
}
WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder(); WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder();
if (!CollectionUtils.isEmpty(trainInfoData.getAllTrain())) {
for (TrainInfo.Builder trainInfo : trainInfoData.getAllTrain()) { for (TrainInfo.Builder trainInfo : trainInfoData.getAllTrain()) {
trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainBlock", "block"); trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainBlock", "block");
trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainRemove", "remove"); trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainRemove", "remove");
@ -67,23 +71,11 @@ public class LineTrainMessageServer implements IMessageServer {
trainInfoData.reput(trainInfo); trainInfoData.reput(trainInfo);
trainMessage.addTrainInfo(trainInfo); trainMessage.addTrainInfo(trainInfo);
} }
String destination = this.createPlace("lineId", lineId);
messages.add(new TopicMessage(destination, trainMessage.build().toByteArray())); messages.add(new TopicMessage(destination, trainMessage.build().toByteArray()));
} }
}
if (CollectionUtils.isEmpty(messages)) {
return null;
}
return messages; return messages;
} }
public static void main(String[] args) {
WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder();
trainMessage.addTrainInfo(TrainInfo.newBuilder());
Map<FieldDescriptor, Object> maper = trainMessage.getAllFields();
System.out.println(maper);
maper.forEach((k, v) -> {
System.out.println(k.getName());
});
}
} }

@ -1 +1 @@
Subproject commit a5229b090fd21a5f72cd437ccb9623257724cbed Subproject commit 269d2b054f463bec5abf0330dfdb5cd48f66a8f2