【列车运行方向判断逻辑增加车次号判断】

This commit is contained in:
weizhihong 2023-07-25 11:12:07 +08:00
parent 535d4dce08
commit e209801521
4 changed files with 41 additions and 16 deletions

View File

@ -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,32 +68,41 @@ 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) {
return;
// 目的地最大公里标大于设备最大公里标上行
if (destinationKm != null) {
direction =
destinationKm.getMaxKilometer() > deviceKm.getMaxKilometer()
? TrainRunDirection.UP
: TrainRunDirection.DOWN;
}
// 确定方向
if (destinationKm.getMaxKilometer() > deviceKm.getMaxKilometer()) { // 目的地最大公里标大于设备最大公里标上行
obj.setDir(TrainRunDirection.UP.getDir());
} else {
obj.setDir(TrainRunDirection.DOWN.getDir());
}
// 如果目的码都没有确定方向则使用车次确定方向
if (direction == null && StringUtils.isNoneEmpty(globalId)) {
direction = TrainRunDirection.match(Integer.parseInt(globalId.substring(0, 1)));
}
if (direction != null) {
obj.setDir(direction.getDir());
}
// 赋值公里标
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;
}
}
}

View File

@ -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);
}

View File

@ -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);
}

@ -1 +1 @@
Subproject commit b3b9885e2784cdad86901303e0bb9abf28c35e10
Subproject commit c9a07e75f06e8247d33f9e08c52d5045f1db2bc2