From e965a43c9414d0151e48321afed05d8e438976ee Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 30 Jun 2023 16:49:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E7=BA=BF?= =?UTF-8?q?=E7=BD=91=E6=95=B0=E6=8D=AE=E5=8F=91=E5=B8=83=E5=87=BA=E9=94=99?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ats/cache/LineGraphicDataRepository.java | 22 ++++++++++--------- xian-ncc-da-message | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java index 97ab534..9c6135d 100644 --- a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java @@ -43,16 +43,18 @@ public class LineGraphicDataRepository { */ public static void putLineGraph(PublishedGi publishGi) { try { - LayoutGraphicsProto.RtssGraphicStorage storage = - LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto()); - Map> lineDataMap = new HashMap<>(); - // 构建区段 - sectionInitLineGraph(lineDataMap, storage); - // 构建道岔 - switchInitLineGraph(lineDataMap, storage); - // 设置公里标 - setUpKilometerCode(lineDataMap, storage); - lineGraphMap.put(publishGi.getLineId(), lineDataMap); + if (publishGi.getLineId() != null) { + LayoutGraphicsProto.RtssGraphicStorage storage = + LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto()); + Map> lineDataMap = new HashMap<>(); + // 构建区段 + sectionInitLineGraph(lineDataMap, storage); + // 构建道岔 + switchInitLineGraph(lineDataMap, storage); + // 设置公里标 + setUpKilometerCode(lineDataMap, storage); + lineGraphMap.put(publishGi.getLineId(), lineDataMap); + } } catch (InvalidProtocolBufferException e) { log.error("反序列化信息失败", e); } diff --git a/xian-ncc-da-message b/xian-ncc-da-message index 2b9ad05..9a7b4b7 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit 2b9ad05b202b3b90c3f64b6b8c8a56ec83716f08 +Subproject commit 9a7b4b7a3a912970197155a149a9da463d2a68fc From 9cedb63b0ec40e08e651d7d677636f2d36992aa5 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Fri, 30 Jun 2023 17:14:23 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/ws/LineDeviceMessageServer.java | 19 +++++---- .../xiannccda/ws/LineTrainMessageServer.java | 40 ++++++++----------- xian-ncc-da-message | 2 +- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java index 404103a..8461490 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java @@ -70,21 +70,20 @@ public class LineDeviceMessageServer implements IMessageServer { @Override public List onTick() { if (this.lineIdSet.isEmpty()) { - return null; + return Collections.emptyList(); } List messages = Lists.newArrayList(); for (String lineId : this.lineIdSet) { DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE); - if (!deviceDataSource.isStatusVOEmpty()) { - WsLineMessage.Builder msg = WsLineMessage.newBuilder(); - fillBuilderFunction((field) -> deviceDataSource.getStatusVOMap().get(field), msg); - DeviceStatusDataOperate.clearStatusVOMap(DeviceStatusDataRepository.getDeviceStatusData(lineId)); - String destination = this.createPlace("lineId", lineId); - messages.add(new TopicMessage(destination, msg.build().toByteArray())); + String destination = this.createPlace("lineId", lineId); + if (deviceDataSource.isStatusVOEmpty()) { + messages.add(new TopicMessage(destination, null)); + continue; } - } - if (CollectionUtils.isEmpty(messages)) { - return null; + WsLineMessage.Builder msg = WsLineMessage.newBuilder(); + fillBuilderFunction((field) -> deviceDataSource.getStatusVOMap().get(field), msg); + DeviceStatusDataOperate.clearStatusVOMap(DeviceStatusDataRepository.getDeviceStatusData(lineId)); + messages.add(new TopicMessage(destination, msg.build().toByteArray())); } return messages; } diff --git a/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java index 8cd75c4..9d1f830 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java @@ -53,37 +53,29 @@ public class LineTrainMessageServer implements IMessageServer { @Override public List onTick() { if (this.lineIdSet.isEmpty()) { - return null; + return Collections.emptyList(); } List messages = Lists.newArrayList(); for (String lineId : this.lineIdSet) { + String destination = this.createPlace("lineId", lineId); TrainDataSource trainInfoData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN); - WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder(); - if (!CollectionUtils.isEmpty(trainInfoData.getAllTrain())) { - for (TrainInfo.Builder trainInfo : trainInfoData.getAllTrain()) { - trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainBlock", "block"); - trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainRemove", "remove"); - trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainRecord", "record"); - trainInfoData.reput(trainInfo); - trainMessage.addTrainInfo(trainInfo); - } - String destination = this.createPlace("lineId", lineId); - messages.add(new TopicMessage(destination, trainMessage.build().toByteArray())); + if (CollectionUtils.isEmpty(trainInfoData.getAllTrain())) { + messages.add(new TopicMessage(destination, null)); + continue; } - } - if (CollectionUtils.isEmpty(messages)) { - return null; + WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder(); + for (TrainInfo.Builder trainInfo : trainInfoData.getAllTrain()) { + trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainBlock", "block"); + trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainRemove", "remove"); + trainInfoData.fillBlockOrRecordOrRemove(trainInfo, "TrainRecord", "record"); + trainInfoData.reput(trainInfo); + trainMessage.addTrainInfo(trainInfo); + } + + messages.add(new TopicMessage(destination, trainMessage.build().toByteArray())); } return messages; } - public static void main(String[] args) { - WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder(); - trainMessage.addTrainInfo(TrainInfo.newBuilder()); - Map maper = trainMessage.getAllFields(); - System.out.println(maper); - maper.forEach((k, v) -> { - System.out.println(k.getName()); - }); - } + } diff --git a/xian-ncc-da-message b/xian-ncc-da-message index 9a7b4b7..549aa2e 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit 9a7b4b7a3a912970197155a149a9da463d2a68fc +Subproject commit 549aa2ec10bffe292a1a68e278ae824a8502db0b From 56b7a0d14e8ea20d677194fcf2e4f078e07a2a8f Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 30 Jun 2023 17:17:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E3=80=90=E7=BA=BF=E7=BD=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E9=A2=91=E7=8E=87?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/LineDeviceStatusService.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java index 8441c49..887df1c 100644 --- a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java +++ b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java @@ -25,9 +25,7 @@ import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -/** - * 线路设备信息更新 - */ +/** 线路设备信息更新 */ @Slf4j @Service public class LineDeviceStatusService { @@ -73,17 +71,31 @@ public class LineDeviceStatusService { public void refreshTestData() { List allMockData = nccMockDataService.loadAllTrainInitData(); DeviceStatusConvertorManager.doConvertor(allMockData); + int frequency = 1500, stopTime = 30000; AtomicLong id = new AtomicLong(0); + AtomicLong resetTimes = new AtomicLong(stopTime); Executors.newSingleThreadScheduledExecutor() .scheduleWithFixedDelay( () -> { - int count = (int) (Math.random() * 12); - List updateMockData = - nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count); - DeviceStatusConvertorManager.doConvertor(updateMockData); + boolean isEmpty = true; + if (resetTimes.get() == stopTime) { // 代表还没有停顿,不相等说明已经进入空循环 + int count = (int) (Math.random() * 12); + List updateMockData = + nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count); + 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, - 1500, + frequency, + frequency, TimeUnit.MILLISECONDS); } }