Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java # xian-ncc-da-message
This commit is contained in:
commit
14454be2dc
@ -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();
|
||||
|
@ -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.CommonInfo;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
|
||||
@ -26,34 +28,25 @@ 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<>();
|
||||
|
||||
/**
|
||||
* 线路-设备code-设备
|
||||
*/
|
||||
private static final HashBasedTable<Integer, String, MessageOrBuilder> line_code_table =
|
||||
/** 线路-设备code-设备 */
|
||||
private static final HashBasedTable<Short, String, MessageOrBuilder> line_code_table =
|
||||
HashBasedTable.create();
|
||||
|
||||
/**
|
||||
* 线路-设备id-设备
|
||||
*/
|
||||
private static final HashBasedTable<Integer, String, MessageOrBuilder> line_id_table = HashBasedTable.create();
|
||||
/** 线路-设备id-设备 */
|
||||
private static final HashBasedTable<Short, String, MessageOrBuilder> line_id_table =
|
||||
HashBasedTable.create();
|
||||
|
||||
/**
|
||||
* 缓存线路数据信息
|
||||
@ -68,13 +61,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
|
||||
@ -88,18 +85,18 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 获取线路上区段名为【sectionName】的公里标
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,16 +104,14 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除线路绘图数据
|
||||
*/
|
||||
/** 删除线路绘图数据 */
|
||||
public static void removeLineGraph(Integer id) {
|
||||
lineGraphMap.remove(id);
|
||||
}
|
||||
@ -165,55 +160,59 @@ public class LineGraphicDataRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取线路的区段集合
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @return 区段集合
|
||||
*/
|
||||
public static Map<String, Builder> getLineSectionBuild(int lineId) {
|
||||
Map<String, Map<String, Builder>> lineDataMap = lineGraphMap.get(lineId);
|
||||
if (CollectionUtils.isNotEmpty(lineDataMap)) {
|
||||
return lineDataMap.get(DeviceType.Section.name());
|
||||
}
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建程序中的区段信息
|
||||
*
|
||||
* @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) {
|
||||
sectionBuilder.addAllChildrenId(section.getChildrenList());
|
||||
// 初始化逻辑区段信息,建立逻辑区段与物理区段之间的关系
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建道岔信息
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 缓存数据
|
||||
* @param storage 地图构建数据
|
||||
*/
|
||||
@ -234,37 +233,56 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置公里标
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 缓存数据
|
||||
* @param storage 地图构建数据
|
||||
*/
|
||||
@ -285,27 +303,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);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -315,7 +329,7 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 初始化坐标转换对象
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param lineId 线路ID
|
||||
* @param dataMap 设备集合
|
||||
* @param storage 地图信息
|
||||
*/
|
||||
@ -343,8 +357,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) {
|
||||
@ -387,6 +401,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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 公里标转换
|
||||
*
|
||||
@ -426,32 +483,134 @@ 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); // 最大公里标
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 坐标系枚举
|
||||
* <<<<<<< HEAD 生成默认的公里标对象
|
||||
*
|
||||
* @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 {
|
||||
MAIN_LINE("MAIN_LINE", List.of("YDK", "ZDK", "XDK", "SDK")),
|
||||
@ -496,9 +655,7 @@ public class LineGraphicDataRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 坐标转换对象
|
||||
*/
|
||||
/** 坐标转换对象 */
|
||||
@Getter
|
||||
private static class CoordinateConvertor {
|
||||
|
||||
@ -513,8 +670,8 @@ public class LineGraphicDataRepository {
|
||||
/**
|
||||
* 生成坐标转换对象
|
||||
*
|
||||
* @param configSystem 原配置坐标系信息
|
||||
* @param convertorSystem 转换坐标系类型
|
||||
* @param configSystem 原配置坐标系信息
|
||||
* @param convertorSystem 转换坐标系类型
|
||||
* @param convertorCoordinate 转换坐标
|
||||
* @return 转换对象
|
||||
*/
|
||||
@ -566,7 +723,7 @@ public class LineGraphicDataRepository {
|
||||
* 将出入库公里标转换为正线标
|
||||
*
|
||||
* @param basisKilometer 出入库基准公里标
|
||||
* @param targetType 目标坐标系
|
||||
* @param targetType 目标坐标系
|
||||
* @return 正线公里标数字
|
||||
*/
|
||||
public long convertorKilometer(KilometerSystem basisKilometer, CoordinateEnum targetType) {
|
||||
|
@ -6,11 +6,14 @@ import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository;
|
||||
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;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** 线网的列车数据,一些公共方法 */
|
||||
@ -51,27 +54,116 @@ public abstract class LineNetTrainComMethod {
|
||||
*/
|
||||
public static void setUpKilometerCode(
|
||||
WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj, DeviceType type, String deviceName) {
|
||||
// 非区段、道岔直接返回
|
||||
if (!DeviceType.DEVICE_TYPE_TRACK.equals(type) && !DeviceType.DEVICE_TYPE_SWITCH.equals(type)) {
|
||||
// 获取到当前区段公里标
|
||||
DeviceKilometer.Builder km = getDeviceKM(obj.getLineId(), type, deviceName);
|
||||
if (km != null) {
|
||||
obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), km));
|
||||
} else {
|
||||
log.warn(String.format("设备%s没有公里标信息", deviceName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据目的码确定方向,并确定公里标
|
||||
*
|
||||
* @param obj 要设置的对象
|
||||
* @param destinationCode 目的码
|
||||
* @param type 设备类型
|
||||
* @param name 设备名称
|
||||
*/
|
||||
public static void setTrainDirectionAndKilometerCode(
|
||||
WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj,
|
||||
String destinationCode,
|
||||
DeviceType type,
|
||||
String name) {
|
||||
DeviceKilometer.Builder deviceKm = getDeviceKM(obj.getLineId(), type, name);
|
||||
if (deviceKm == null) {
|
||||
return;
|
||||
}
|
||||
// 转换成程序中的名称
|
||||
String convertName = DeviceNameChangerManage.findMatch(type, deviceName);
|
||||
// 获取到当前区段公里标
|
||||
List<Long> kmList =
|
||||
LineGraphicDataRepository.getKilometerCodeList(obj.getLineId(), convertName);
|
||||
if (CollectionUtils.isNotEmpty(kmList)) {
|
||||
long kilometer;
|
||||
if (obj.getDir() == 1) { // 下行取大值
|
||||
kilometer = kmList.stream().min(Long::compareTo).get();
|
||||
} else if (obj.getDir() == 2) { // 上行取小值
|
||||
kilometer = kmList.stream().max(Long::compareTo).get();
|
||||
} else { // 无方向获取第一个
|
||||
kilometer = kmList.get(0);
|
||||
}
|
||||
obj.setKilometerCode(kilometer);
|
||||
DeviceKilometer.Builder destinationKm = getDirectionCodeKM(obj.getLineId(), destinationCode);
|
||||
if (destinationKm == null) {
|
||||
return;
|
||||
}
|
||||
// 确定方向
|
||||
if (destinationKm.getMaxKilometer() > deviceKm.getMaxKilometer()) { // 目的地最大公里标大于设备最大公里标,上行
|
||||
obj.setDir(TrainRunDirection.UP.getDir());
|
||||
} else {
|
||||
log.warn(String.format("设备%s没有公里标信息", convertName));
|
||||
obj.setDir(TrainRunDirection.DOWN.getDir());
|
||||
}
|
||||
// 赋值公里标
|
||||
obj.setKilometerCode(selectDeviceKilometerCode(obj.getDir(), deviceKm));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备的公里标
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param type 设备类型
|
||||
* @param name 设备名称
|
||||
* @return 公里标列表
|
||||
*/
|
||||
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 null;
|
||||
}
|
||||
// 转换成程序中的名称
|
||||
String convertName = DeviceNameChangerManage.findMatch(type, name);
|
||||
// 获取到当前区段公里标
|
||||
return LineGraphicDataRepository.getKilometerCodeList(lineId, convertName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取目的地码的公里标信息
|
||||
*
|
||||
* @param lineId 线路ID
|
||||
* @param code 目的地码
|
||||
* @return 公里标列表
|
||||
*/
|
||||
private static DeviceKilometer.Builder getDirectionCodeKM(int lineId, String code) {
|
||||
Map<String, Builder> map = LineGraphicDataRepository.getLineSectionBuild(lineId);
|
||||
Optional<Builder> destination =
|
||||
map.values().stream()
|
||||
.filter(
|
||||
s -> {
|
||||
DeviceInfoProto.Section.Builder b = (DeviceInfoProto.Section.Builder) s;
|
||||
return Objects.equals(b.getDestinationCode(), code);
|
||||
})
|
||||
.findFirst();
|
||||
if (destination.isPresent()) {
|
||||
DeviceInfoProto.Section.Builder b = (DeviceInfoProto.Section.Builder) destination.get();
|
||||
return b.getKilometerBuilder();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择对应的公里标信息
|
||||
*
|
||||
* @param dir 运行方向
|
||||
* @param km 公里标信息
|
||||
* @return 公里标
|
||||
*/
|
||||
private static long selectDeviceKilometerCode(int dir, DeviceKilometer.Builder km) {
|
||||
// 下行(1)取小值 \ 上行(2)取大值
|
||||
return TrainRunDirection.UP.isMatch(dir) ? km.getMaxKilometer() : km.getMinKilometer();
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static enum TrainRunDirection {
|
||||
UP(2),
|
||||
DOWN(1),
|
||||
NO(0);
|
||||
|
||||
private int dir;
|
||||
|
||||
TrainRunDirection(int dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public boolean isMatch(int dir) {
|
||||
return this.dir == dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,8 @@ public class LineNetTrainInitConvertor extends DeviceStatusConvertor {
|
||||
offset.setLineId(response.getLineId()); // 线路id
|
||||
offset.setTrainIndex(trainCell.getTrainIndex()); // 列车标示号,全线唯一
|
||||
offset.setGroupId(trainCell.getGroupId()); // 车组号
|
||||
offset.setDir(0); // 初始设置无运行方向
|
||||
LineNetTrainComMethod.setUpKilometerCode(
|
||||
offset, trainCell.getDevType(), trainCell.getDevName());
|
||||
LineNetTrainComMethod.setTrainDirectionAndKilometerCode(
|
||||
offset, trainCell.getDestinationId(), trainCell.getDevType(), trainCell.getDevName());
|
||||
offset.setShow(offset.getKilometerCode() != 0);
|
||||
buildList.add(offset);
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor {
|
||||
offset.setTrainIndex(response.getTrainIndex()); // 列车标示号,全线唯一
|
||||
offset.setGroupId(response.getGroupId()); // 车组号
|
||||
LineNetTrainComMethod.getDeviceStatusById(offset); // 合并老旧数据
|
||||
LineNetTrainComMethod.setUpKilometerCode(
|
||||
offset, response.getDevType(), response.getDevName());
|
||||
LineNetTrainComMethod.setTrainDirectionAndKilometerCode(
|
||||
offset, response.getDestinationId(), response.getDevType(), response.getDevName());
|
||||
offset.setShow(offset.getKilometerCode() != 0);
|
||||
buildList.add(offset);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,28 +20,25 @@ 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;
|
||||
|
||||
/** 线路设备信息更新 */
|
||||
@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();
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e9ebd34921652f48c2d84ac531e392ce32d17bb5
|
||||
Subproject commit b3b9885e2784cdad86901303e0bb9abf28c35e10
|
Loading…
Reference in New Issue
Block a user