Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9de0a24573
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,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<MessageData> 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<MessageData> 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);
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit b3b9885e2784cdad86901303e0bb9abf28c35e10
|
||||
Subproject commit c9a07e75f06e8247d33f9e08c52d5045f1db2bc2
|
Loading…
Reference in New Issue
Block a user