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