【修改逻辑区段初始化逻辑】
This commit is contained in:
parent
ad9464b5d8
commit
f82fc994eb
@ -1,11 +1,11 @@
|
||||
package club.joylink.xiannccda.ats.cache;
|
||||
|
||||
import club.joylink.xiannccda.ats.message.line3.DeviceNameChanger;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceInfoProto;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RelatedRef.DeviceType;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
|
||||
import club.joylink.xiannccda.entity.PublishedGi;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||
@ -19,21 +19,15 @@ import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 发布时缓存在内存中的线路数据
|
||||
*/
|
||||
/** 发布时缓存在内存中的线路数据 */
|
||||
@Slf4j
|
||||
public class LineGraphicDataRepository {
|
||||
|
||||
/**
|
||||
* 线路数据信息
|
||||
*/
|
||||
/** 线路数据信息 */
|
||||
private static final Map<Integer, Map<String, Map<String, Builder>>> lineGraphMap =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 线路各坐标系转换关系
|
||||
*/
|
||||
/** 线路各坐标系转换关系 */
|
||||
private static final Map<Integer, Map<String, CoordinateConvertor>> lineCoordinateMain =
|
||||
new HashMap<>();
|
||||
|
||||
@ -47,14 +41,16 @@ public class LineGraphicDataRepository {
|
||||
if (publishGi.getLineId() != null) {
|
||||
LayoutGraphicsProto.RtssGraphicStorage storage =
|
||||
LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto());
|
||||
// DeviceNameChanger.init(storage);
|
||||
// DeviceNameChanger.init(storage);
|
||||
Map<String, Map<String, Builder>> lineDataMap = new HashMap<>();
|
||||
// 构建区段
|
||||
sectionInitLineGraph(publishGi.getLineId(), lineDataMap, storage);
|
||||
sectionInitLineGraph(lineDataMap, storage);
|
||||
// 构建道岔
|
||||
turnoutInitLineGraph(publishGi.getLineId(), lineDataMap, storage);
|
||||
// 设置公里标
|
||||
setUpKilometerCode(publishGi.getLineId(), lineDataMap, storage);
|
||||
// 设置公里标后,开始构建逻辑区段的编码、公里标信息
|
||||
setUpLogicSectionInfo(lineDataMap, storage);
|
||||
lineGraphMap.put(publishGi.getLineId(), lineDataMap);
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
@ -65,7 +61,7 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 获取线路上区段名为【sectionName】的公里标
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param sectionName 区段名称
|
||||
* @return 公里标
|
||||
*/
|
||||
@ -91,9 +87,7 @@ public class LineGraphicDataRepository {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除线路绘图数据
|
||||
*/
|
||||
/** 删除线路绘图数据 */
|
||||
public static void removeLineGraph(Integer id) {
|
||||
lineGraphMap.remove(id);
|
||||
}
|
||||
@ -101,37 +95,52 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 构建程序中的区段信息
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 缓存数据
|
||||
* @param storage 地图构建数据
|
||||
*/
|
||||
private static void sectionInitLineGraph(
|
||||
Integer lineId,
|
||||
Map<String, Map<String, Builder>> dataMap,
|
||||
LayoutGraphicsProto.RtssGraphicStorage storage) {
|
||||
Map<String, Map<String, Builder>> dataMap, LayoutGraphicsProto.RtssGraphicStorage storage) {
|
||||
// 地图
|
||||
List<Section> sectionList = storage.getSectionList();
|
||||
// 存储的地图数据
|
||||
// 物理区段数据
|
||||
Map<String, Builder> cacheSectionMap = new HashMap<>(sectionList.size());
|
||||
sectionList.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);
|
||||
sectionBuilder.setCode(section.getCode());
|
||||
// 暂时先注释,等数据正确后再做处理
|
||||
// sectionBuilder.setType(section.getSectionType());
|
||||
cacheSectionMap.put(sid, sectionBuilder);
|
||||
});
|
||||
// 要保存的逻辑区段信息,预设值[section数量 * 【ABCD】]
|
||||
Map<String, Builder> cacheLogicSectionMap = new HashMap<>(sectionList.size() * 4);
|
||||
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);
|
||||
sectionBuilder.setCode(section.getCode());
|
||||
if (section.getChildrenCount() > 0) {
|
||||
sectionBuilder.getChildrenIdList().addAll(section.getChildrenList());
|
||||
// 初始化逻辑区段信息,建立逻辑区段与物理区段之间的关系
|
||||
section
|
||||
.getChildrenList()
|
||||
.forEach(
|
||||
id ->
|
||||
cacheLogicSectionMap.put(
|
||||
id,
|
||||
DeviceInfoProto.Section.newBuilder()
|
||||
.setId(id)
|
||||
.setPhysicalSectionId(sid)));
|
||||
}
|
||||
cacheSectionMap.put(sid, sectionBuilder);
|
||||
});
|
||||
// 将逻辑区段信息放入区段集合中
|
||||
cacheSectionMap.putAll(cacheLogicSectionMap);
|
||||
dataMap.put(DeviceType.Section.name(), cacheSectionMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建道岔信息
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 缓存数据
|
||||
* @param storage 地图构建数据
|
||||
*/
|
||||
@ -182,7 +191,7 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 设置公里标
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 缓存数据
|
||||
* @param storage 地图构建数据
|
||||
*/
|
||||
@ -233,7 +242,7 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 初始化坐标转换对象
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 设备集合
|
||||
* @param storage 地图信息
|
||||
*/
|
||||
@ -326,8 +335,47 @@ public class LineGraphicDataRepository {
|
||||
}
|
||||
|
||||
/**
|
||||
* 坐标系枚举
|
||||
* 构建逻辑区段的编码、公里标信息
|
||||
*
|
||||
* @param dataMap 设备集合
|
||||
* @param storage 地图信息
|
||||
*/
|
||||
private static void setUpLogicSectionInfo(
|
||||
Map<String, Map<String, Builder>> dataMap, LayoutGraphicsProto.RtssGraphicStorage storage) {
|
||||
Map<String, Builder> sectionMap = dataMap.getOrDefault(DeviceType.Section.name(), Map.of());
|
||||
if (sectionMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
storage
|
||||
.getLogicSectionsList()
|
||||
.forEach(
|
||||
section -> {
|
||||
String sid = section.getCommon().getId();
|
||||
if (sectionMap.containsKey(sid)) {
|
||||
DeviceInfoProto.Section.Builder sectionBuilder =
|
||||
(DeviceInfoProto.Section.Builder) sectionMap.get(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();
|
||||
long avgDistance = (max - min) / physicalSection.getChildrenIdCount();
|
||||
int index = physicalSection.getChildrenIdList().indexOf(sid);
|
||||
// 最小公里标
|
||||
sectionBuilder.getConvertKilometerList().add(min + index * avgDistance);
|
||||
// 最大公里标
|
||||
sectionBuilder.getConvertKilometerList().add(min + (index + 1) * avgDistance);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 坐标系枚举 */
|
||||
@Getter
|
||||
private enum CoordinateEnum {
|
||||
MAIN_LINE("MAIN_LINE", List.of("YDK", "ZDK", "XDK", "SDK")),
|
||||
@ -372,9 +420,7 @@ public class LineGraphicDataRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 坐标转换对象
|
||||
*/
|
||||
/** 坐标转换对象 */
|
||||
@Getter
|
||||
private static class CoordinateConvertor {
|
||||
|
||||
@ -389,8 +435,8 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 生成坐标转换对象
|
||||
*
|
||||
* @param configSystem 原配置坐标系信息
|
||||
* @param convertorSystem 转换坐标系类型
|
||||
* @param configSystem 原配置坐标系信息
|
||||
* @param convertorSystem 转换坐标系类型
|
||||
* @param convertorCoordinate 转换坐标
|
||||
* @return 转换对象
|
||||
*/
|
||||
@ -442,7 +488,7 @@ public class LineGraphicDataRepository {
|
||||
* 将出入库公里标转换为正线标
|
||||
*
|
||||
* @param basisKilometer 出入库基准公里标
|
||||
* @param targetType 目标坐标系
|
||||
* @param targetType 目标坐标系
|
||||
* @return 正线公里标数字
|
||||
*/
|
||||
public long convertorKilometer(KilometerSystem basisKilometer, CoordinateEnum targetType) {
|
||||
|
Loading…
Reference in New Issue
Block a user