From 203e1cc5218cd6273fe494752618bb6bbb8e7562 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 6 Jul 2023 14:03:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=BF=A1=E6=81=AF=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ats/cache/LineGraphicDataRepository.java | 73 +++++++++++++------ xian-ncc-da-message | 2 +- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java index d6ec87a..56b0c74 100644 --- a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -45,7 +44,7 @@ public class LineGraphicDataRepository { // 构建区段 sectionInitLineGraph(publishGi.getLineId(), lineDataMap, storage); // 构建道岔 - switchInitLineGraph(publishGi.getLineId(), lineDataMap, storage); + turnoutInitLineGraph(publishGi.getLineId(), lineDataMap, storage); // 设置公里标 setUpKilometerCode(publishGi.getLineId(), lineDataMap, storage); lineGraphMap.put(publishGi.getLineId(), lineDataMap); @@ -130,23 +129,47 @@ public class LineGraphicDataRepository { * @param dataMap 缓存数据 * @param storage 地图构建数据 */ - private static void switchInitLineGraph( + private static void turnoutInitLineGraph( Integer lineId, Map> dataMap, LayoutGraphicsProto.RtssGraphicStorage storage) { - Map cacheSwitchMap = - storage.getTurnoutsList().stream() - .collect( - Collectors.toMap( - t -> t.getCommon().getId(), - t -> { - DeviceInfoProto.Turnout.Builder switchBuilder = - DeviceInfoProto.Turnout.newBuilder(); - switchBuilder.setId(t.getCommon().getId()); - switchBuilder.setCode(t.getCode()); - switchBuilder.addAllKilometerSystem(t.getKilometerSystemList()); - return switchBuilder; - })); + Map convertorMap = + lineCoordinateMain.computeIfAbsent(lineId, id -> new HashMap<>()); + Map cacheSwitchMap = new HashMap<>(storage.getTurnoutsList().size()); + storage.getTurnoutsList().stream() + .forEach( + t -> { + List systemList = + t.getKilometerSystemList().stream() + .filter(k -> StringUtils.isNotEmpty(k.getCoordinateSystem())) + .toList(); + DeviceInfoProto.Turnout.Builder turnoutBuilder = DeviceInfoProto.Turnout.newBuilder(); + turnoutBuilder.setId(t.getCommon().getId()); + turnoutBuilder.setCode(t.getCode()); + turnoutBuilder.addAllKilometerSystem(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())); + } + } + } + } + } + }); dataMap.put(DeviceType.Turnout.name(), cacheSwitchMap); } @@ -163,8 +186,8 @@ public class LineGraphicDataRepository { LayoutGraphicsProto.RtssGraphicStorage storage) { // 初始化转换信息 initConvertorCoordinate(lineId, dataMap, storage); - Map sectionMap = dataMap.get(DeviceType.Section.name()); - Map turnoutMap = dataMap.get(DeviceType.Turnout.name()); + Map sectionMap = dataMap.getOrDefault(DeviceType.Section.name(), Map.of()); + Map turnoutMap = dataMap.getOrDefault(DeviceType.Turnout.name(), Map.of()); storage.getAxleCountingsList().stream() .filter(ac -> StringUtils.isNotEmpty(ac.getKilometerSystem().getCoordinateSystem())) .forEach( @@ -212,7 +235,14 @@ public class LineGraphicDataRepository { Integer lineId, Map> dataMap, LayoutGraphicsProto.RtssGraphicStorage storage) { - Map turnoutMap = dataMap.getOrDefault(DeviceType.Turnout.name(), Map.of()); + // 强制转换道岔 + Map turnoutMap = dataMap.get(DeviceType.Turnout.name()); + if (CollectionUtils.isEmpty(turnoutMap)) { + return; + } + Map convertorMap = + lineCoordinateMain.computeIfAbsent(lineId, id -> new HashMap<>()); + // 从计轴中转换信息 storage .getAxleCountingsList() .forEach( @@ -225,8 +255,7 @@ public class LineGraphicDataRepository { DeviceType.Turnout.equals(ref.getDeviceType()) && turnoutMap.containsKey(ref.getId())) .map(ref -> (DeviceInfoProto.Turnout.Builder) turnoutMap.get(ref.getId())) - .filter(turnout -> turnout.getKilometerSystemList().size() != 0) - .map(turnout -> turnout.getKilometerSystemList().get(0)) + .map(t -> t.getKilometerSystemList().get(0)) .toList(); // 如果关联多个道岔 if (kilometerSystemList.size() > 1) { @@ -252,8 +281,6 @@ public class LineGraphicDataRepository { String convertorKey = CoordinateConvertor.generateConvertorKey( axleSystem.getCoordinateSystem(), diffSystem.getCoordinateSystem()); - Map convertorMap = - lineCoordinateMain.computeIfAbsent(lineId, id -> new HashMap<>()); if (!convertorMap.containsKey(convertorKey)) { // 计轴与相同坐标系岔心之间差值 long diffValue = axleSystem.getKilometer() - sameSystem.getKilometer(); diff --git a/xian-ncc-da-message b/xian-ncc-da-message index 1ab5b1a..8fd000d 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit 1ab5b1ae7fd44e5b31e424407f3b783b40190c95 +Subproject commit 8fd000d45907f94410786c3bd6c1ab37edbe91e8