【修改设备公里标初始化,增加道岔区段初始化】

This commit is contained in:
weizhihong 2023-07-21 17:01:43 +08:00
parent d338cbb135
commit cfa8eb81a1
8 changed files with 1908 additions and 1792 deletions

View File

@ -5,20 +5,18 @@ import club.joylink.xiannccda.dto.PublishedGIQueryDTO;
import club.joylink.xiannccda.entity.PublishedGi;
import club.joylink.xiannccda.repository.IPublishedGiRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/** 线路发布数据内存管理 */
@Component
@RequiredArgsConstructor
public class LineGraphicDataManage implements ApplicationRunner {
final IPublishedGiRepository iPublishedGiRepository;
public LineGraphicDataManage(IPublishedGiRepository iPublishedGiRepository) {
this.iPublishedGiRepository = iPublishedGiRepository;
}
@Override
public void run(ApplicationArguments args) throws Exception {
PublishedGIQueryDTO query = new PublishedGIQueryDTO();

View File

@ -1,6 +1,8 @@
package club.joylink.xiannccda.ats.cache;
import club.joylink.xiannccda.dto.protos.DeviceInfoProto;
import club.joylink.xiannccda.dto.protos.DeviceInfoProto.DeviceKilometer;
import club.joylink.xiannccda.dto.protos.DeviceInfoProto.Turnout;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RelatedRef.DeviceType;
@ -55,13 +57,17 @@ public class LineGraphicDataRepository {
// DeviceNameChanger.init(storage);
Map<String, Map<String, Builder>> lineDataMap = new HashMap<>();
// 构建区段
sectionInitLineGraph(lineDataMap, storage);
physicalSectionInitLineGraph(lineDataMap, storage);
// 构建道岔
turnoutInitLineGraph(publishGi.getLineId(), lineDataMap, storage);
// 设置公里标
setUpKilometerCode(publishGi.getLineId(), lineDataMap, storage);
// --------------------这里需要依赖区段道岔初始化信息 start-----------------
// 设置公里标后开始构建逻辑区段的编码公里标信息
setUpLogicSectionInfo(lineDataMap, storage);
// 设置道岔区段信息
setUpTurnoutPhysicalSectionInfo(lineDataMap, storage);
// --------------------这里需要依赖区段道岔初始化信息 end ------------------
lineGraphMap.put(publishGi.getLineId(), lineDataMap);
// 填充line_code_table
@ -79,14 +85,14 @@ public class LineGraphicDataRepository {
* @param sectionName 区段名称
* @return 公里标
*/
public static List<Long> getKilometerCodeList(int lineId, String sectionName) {
public static DeviceKilometer.Builder getKilometerCodeList(int lineId, String sectionName) {
Map<String, Map<String, Builder>> lineDataMap = lineGraphMap.get(lineId);
if (CollectionUtils.isNotEmpty(lineDataMap)) {
Map<String, Builder> sectionMap = lineDataMap.get(DeviceType.Section.name());
for (Builder v : sectionMap.values()) {
DeviceInfoProto.Section.Builder builder = (DeviceInfoProto.Section.Builder) v;
if (Objects.equals(builder.getCode(), sectionName)) {
return builder.getConvertKilometerList();
return builder.getKilometerBuilder();
}
}
@ -94,11 +100,11 @@ public class LineGraphicDataRepository {
for (Builder v : turnoutMap.values()) {
DeviceInfoProto.Turnout.Builder builder = (DeviceInfoProto.Turnout.Builder) v;
if (Objects.equals(builder.getCode(), sectionName)) {
return builder.getConvertKilometerList();
return builder.getKilometerBuilder();
}
}
}
return List.of();
return null;
}
/** 删除线路绘图数据 */
@ -160,24 +166,22 @@ public class LineGraphicDataRepository {
* @param dataMap 缓存数据
* @param storage 地图构建数据
*/
private static void sectionInitLineGraph(
private static void physicalSectionInitLineGraph(
Map<String, Map<String, Builder>> dataMap, LayoutGraphicsProto.RtssGraphicStorage storage) {
// 地图
List<Section> sectionList = storage.getSectionList();
// 物理区段数据
Map<String, Builder> cacheSectionMap = new HashMap<>(sectionList.size());
// 要保存的逻辑区段信息,预设值[section数量 * ABCD]
Map<String, Builder> cacheLogicSectionMap = new HashMap<>(sectionList.size() * 4);
// 先初始化物理区段信息
List<Section> sectionList =
storage.getSectionList().stream()
.filter(s -> Objects.equals(s.getSectionType(), SectionType.Physical))
.toList();
// 物理区段数据 + 逻辑区段数据预设值[物理section数量 * ABCD]
Map<String, Builder> sectionMap = new HashMap<>(sectionList.size() * 5);
sectionList.stream()
// 目前数据中还存在 区段类型为 逻辑区段类型暂时先过滤掉错误
.filter(section -> !SectionType.UNRECOGNIZED.equals(section.getSectionType()))
.forEach(
section -> {
String sid = section.getCommon().getId();
DeviceInfoProto.Section.Builder sectionBuilder =
cacheSectionMap.containsKey(sid)
? (DeviceInfoProto.Section.Builder) cacheSectionMap.get(sid)
: DeviceInfoProto.Section.newBuilder().setId(sid);
DeviceInfoProto.Section.Builder sectionBuilder = initSection(sectionMap, sid);
sectionBuilder.setCode(section.getCode());
sectionBuilder.setDestinationCode(section.getDestinationCode());
if (section.getChildrenCount() > 0) {
@ -185,19 +189,10 @@ public class LineGraphicDataRepository {
// 初始化逻辑区段信息,建立逻辑区段与物理区段之间的关系
section
.getChildrenList()
.forEach(
id ->
cacheLogicSectionMap.put(
id,
DeviceInfoProto.Section.newBuilder()
.setId(id)
.setPhysicalSectionId(sid)));
.forEach(id -> initSection(sectionMap, id).setPhysicalSectionId(sid));
}
cacheSectionMap.put(sid, sectionBuilder);
});
// 将逻辑区段信息放入区段集合中
cacheSectionMap.putAll(cacheLogicSectionMap);
dataMap.put(DeviceType.Section.name(), cacheSectionMap);
dataMap.put(DeviceType.Section.name(), sectionMap);
}
/**
@ -224,33 +219,52 @@ public class LineGraphicDataRepository {
DeviceInfoProto.Turnout.Builder turnoutBuilder = DeviceInfoProto.Turnout.newBuilder();
turnoutBuilder.setId(t.getCommon().getId());
turnoutBuilder.setCode(t.getCode());
turnoutBuilder.addAllKilometerSystem(systemList);
turnoutBuilder.setKilometer(initKilometer(systemList));
cacheSwitchMap.put(t.getCommon().getId(), turnoutBuilder);
// 从道岔中生成坐标转换对象
if (systemList.size() > 1) {
for (int i = 0, len = systemList.size(); i < len; i++) {
KilometerSystem si = systemList.get(i);
for (int j = i + 1; j < len; j++) {
KilometerSystem sj = systemList.get(j);
// 坐标系不一致时生成转换对象
if (!Objects.equals(sj.getCoordinateSystem(), si.getCoordinateSystem())) {
String convertorKey =
CoordinateConvertor.generateConvertorKey(
sj.getCoordinateSystem(), si.getCoordinateSystem());
if (!convertorMap.containsKey(convertorKey)) {
convertorMap.put(
convertorKey,
CoordinateConvertor.generate(
si, sj.getCoordinateSystem(), sj.getKilometer()));
}
}
}
}
}
convertorCoordinateByTurnoutKM(convertorMap, systemList);
});
dataMap.put(DeviceType.Turnout.name(), cacheSwitchMap);
}
/**
* 设置道岔区段信息
*
* @param dataMap 设备信息
* @param storage
*/
private static void setUpTurnoutPhysicalSectionInfo(
Map<String, Map<String, Builder>> dataMap, LayoutGraphicsProto.RtssGraphicStorage storage) {
Map<String, Builder> curSectionMap = dataMap.getOrDefault(DeviceType.Section.name(), Map.of());
Map<String, Builder> turnoutMap = dataMap.getOrDefault(DeviceType.Turnout.name(), Map.of());
// 先初始化物理区段信息
List<Section> sectionList =
storage.getSectionList().stream()
.filter(s -> Objects.equals(s.getSectionType(), SectionType.TurnoutPhysical))
.toList();
// 道岔区段数据
Map<String, Builder> sectionMap = new HashMap<>(sectionList.size());
sectionList.forEach(
section -> {
String sid = section.getCommon().getId();
DeviceInfoProto.Section.Builder s = initSection(sectionMap, sid);
s.setCode(section.getCode());
s.setDestinationCode(section.getDestinationCode());
if (section.getChildrenCount() > 0) {
section
.getChildrenList()
.forEach(
tid -> {
Turnout.Builder t = findTurnout(turnoutMap, tid);
if (t != null) {
updateMinAndMaxKilometer(s.getKilometerBuilder(), t.getKilometerBuilder());
}
});
}
});
curSectionMap.putAll(sectionMap);
dataMap.put(DeviceType.Section.name(), curSectionMap);
}
/**
* 设置公里标
*
@ -275,27 +289,23 @@ public class LineGraphicDataRepository {
.forEach(
ref -> {
if (Objects.equals(DeviceType.Section, ref.getDeviceType())) {
if (sectionMap.containsKey(ref.getId())) {
DeviceInfoProto.Section.Builder sectionBuilder =
(DeviceInfoProto.Section.Builder) sectionMap.get(ref.getId());
sectionBuilder.addKilometerSystem(ac.getKilometerSystem());
sectionBuilder.addConvertKilometer(mainLineCoordinate);
DeviceInfoProto.Section.Builder b = findSection(sectionMap, ref.getId());
if (b != null) {
DeviceInfoProto.DeviceKilometer.Builder k = b.getKilometerBuilder();
updateKilometer(k, ac.getKilometerSystem(), mainLineCoordinate);
}
} else if (Objects.equals(DeviceType.Turnout, ref.getDeviceType())) {
if (turnoutMap.containsKey(ref.getId())) {
DeviceInfoProto.Turnout.Builder turnoutBuilder =
(DeviceInfoProto.Turnout.Builder) turnoutMap.get(ref.getId());
// 如果已经转换过则不再做转换
if (turnoutBuilder.getConvertKilometerCount() == 0) {
turnoutBuilder.getKilometerSystemList().stream()
.filter(s -> StringUtils.isNotEmpty(s.getCoordinateSystem()))
.forEach(
s ->
turnoutBuilder.addConvertKilometer(
doConvertorCoordinate(lineId, s)));
}
// 放入当前计轴转换信息
turnoutBuilder.addConvertKilometer(mainLineCoordinate);
DeviceInfoProto.Turnout.Builder b = findTurnout(turnoutMap, ref.getId());
if (b != null) {
DeviceInfoProto.DeviceKilometer.Builder k = b.getKilometerBuilder();
// 更新道岔自身的公里标数据
k.getKilometerSystemList()
.forEach(
s ->
updateMinAndMaxKilometer(
k, doConvertorCoordinate(lineId, s)));
// 放入当前计轴信息
updateKilometer(k, ac.getKilometerSystem(), mainLineCoordinate);
}
}
});
@ -333,8 +343,8 @@ public class LineGraphicDataRepository {
DeviceType.Turnout.equals(ref.getDeviceType())
&& turnoutMap.containsKey(ref.getId()))
.map(ref -> (DeviceInfoProto.Turnout.Builder) turnoutMap.get(ref.getId()))
.filter(t -> t.getKilometerSystemCount() > 0)
.map(t -> t.getKilometerSystemList().get(0))
.filter(t -> t.getKilometer().getKilometerSystemCount() > 0)
.map(t -> t.getKilometer().getKilometerSystemList().get(0))
.toList();
// 如果关联多个道岔
if (kilometerSystemList.size() > 1) {
@ -377,6 +387,49 @@ public class LineGraphicDataRepository {
});
}
/**
* 根据道岔的公里标获取转换信息
*
* @param convertorMap 转换保存集合
* @param systemList 公里标集合
*/
private static void convertorCoordinateByTurnoutKM(
Map<String, CoordinateConvertor> convertorMap, List<KilometerSystem> systemList) {
if (CollectionUtils.isEmpty(systemList)) {
return;
}
// 有效坐标系
List<KilometerSystem> effectiveList =
systemList.stream().filter(s -> StringUtils.isNotEmpty(s.getCoordinateSystem())).toList();
if (CollectionUtils.isEmpty(effectiveList)) {
return;
}
// 坐标系的种类
long typeCount =
effectiveList.stream().map(KilometerSystem::getCoordinateSystem).distinct().count();
if (typeCount < 2) { // 种类小于2则不需要转换
return;
}
// 从道岔中生成坐标转换对象
for (int i = 0, len = effectiveList.size(); i < len; i++) {
KilometerSystem si = effectiveList.get(i);
for (int j = i + 1; j < len; j++) {
KilometerSystem sj = effectiveList.get(j);
// 坐标系不一致时生成转换对象
if (!Objects.equals(sj.getCoordinateSystem(), si.getCoordinateSystem())) {
String convertorKey =
CoordinateConvertor.generateConvertorKey(
sj.getCoordinateSystem(), si.getCoordinateSystem());
if (!convertorMap.containsKey(convertorKey)) {
convertorMap.put(
convertorKey,
CoordinateConvertor.generate(si, sj.getCoordinateSystem(), sj.getKilometer()));
}
}
}
}
}
/**
* 公里标转换
*
@ -416,29 +469,133 @@ public class LineGraphicDataRepository {
section -> {
String sid = section.getCommon().getId();
if (sectionMap.containsKey(sid)) {
DeviceInfoProto.Section.Builder sectionBuilder =
(DeviceInfoProto.Section.Builder) sectionMap.get(sid);
DeviceInfoProto.Section.Builder sectionBuilder = findSection(sectionMap, sid);
sectionBuilder.setCode(section.getCode());
// 获取到物理区段信息
DeviceInfoProto.Section.Builder physicalSection =
(DeviceInfoProto.Section.Builder)
sectionMap.get(sectionBuilder.getPhysicalSectionId());
if (physicalSection.getKilometerSystemCount() > 0) {
long min =
physicalSection.getConvertKilometerList().stream().min(Long::compareTo).get();
long max =
physicalSection.getConvertKilometerList().stream().max(Long::compareTo).get();
findSection(sectionMap, sectionBuilder.getPhysicalSectionId());
DeviceKilometer.Builder deviceKilometer = sectionBuilder.getKilometerBuilder();
DeviceKilometer.Builder parentKilometer = physicalSection.getKilometerBuilder();
if (parentKilometer.getKilometerSystemCount() > 0) {
long min = parentKilometer.getMinKilometer();
long max = parentKilometer.getMaxKilometer();
long avgDistance = (max - min) / physicalSection.getChildrenIdCount();
int index = physicalSection.getChildrenIdList().indexOf(sid);
// 最小公里标
sectionBuilder.addConvertKilometer(min + index * avgDistance);
// 最大公里标
sectionBuilder.addConvertKilometer(min + (index + 1) * avgDistance);
deviceKilometer.setMinKilometer(min + index * avgDistance); // 最小公里标
deviceKilometer.setMaxKilometer(min + (index + 1) * avgDistance); // 最大公里标
}
}
});
}
/**
* 生成默认的公里标对象
*
* @param list 公里标列表
* @return 对象信息
*/
private static DeviceInfoProto.DeviceKilometer.Builder initKilometer(List<KilometerSystem> list) {
DeviceInfoProto.DeviceKilometer.Builder builder = initKilometer();
if (CollectionUtils.isNotEmpty(list)) {
builder.addAllKilometerSystem(list);
}
return builder;
}
/**
* 生成默认的公里标对象
*
* @return 对象信息
*/
private static DeviceInfoProto.DeviceKilometer.Builder initKilometer() {
DeviceInfoProto.DeviceKilometer.Builder builder = DeviceInfoProto.DeviceKilometer.newBuilder();
builder.setMinKilometer(Long.MAX_VALUE);
builder.setMaxKilometer(Long.MIN_VALUE);
return builder;
}
/**
* 更新实体内的公里标信息
*
* @param kilometer 公里标对象
* @param km 传入的公里标
* @param mainLineCoordinate 转换成的正线公里标信息
*/
private static void updateKilometer(
DeviceInfoProto.DeviceKilometer.Builder kilometer,
KilometerSystem km,
long mainLineCoordinate) {
kilometer.addKilometerSystem(km);
kilometer.setMinKilometer(Math.min(kilometer.getMinKilometer(), mainLineCoordinate));
kilometer.setMaxKilometer(Math.max(kilometer.getMaxKilometer(), mainLineCoordinate));
}
/**
* 更新实体最大最小公里标
*
* @param kilometer 公里标对象
* @param mainLineCoordinate 转换的正线数据
*/
private static void updateMinAndMaxKilometer(
DeviceInfoProto.DeviceKilometer.Builder kilometer, long mainLineCoordinate) {
kilometer.setMinKilometer(Math.min(kilometer.getMinKilometer(), mainLineCoordinate));
kilometer.setMaxKilometer(Math.max(kilometer.getMaxKilometer(), mainLineCoordinate));
}
private static void updateMinAndMaxKilometer(
DeviceInfoProto.DeviceKilometer.Builder kilometer,
DeviceInfoProto.DeviceKilometer.Builder km) {
kilometer.setMinKilometer(Math.min(kilometer.getMinKilometer(), km.getMinKilometer()));
kilometer.setMaxKilometer(Math.max(kilometer.getMaxKilometer(), km.getMaxKilometer()));
}
/**
* 获取区段信息没有时创建并放入map中
*
* @param map 区段的集合
* @param id 区段ID
* @return 区段实体信息
*/
private static DeviceInfoProto.Section.Builder initSection(Map<String, Builder> map, String id) {
if (map.containsKey(id)) {
return (DeviceInfoProto.Section.Builder) map.get(id);
} else {
DeviceInfoProto.Section.Builder builder = DeviceInfoProto.Section.newBuilder();
builder.setId(id);
builder.setKilometer(initKilometer());
map.put(id, builder);
return builder;
}
}
/**
* 获取区段信息
*
* @param map 区段集合
* @param id 区段ID
* @return 区段信息
*/
private static DeviceInfoProto.Section.Builder findSection(Map<String, Builder> map, String id) {
if (map.containsKey(id)) {
return (DeviceInfoProto.Section.Builder) map.get(id);
}
return null;
}
/**
* 获取道岔信息
*
* @param map 道岔集合
* @param id 道岔ID
* @return 道岔信息
*/
private static DeviceInfoProto.Turnout.Builder findTurnout(Map<String, Builder> map, String id) {
if (map.containsKey(id)) {
return (DeviceInfoProto.Turnout.Builder) map.get(id);
}
return null;
}
/** 坐标系枚举 */
@Getter
private enum CoordinateEnum {

View File

@ -7,10 +7,9 @@ import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData;
import club.joylink.xiannccda.ats.message.line3.changer.DeviceNameChangerManage;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.protos.DeviceInfoProto;
import club.joylink.xiannccda.dto.protos.DeviceInfoProto.DeviceKilometer;
import club.joylink.xiannccda.dto.protos.WsMessageProto;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@ -56,9 +55,9 @@ public abstract class LineNetTrainComMethod {
public static void setUpKilometerCode(
WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj, DeviceType type, String deviceName) {
// 获取到当前区段公里标
List<Long> kmList = getDeviceKilometerCode(obj.getLineId(), type, deviceName);
if (CollectionUtils.isNotEmpty(kmList)) {
obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), kmList));
DeviceKilometer.Builder km = getDeviceKM(obj.getLineId(), type, deviceName);
if (km != null) {
obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), km));
} else {
log.warn(String.format("设备%s没有公里标信息", deviceName));
}
@ -70,31 +69,29 @@ public abstract class LineNetTrainComMethod {
* @param obj 要设置的对象
* @param destinationCode 目的码
* @param type 设备类型
* @param deviceName 设备名称
* @param name 设备名称
*/
public static void setTrainDirectionAndKilometerCode(
WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj,
String destinationCode,
DeviceType type,
String deviceName) {
List<Long> deviceKmList = getDeviceKilometerCode(obj.getLineId(), type, deviceName);
if (CollectionUtils.isEmpty(deviceKmList)) {
String name) {
DeviceKilometer.Builder deviceKm = getDeviceKM(obj.getLineId(), type, name);
if (deviceKm == null) {
return;
}
List<Long> destinationKmList = getDirectionCodeKilometerCode(obj.getLineId(), destinationCode);
if (CollectionUtils.isEmpty(destinationKmList)) {
DeviceKilometer.Builder destinationKm = getDirectionCodeKM(obj.getLineId(), destinationCode);
if (destinationKm == null) {
return;
}
// 确定方向
long deviceMax = deviceKmList.stream().max(Long::compareTo).get();
long destinationMax = destinationKmList.stream().max(Long::compareTo).get();
if (destinationMax > deviceMax) { // 目的地最大公里标大于设备最大公里标上行
obj.setDir(TrainRunDirection.UP.getNum());
if (destinationKm.getMaxKilometer() > deviceKm.getMaxKilometer()) { // 目的地最大公里标大于设备最大公里标上行
obj.setDir(TrainRunDirection.UP.getDir());
} else {
obj.setDir(TrainRunDirection.DOWN.getNum());
obj.setDir(TrainRunDirection.DOWN.getDir());
}
// 赋值公里标
obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), deviceKmList));
obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), deviceKm));
}
/**
@ -102,16 +99,16 @@ public abstract class LineNetTrainComMethod {
*
* @param lineId 线路ID
* @param type 设备类型
* @param deviceName 设备名称
* @param name 设备名称
* @return 公里标列表
*/
private static List<Long> getDeviceKilometerCode(int lineId, DeviceType type, String deviceName) {
private static DeviceKilometer.Builder getDeviceKM(int lineId, DeviceType type, String name) {
// 非区段道岔直接返回
if (!DeviceType.DEVICE_TYPE_TRACK.equals(type) && !DeviceType.DEVICE_TYPE_SWITCH.equals(type)) {
return List.of();
return null;
}
// 转换成程序中的名称
String convertName = DeviceNameChangerManage.findMatch(type, deviceName);
String convertName = DeviceNameChangerManage.findMatch(type, name);
// 获取到当前区段公里标
return LineGraphicDataRepository.getKilometerCodeList(lineId, convertName);
}
@ -123,7 +120,7 @@ public abstract class LineNetTrainComMethod {
* @param code 目的地码
* @return 公里标列表
*/
private static List<Long> getDirectionCodeKilometerCode(int lineId, String code) {
private static DeviceKilometer.Builder getDirectionCodeKM(int lineId, String code) {
Map<String, Builder> map = LineGraphicDataRepository.getLineSectionBuild(lineId);
Optional<Builder> destination =
map.values().stream()
@ -135,9 +132,9 @@ public abstract class LineNetTrainComMethod {
.findFirst();
if (destination.isPresent()) {
DeviceInfoProto.Section.Builder b = (DeviceInfoProto.Section.Builder) destination.get();
return b.getConvertKilometerList();
return b.getKilometerBuilder();
} else {
return List.of();
return null;
}
}
@ -145,19 +142,12 @@ public abstract class LineNetTrainComMethod {
* 选择对应的公里标信息
*
* @param dir 运行方向
* @param kmList 公里标列表
* @param km 公里标信息
* @return 公里标
*/
private static long selectDeviceKilometerCode(int dir, List<Long> kmList) {
long kilometer;
if (dir == 1) { // 下行取大值
kilometer = kmList.stream().min(Long::compareTo).get();
} else if (dir == 2) { // 上行取小值
kilometer = kmList.stream().max(Long::compareTo).get();
} else { // 无方向获取第一个
kilometer = kmList.get(0);
}
return kilometer;
private static long selectDeviceKilometerCode(int dir, DeviceKilometer.Builder km) {
// 下行(1)取小值 \ 上行(2)取大值
return TrainRunDirection.UP.isMatch(dir) ? km.getMaxKilometer() : km.getMinKilometer();
}
@Getter
@ -166,10 +156,14 @@ public abstract class LineNetTrainComMethod {
DOWN(1),
NO(0);
private int num;
private int dir;
TrainRunDirection(int num) {
this.num = num;
TrainRunDirection(int dir) {
this.dir = dir;
}
public boolean isMatch(int dir) {
return this.dir == dir;
}
}
}

View File

@ -0,0 +1,52 @@
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.device.DeviceType;
import club.joylink.xiannccda.ats.message.line3.rep.TrainRecordResponse;
import club.joylink.xiannccda.dto.protos.WsMessageProto;
import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
@Override
public MessageId getMessageId() {
return MessageId.TRAIN_RECORD;
}
@Override
public void run(List<MessageData> messageDataList) {
try {
List<Builder> buildList = Lists.newArrayList();
// 已存在的设备信息
for (MessageData data : messageDataList) {
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
TrainRecordResponse response = (TrainRecordResponse) data;
WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset =
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
offset.setLineId(response.getLineId()); // 线路id
offset.setGroupId(response.getGroupId()); // 车组号
LineNetTrainComMethod.getDeviceStatusById(offset); // 合并老旧数据
offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向
// 设置公里标信息
LineNetTrainComMethod.setUpKilometerCode(
offset, DeviceType.DEVICE_TYPE_TRACK, response.getTrackName());
offset.setShow(offset.getKilometerCode() != 0);
buildList.add(offset);
}
}
// 增加设备信息
DeviceStatusDataOperate.addDevices(buildList, LineNetTrainComMethod.getDeviceStatusData());
} catch (Exception e) {
log.error("信息生成出错", e);
}
}
}

View File

@ -16926,27 +16926,7 @@ public final class LayoutGraphicsProto {
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return The upAndDown.
*/
java.lang.String getUpAndDown();
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return The bytes for upAndDown.
*/
com.google.protobuf.ByteString
getUpAndDownBytes();
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -16955,7 +16935,7 @@ public final class LayoutGraphicsProto {
java.lang.String getRefStation();
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -16963,6 +16943,16 @@ public final class LayoutGraphicsProto {
*/
com.google.protobuf.ByteString
getRefStationBytes();
/**
* <pre>
*上下行--true表示上行false表示下行
* </pre>
*
* <code>bool up = 7;</code>
* @return The up.
*/
boolean getUp();
}
/**
* Protobuf type {@code graphicData.Platform}
@ -16979,7 +16969,6 @@ public final class LayoutGraphicsProto {
private Platform() {
code_ = "";
direction_ = "";
upAndDown_ = "";
refStation_ = "";
}
@ -17130,59 +17119,12 @@ public final class LayoutGraphicsProto {
}
}
public static final int UPANDDOWN_FIELD_NUMBER = 5;
@SuppressWarnings("serial")
private volatile java.lang.Object upAndDown_ = "";
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return The upAndDown.
*/
@java.lang.Override
public java.lang.String getUpAndDown() {
java.lang.Object ref = upAndDown_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
upAndDown_ = s;
return s;
}
}
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return The bytes for upAndDown.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getUpAndDownBytes() {
java.lang.Object ref = upAndDown_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
upAndDown_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int REFSTATION_FIELD_NUMBER = 6;
@SuppressWarnings("serial")
private volatile java.lang.Object refStation_ = "";
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -17203,7 +17145,7 @@ public final class LayoutGraphicsProto {
}
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -17224,6 +17166,21 @@ public final class LayoutGraphicsProto {
}
}
public static final int UP_FIELD_NUMBER = 7;
private boolean up_ = false;
/**
* <pre>
*上下行--true表示上行false表示下行
* </pre>
*
* <code>bool up = 7;</code>
* @return The up.
*/
@java.lang.Override
public boolean getUp() {
return up_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
@ -17250,12 +17207,12 @@ public final class LayoutGraphicsProto {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(direction_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 4, direction_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(upAndDown_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 5, upAndDown_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(refStation_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 6, refStation_);
}
if (up_ != false) {
output.writeBool(7, up_);
}
getUnknownFields().writeTo(output);
}
@ -17279,12 +17236,13 @@ public final class LayoutGraphicsProto {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(direction_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, direction_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(upAndDown_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, upAndDown_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(refStation_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, refStation_);
}
if (up_ != false) {
size += com.google.protobuf.CodedOutputStream
.computeBoolSize(7, up_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
return size;
@ -17311,10 +17269,10 @@ public final class LayoutGraphicsProto {
!= other.getHasdoor()) return false;
if (!getDirection()
.equals(other.getDirection())) return false;
if (!getUpAndDown()
.equals(other.getUpAndDown())) return false;
if (!getRefStation()
.equals(other.getRefStation())) return false;
if (getUp()
!= other.getUp()) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@ -17337,10 +17295,11 @@ public final class LayoutGraphicsProto {
getHasdoor());
hash = (37 * hash) + DIRECTION_FIELD_NUMBER;
hash = (53 * hash) + getDirection().hashCode();
hash = (37 * hash) + UPANDDOWN_FIELD_NUMBER;
hash = (53 * hash) + getUpAndDown().hashCode();
hash = (37 * hash) + REFSTATION_FIELD_NUMBER;
hash = (53 * hash) + getRefStation().hashCode();
hash = (37 * hash) + UP_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(
getUp());
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@ -17480,8 +17439,8 @@ public final class LayoutGraphicsProto {
code_ = "";
hasdoor_ = false;
direction_ = "";
upAndDown_ = "";
refStation_ = "";
up_ = false;
return this;
}
@ -17530,10 +17489,10 @@ public final class LayoutGraphicsProto {
result.direction_ = direction_;
}
if (((from_bitField0_ & 0x00000010) != 0)) {
result.upAndDown_ = upAndDown_;
result.refStation_ = refStation_;
}
if (((from_bitField0_ & 0x00000020) != 0)) {
result.refStation_ = refStation_;
result.up_ = up_;
}
}
@ -17565,15 +17524,13 @@ public final class LayoutGraphicsProto {
bitField0_ |= 0x00000008;
onChanged();
}
if (!other.getUpAndDown().isEmpty()) {
upAndDown_ = other.upAndDown_;
if (!other.getRefStation().isEmpty()) {
refStation_ = other.refStation_;
bitField0_ |= 0x00000010;
onChanged();
}
if (!other.getRefStation().isEmpty()) {
refStation_ = other.refStation_;
bitField0_ |= 0x00000020;
onChanged();
if (other.getUp() != false) {
setUp(other.getUp());
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
@ -17623,16 +17580,16 @@ public final class LayoutGraphicsProto {
bitField0_ |= 0x00000008;
break;
} // case 34
case 42: {
upAndDown_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000010;
break;
} // case 42
case 50: {
refStation_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000010;
break;
} // case 50
case 56: {
up_ = input.readBool();
bitField0_ |= 0x00000020;
break;
} // case 56
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
@ -17977,102 +17934,10 @@ public final class LayoutGraphicsProto {
return this;
}
private java.lang.Object upAndDown_ = "";
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return The upAndDown.
*/
public java.lang.String getUpAndDown() {
java.lang.Object ref = upAndDown_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
upAndDown_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return The bytes for upAndDown.
*/
public com.google.protobuf.ByteString
getUpAndDownBytes() {
java.lang.Object ref = upAndDown_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
upAndDown_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @param value The upAndDown to set.
* @return This builder for chaining.
*/
public Builder setUpAndDown(
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
upAndDown_ = value;
bitField0_ |= 0x00000010;
onChanged();
return this;
}
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @return This builder for chaining.
*/
public Builder clearUpAndDown() {
upAndDown_ = getDefaultInstance().getUpAndDown();
bitField0_ = (bitField0_ & ~0x00000010);
onChanged();
return this;
}
/**
* <pre>
*上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string upAndDown = 5;</code>
* @param value The bytes for upAndDown to set.
* @return This builder for chaining.
*/
public Builder setUpAndDownBytes(
com.google.protobuf.ByteString value) {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
upAndDown_ = value;
bitField0_ |= 0x00000010;
onChanged();
return this;
}
private java.lang.Object refStation_ = "";
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -18092,7 +17957,7 @@ public final class LayoutGraphicsProto {
}
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -18113,7 +17978,7 @@ public final class LayoutGraphicsProto {
}
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -18124,13 +17989,13 @@ public final class LayoutGraphicsProto {
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
refStation_ = value;
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000010;
onChanged();
return this;
}
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -18138,13 +18003,13 @@ public final class LayoutGraphicsProto {
*/
public Builder clearRefStation() {
refStation_ = getDefaultInstance().getRefStation();
bitField0_ = (bitField0_ & ~0x00000020);
bitField0_ = (bitField0_ & ~0x00000010);
onChanged();
return this;
}
/**
* <pre>
*关联的车站
*string upAndDown =5; //上下行--upLink表示上行downLink表示下行
* </pre>
*
* <code>string refStation = 6;</code>
@ -18156,10 +18021,54 @@ public final class LayoutGraphicsProto {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
refStation_ = value;
bitField0_ |= 0x00000010;
onChanged();
return this;
}
private boolean up_ ;
/**
* <pre>
*上下行--true表示上行false表示下行
* </pre>
*
* <code>bool up = 7;</code>
* @return The up.
*/
@java.lang.Override
public boolean getUp() {
return up_;
}
/**
* <pre>
*上下行--true表示上行false表示下行
* </pre>
*
* <code>bool up = 7;</code>
* @param value The up to set.
* @return This builder for chaining.
*/
public Builder setUp(boolean value) {
up_ = value;
bitField0_ |= 0x00000020;
onChanged();
return this;
}
/**
* <pre>
*上下行--true表示上行false表示下行
* </pre>
*
* <code>bool up = 7;</code>
* @return This builder for chaining.
*/
public Builder clearUp() {
bitField0_ = (bitField0_ & ~0x00000020);
up_ = false;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
@ -40831,78 +40740,78 @@ public final class LayoutGraphicsProto {
"\n\007Polygon\022\'\n\006common\030\001 \001(\0132\027.graphicData." +
"CommonInfo\022\014\n\004code\030\002 \001(\t\022\021\n\tlineWidth\030\003 " +
"\001(\005\022\021\n\tlineColor\030\004 \001(\t\022\"\n\006points\030\005 \003(\0132\022" +
".graphicData.Point\"\214\001\n\010Platform\022\'\n\006commo" +
".graphicData.Point\"\205\001\n\010Platform\022\'\n\006commo" +
"n\030\001 \001(\0132\027.graphicData.CommonInfo\022\014\n\004code" +
"\030\002 \001(\t\022\017\n\007hasdoor\030\003 \001(\010\022\021\n\tdirection\030\004 \001" +
"(\t\022\021\n\tupAndDown\030\005 \001(\t\022\022\n\nrefStation\030\006 \001(" +
"\t\"\270\001\n\007Station\022\'\n\006common\030\001 \001(\0132\027.graphicD" +
"ata.CommonInfo\022\014\n\004code\030\002 \001(\t\022\022\n\nhasContr" +
"ol\030\003 \001(\010\022\035\n\025concentrationStations\030\004 \001(\010\022" +
"5\n\017kilometerSystem\030\006 \001(\0132\034.graphicData.K" +
"ilometerSystem\022\014\n\004name\030\007 \001(\t\"k\n\013StationL" +
"ine\022\'\n\006common\030\001 \001(\0132\027.graphicData.Common" +
"Info\022\014\n\004code\030\002 \001(\t\022\023\n\013hasTransfer\030\003 \001(\010\022" +
"\020\n\010hideName\030\004 \001(\010\"Y\n\013TrainWindow\022\'\n\006comm" +
"on\030\001 \001(\0132\027.graphicData.CommonInfo\022\014\n\004cod" +
"e\030\002 \001(\t\022\023\n\013refDeviceId\030\003 \003(\t\"\256\001\n\014AxleCou" +
"nting\022\'\n\006common\030\001 \001(\0132\027.graphicData.Comm" +
"onInfo\022\014\n\004code\030\002 \001(\t\0225\n\017kilometerSystem\030" +
"\003 \001(\0132\034.graphicData.KilometerSystem\0220\n\017a" +
"xleCountingRef\030\004 \003(\0132\027.graphicData.Relat" +
"edRef\">\n\005Train\022\'\n\006common\030\001 \001(\0132\027.graphic" +
"Data.CommonInfo\022\014\n\004code\030\002 \001(\t\"B\n\tTrainLi" +
"ne\022\'\n\006common\030\001 \001(\0132\027.graphicData.CommonI" +
"nfo\022\014\n\004code\030\002 \001(\t\"@\n\007IscsFan\022\'\n\006common\030\001" +
" \001(\0132\027.graphicData.CommonInfo\022\014\n\004code\030\002 " +
"\001(\t\"\333\002\n\007Turnout\022\'\n\006common\030\001 \001(\0132\027.graphi" +
"cData.CommonInfo\022\014\n\004code\030\002 \001(\t\022\"\n\006pointA" +
"\030\006 \003(\0132\022.graphicData.Point\022\"\n\006pointB\030\007 \003" +
"(\0132\022.graphicData.Point\022\"\n\006pointC\030\010 \003(\0132\022" +
".graphicData.Point\022&\n\005paRef\030\t \001(\0132\027.grap" +
"hicData.RelatedRef\022&\n\005pbRef\030\n \001(\0132\027.grap" +
"hicData.RelatedRef\022&\n\005pcRef\030\013 \001(\0132\027.grap" +
"hicData.RelatedRef\0225\n\017kilometerSystem\030\r " +
"\003(\0132\034.graphicData.KilometerSystem\">\n\017Kil" +
"ometerSystem\022\021\n\tkilometer\030\001 \001(\003\022\030\n\020coord" +
"inateSystem\030\002 \001(\t\"\206\001\n\006Signal\022\'\n\006common\030\001" +
" \001(\0132\027.graphicData.CommonInfo\022\014\n\004code\030\002 " +
"\001(\t\022\016\n\006mirror\030\003 \001(\010\0225\n\017kilometerSystem\030\006" +
" \001(\0132\034.graphicData.KilometerSystem\"\340\001\n\007R" +
"unLine\022\'\n\006common\030\001 \001(\0132\027.graphicData.Com" +
"monInfo\022\014\n\004code\030\002 \001(\t\022\"\n\006points\030\003 \003(\0132\022." +
"graphicData.Point\022\021\n\tnameColor\030\004 \001(\t\022\023\n\013" +
"nameBgColor\030\005 \001(\t\022\022\n\ncontainSta\030\010 \003(\t\022\025\n" +
"\rlinkPathLines\030\t \003(\t\022\016\n\006lineId\030\n \001(\t\022\027\n\017" +
"dashPointIndexs\030\013 \003(\005\"\337\002\n\007Section\022\'\n\006com" +
"mon\030\001 \001(\0132\027.graphicData.CommonInfo\022\014\n\004co" +
"de\030\002 \001(\t\022\"\n\006points\030\003 \003(\0132\022.graphicData.P" +
"oint\022&\n\005paRef\030\004 \001(\0132\027.graphicData.Relate" +
"dRef\022&\n\005pbRef\030\005 \001(\0132\027.graphicData.Relate" +
"dRef\0225\n\013sectionType\030\006 \001(\0162 .graphicData." +
"Section.SectionType\022\025\n\raxleCountings\030\007 \003" +
"(\t\022\020\n\010children\030\010 \003(\t\022\027\n\017destinationCode\030" +
"\t \001(\t\"0\n\013SectionType\022\014\n\010Physical\020\000\022\023\n\017Tu" +
"rnoutPhysical\020\002\"i\n\014LogicSection\022\'\n\006commo" +
"n\030\001 \001(\0132\027.graphicData.CommonInfo\022\014\n\004code" +
"\030\002 \001(\t\022\"\n\006points\030\003 \003(\0132\022.graphicData.Poi" +
"nt\"V\n\016KilometerPoint\022!\n\005point\030\001 \001(\0132\022.gr" +
"aphicData.Point\022\021\n\tkilometer\030\002 \001(\003\022\016\n\006st" +
"Name\030\003 \001(\t\"\277\001\n\010PathLine\022\'\n\006common\030\001 \001(\0132" +
"\027.graphicData.CommonInfo\022\014\n\004code\030\002 \001(\t\022\"" +
"\n\006points\030\003 \003(\0132\022.graphicData.Point\022\014\n\004is" +
"Up\030\004 \001(\010\0224\n\017kilometerPoints\030\005 \003(\0132\033.grap" +
"hicData.KilometerPoint\022\024\n\014isKmIncrease\030\006" +
" \001(\010\"\366\001\n\nRelatedRef\0226\n\ndeviceType\030\001 \001(\0162" +
"\".graphicData.RelatedRef.DeviceType\022\n\n\002i" +
"d\030\002 \001(\t\0226\n\ndevicePort\030\003 \001(\0162\".graphicDat" +
"a.RelatedRef.DevicePort\"I\n\nDeviceType\022\013\n" +
"\007Section\020\000\022\013\n\007Turnout\020\001\022\017\n\013TrainWindow\020\002" +
"\022\020\n\014AxleCounting\020\003\"!\n\nDevicePort\022\005\n\001A\020\000\022" +
"\005\n\001B\020\001\022\005\n\001C\020\002\"Y\n\tSeparator\022\'\n\006common\030\001 \001" +
"(\t\022\022\n\nrefStation\030\006 \001(\t\022\n\n\002up\030\007 \001(\010\"\270\001\n\007S" +
"tation\022\'\n\006common\030\001 \001(\0132\027.graphicData.Com" +
"monInfo\022\014\n\004code\030\002 \001(\t\022\022\n\nhasControl\030\003 \001(" +
"\010\022\035\n\025concentrationStations\030\004 \001(\010\0225\n\017kilo" +
"meterSystem\030\006 \001(\0132\034.graphicData.Kilomete" +
"rSystem\022\014\n\004name\030\007 \001(\t\"k\n\013StationLine\022\'\n\006" +
"common\030\001 \001(\0132\027.graphicData.CommonInfo\022\014\n" +
"\004code\030\002 \001(\t\022\023\n\013hasTransfer\030\003 \001(\010\022\020\n\010hide" +
"Name\030\004 \001(\010\"Y\n\013TrainWindow\022\'\n\006common\030\001 \001(" +
"\0132\027.graphicData.CommonInfo\022\014\n\004code\030\002 \001(\t" +
"\022\023\n\013refDeviceId\030\003 \003(\t\"\256\001\n\014AxleCounting\022\'" +
"\n\006common\030\001 \001(\0132\027.graphicData.CommonInfo\022" +
"\014\n\004code\030\002 \001(\t\0225\n\017kilometerSystem\030\003 \001(\0132\034" +
".graphicData.KilometerSystem\0220\n\017axleCoun" +
"tingRef\030\004 \003(\0132\027.graphicData.RelatedRef\">" +
"\n\005Train\022\'\n\006common\030\001 \001(\0132\027.graphicData.Co" +
"mmonInfo\022\014\n\004code\030\002 \001(\t\"B\n\tTrainLine\022\'\n\006c" +
"ommon\030\001 \001(\0132\027.graphicData.CommonInfo\022\014\n\004" +
"code\030\002 \001(\t\"@\n\007IscsFan\022\'\n\006common\030\001 \001(\0132\027." +
"graphicData.CommonInfo\022\014\n\004code\030\002 \001(\t\"\333\002\n" +
"\007Turnout\022\'\n\006common\030\001 \001(\0132\027.graphicData.C" +
"ommonInfo\022\014\n\004code\030\002 \001(\t\022\"\n\006pointA\030\006 \003(\0132" +
"\022.graphicData.Point\022\"\n\006pointB\030\007 \003(\0132\022.gr" +
"aphicData.Point\022\"\n\006pointC\030\010 \003(\0132\022.graphi" +
"cData.Point\022&\n\005paRef\030\t \001(\0132\027.graphicData" +
".RelatedRef\022&\n\005pbRef\030\n \001(\0132\027.graphicData" +
".RelatedRef\022&\n\005pcRef\030\013 \001(\0132\027.graphicData" +
".RelatedRef\0225\n\017kilometerSystem\030\r \003(\0132\034.g" +
"raphicData.KilometerSystem\">\n\017KilometerS" +
"ystem\022\021\n\tkilometer\030\001 \001(\003\022\030\n\020coordinateSy" +
"stem\030\002 \001(\t\"\206\001\n\006Signal\022\'\n\006common\030\001 \001(\0132\027." +
"graphicData.CommonInfo\022\014\n\004code\030\002 \001(\t\022\016\n\006" +
"mirror\030\003 \001(\010\0225\n\017kilometerSystem\030\006 \001(\0132\034." +
"graphicData.KilometerSystem\"\340\001\n\007RunLine\022" +
"\'\n\006common\030\001 \001(\0132\027.graphicData.CommonInfo" +
"\022\014\n\004code\030\002 \001(\t\022\"\n\006points\030\003 \003(\0132\022.graphic" +
"Data.Point\022\021\n\tnameColor\030\004 \001(\t\022\023\n\013nameBgC" +
"olor\030\005 \001(\t\022\022\n\ncontainSta\030\010 \003(\t\022\025\n\rlinkPa" +
"thLines\030\t \003(\t\022\016\n\006lineId\030\n \001(\t\022\027\n\017dashPoi" +
"ntIndexs\030\013 \003(\005\"\337\002\n\007Section\022\'\n\006common\030\001 \001" +
"(\0132\027.graphicData.CommonInfo\022\014\n\004code\030\002 \001(" +
"\t\022\025\n\rseparatorType\030\003 \001(\tB8\n!club.joylink" +
".xiannccda.dto.protosB\023LayoutGraphicsPro" +
"tob\006proto3"
"\t\022\"\n\006points\030\003 \003(\0132\022.graphicData.Point\022&\n" +
"\005paRef\030\004 \001(\0132\027.graphicData.RelatedRef\022&\n" +
"\005pbRef\030\005 \001(\0132\027.graphicData.RelatedRef\0225\n" +
"\013sectionType\030\006 \001(\0162 .graphicData.Section" +
".SectionType\022\025\n\raxleCountings\030\007 \003(\t\022\020\n\010c" +
"hildren\030\010 \003(\t\022\027\n\017destinationCode\030\t \001(\t\"0" +
"\n\013SectionType\022\014\n\010Physical\020\000\022\023\n\017TurnoutPh" +
"ysical\020\002\"i\n\014LogicSection\022\'\n\006common\030\001 \001(\013" +
"2\027.graphicData.CommonInfo\022\014\n\004code\030\002 \001(\t\022" +
"\"\n\006points\030\003 \003(\0132\022.graphicData.Point\"V\n\016K" +
"ilometerPoint\022!\n\005point\030\001 \001(\0132\022.graphicDa" +
"ta.Point\022\021\n\tkilometer\030\002 \001(\003\022\016\n\006stName\030\003 " +
"\001(\t\"\277\001\n\010PathLine\022\'\n\006common\030\001 \001(\0132\027.graph" +
"icData.CommonInfo\022\014\n\004code\030\002 \001(\t\022\"\n\006point" +
"s\030\003 \003(\0132\022.graphicData.Point\022\014\n\004isUp\030\004 \001(" +
"\010\0224\n\017kilometerPoints\030\005 \003(\0132\033.graphicData" +
".KilometerPoint\022\024\n\014isKmIncrease\030\006 \001(\010\"\366\001" +
"\n\nRelatedRef\0226\n\ndeviceType\030\001 \001(\0162\".graph" +
"icData.RelatedRef.DeviceType\022\n\n\002id\030\002 \001(\t" +
"\0226\n\ndevicePort\030\003 \001(\0162\".graphicData.Relat" +
"edRef.DevicePort\"I\n\nDeviceType\022\013\n\007Sectio" +
"n\020\000\022\013\n\007Turnout\020\001\022\017\n\013TrainWindow\020\002\022\020\n\014Axl" +
"eCounting\020\003\"!\n\nDevicePort\022\005\n\001A\020\000\022\005\n\001B\020\001\022" +
"\005\n\001C\020\002\"Y\n\tSeparator\022\'\n\006common\030\001 \001(\0132\027.gr" +
"aphicData.CommonInfo\022\014\n\004code\030\002 \001(\t\022\025\n\rse" +
"paratorType\030\003 \001(\tB8\n!club.joylink.xiannc" +
"cda.dto.protosB\023LayoutGraphicsProtob\006pro" +
"to3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
@ -40967,7 +40876,7 @@ public final class LayoutGraphicsProto {
internal_static_graphicData_Platform_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_graphicData_Platform_descriptor,
new java.lang.String[] { "Common", "Code", "Hasdoor", "Direction", "UpAndDown", "RefStation", });
new java.lang.String[] { "Common", "Code", "Hasdoor", "Direction", "RefStation", "Up", });
internal_static_graphicData_Station_descriptor =
getDescriptor().getMessageTypes().get(10);
internal_static_graphicData_Station_fieldAccessorTable = new

View File

@ -1,10 +1,13 @@
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;
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRecordConvertor;
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRemoveConvertor;
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainUpdateConvertor;
import club.joylink.xiannccda.ats.message.collect.convertor.TrainInitConvertor;
@ -18,29 +21,31 @@ 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;
/** 线路设备信息更新 */
@Slf4j
@Service
@RequiredArgsConstructor
public class LineDeviceStatusService {
private final WsMessageServerManager wsMessageServerManager;
private final NccMockDataService nccMockDataService;
public LineDeviceStatusService(
WsMessageServerManager wsMessageServerManager, NccMockDataService nccMockDataService) {
this.wsMessageServerManager = wsMessageServerManager;
this.nccMockDataService = nccMockDataService;
}
@PostConstruct
public void deviceStatusRefresh() {
this.createDataConvertor();
// 添加初始化转换方法
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainInitConvertor());
// 列车报点信息转换方法
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainRecordConvertor());
// 列车更新转换方法
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainUpdateConvertor());
// 列车删除转换方法
@ -50,6 +55,9 @@ public class LineDeviceStatusService {
wsMessageServerManager.registerMessageServer(new LineNetMessageServer());
wsMessageServerManager.registerMessageServer(new LineTrainMessageServer());
wsMessageServerManager.registerMessageServer(new LineDeviceMessageServer());
// 加载数据
refreshTestData();
}
private void createDataConvertor() {
@ -61,4 +69,34 @@ 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 edc9973662bc4f02198f72919de9408fa9ea9043
Subproject commit c9a07e75f06e8247d33f9e08c52d5045f1db2bc2