From e209801521c13760fdf273ef88eb451b3f6e6758 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 25 Jul 2023 11:12:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E5=88=97=E8=BD=A6=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=96=B9=E5=90=91=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BD=A6=E6=AC=A1=E5=8F=B7=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convertor/LineNetTrainComMethod.java | 41 ++++++++++++++----- .../convertor/LineNetTrainInitConvertor.java | 7 +++- .../LineNetTrainUpdateConvertor.java | 7 +++- xian-ncc-da-message | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainComMethod.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainComMethod.java index da2e871..ec0a3ca 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainComMethod.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainComMethod.java @@ -15,6 +15,7 @@ import java.util.Objects; import java.util.Optional; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; /** 线网的列车数据,一些公共方法 */ @Slf4j @@ -67,31 +68,40 @@ public abstract class LineNetTrainComMethod { * 根据目的码确定方向,并确定公里标 * * @param obj 要设置的对象 + * @param globalId 车次号 * @param destinationCode 目的码 * @param type 设备类型 * @param name 设备名称 */ public static void setTrainDirectionAndKilometerCode( WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj, + String globalId, String destinationCode, DeviceType type, String name) { + TrainRunDirection direction = null; DeviceKilometer.Builder deviceKm = getDeviceKM(obj.getLineId(), type, name); - if (deviceKm == null) { - return; + if (deviceKm != null && StringUtils.isNoneEmpty(destinationCode)) { + DeviceKilometer.Builder destinationKm = getDirectionCodeKM(obj.getLineId(), destinationCode); + // 目的地最大公里标大于设备最大公里标,上行 + if (destinationKm != null) { + direction = + destinationKm.getMaxKilometer() > deviceKm.getMaxKilometer() + ? TrainRunDirection.UP + : TrainRunDirection.DOWN; + } } - DeviceKilometer.Builder destinationKm = getDirectionCodeKM(obj.getLineId(), destinationCode); - if (destinationKm == null) { - return; + // 如果目的码都没有确定方向,则使用车次确定方向 + if (direction == null && StringUtils.isNoneEmpty(globalId)) { + direction = TrainRunDirection.match(Integer.parseInt(globalId.substring(0, 1))); } - // 确定方向 - if (destinationKm.getMaxKilometer() > deviceKm.getMaxKilometer()) { // 目的地最大公里标大于设备最大公里标,上行 - obj.setDir(TrainRunDirection.UP.getDir()); - } else { - obj.setDir(TrainRunDirection.DOWN.getDir()); + if (direction != null) { + obj.setDir(direction.getDir()); } // 赋值公里标 - obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), deviceKm)); + if (deviceKm != null) { + obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), deviceKm)); + } } /** @@ -165,5 +175,14 @@ public abstract class LineNetTrainComMethod { public boolean isMatch(int dir) { return this.dir == dir; } + + public static TrainRunDirection match(int dir) { + for (TrainRunDirection t : TrainRunDirection.values()) { + if (dir == t.getDir()) { + return t; + } + } + return null; + } } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java index 5fad374..f4e3e93 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java @@ -3,7 +3,6 @@ package club.joylink.xiannccda.ats.message.collect.convertor; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor; - import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationInitResponse; import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationInitResponse.TrainCell; @@ -36,7 +35,11 @@ public class LineNetTrainInitConvertor extends DeviceStatusConvertor { offset.setTrainIndex(trainCell.getTrainIndex()); // 列车标示号,全线唯一 offset.setGroupId(trainCell.getGroupId()); // 车组号 LineNetTrainComMethod.setTrainDirectionAndKilometerCode( - offset, trainCell.getDestinationId(), trainCell.getDevType(), trainCell.getDevName()); + offset, + trainCell.getGlobalId(), + trainCell.getDestinationId(), + trainCell.getDevType(), + trainCell.getDevName()); offset.setShow(offset.getKilometerCode() != 0); buildList.add(offset); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java index 1a58744..db9f797 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java @@ -3,7 +3,6 @@ package club.joylink.xiannccda.ats.message.collect.convertor; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor; - import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse; import club.joylink.xiannccda.dto.protos.WsMessageProto; @@ -36,7 +35,11 @@ public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor { offset.setGroupId(response.getGroupId()); // 车组号 LineNetTrainComMethod.getDeviceStatusById(offset); // 合并老旧数据 LineNetTrainComMethod.setTrainDirectionAndKilometerCode( - offset, response.getDestinationId(), response.getDevType(), response.getDevName()); + offset, + response.getGlobalId(), + response.getDestinationId(), + response.getDevType(), + response.getDevName()); offset.setShow(offset.getKilometerCode() != 0); buildList.add(offset); } diff --git a/xian-ncc-da-message b/xian-ncc-da-message index b3b9885..c9a07e7 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit b3b9885e2784cdad86901303e0bb9abf28c35e10 +Subproject commit c9a07e75f06e8247d33f9e08c52d5045f1db2bc2 From 00c82d229ecb6c379492c9b37f2dcf506b03ebd5 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 25 Jul 2023 16:51:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E5=88=A0=E9=99=A4=E7=BA=BF?= =?UTF-8?q?=E7=BD=91=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/LineDeviceStatusService.java | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java index 231fe2f..6620aa1 100644 --- a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java +++ b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java @@ -1,9 +1,6 @@ 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.convertor.DeviceChangeStatusConvertor; import club.joylink.xiannccda.ats.message.collect.convertor.DeviceInitConvertor; 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.WsMessageServerManager; 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.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -55,9 +47,6 @@ public class LineDeviceStatusService { wsMessageServerManager.registerMessageServer(new LineNetMessageServer()); wsMessageServerManager.registerMessageServer(new LineTrainMessageServer()); wsMessageServerManager.registerMessageServer(new LineDeviceMessageServer()); - - // 加载数据 - refreshTestData(); } private void createDataConvertor() { @@ -69,34 +58,4 @@ public class LineDeviceStatusService { DeviceStatusConvertorManager.addStatusConvertor(new TrainRecordConvertor()); DeviceStatusConvertorManager.addStatusConvertor(new TrainUpdateConvertor()); } - - 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( - () -> { - boolean isEmpty = true; - if (resetTimes.get() == stopTime) { // 代表还没有停顿,不相等说明已经进入空循环 - List 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); - } }