设备名称变更
This commit is contained in:
parent
d154d09855
commit
da6e506688
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.xiannccda.ats.cache;
|
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.DeviceInfoProto;
|
||||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
|
||||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
|
||||||
@ -18,15 +19,21 @@ import lombok.Getter;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/** 发布时缓存在内存中的线路数据 */
|
/**
|
||||||
|
* 发布时缓存在内存中的线路数据
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LineGraphicDataRepository {
|
public class LineGraphicDataRepository {
|
||||||
|
|
||||||
/** 线路数据信息 */
|
/**
|
||||||
|
* 线路数据信息
|
||||||
|
*/
|
||||||
private static final Map<Integer, Map<String, Map<String, Builder>>> lineGraphMap =
|
private static final Map<Integer, Map<String, Map<String, Builder>>> lineGraphMap =
|
||||||
new ConcurrentHashMap<>();
|
new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/** 线路各坐标系转换关系 */
|
/**
|
||||||
|
* 线路各坐标系转换关系
|
||||||
|
*/
|
||||||
private static final Map<Integer, Map<String, CoordinateConvertor>> lineCoordinateMain =
|
private static final Map<Integer, Map<String, CoordinateConvertor>> lineCoordinateMain =
|
||||||
new HashMap<>();
|
new HashMap<>();
|
||||||
|
|
||||||
@ -40,6 +47,7 @@ public class LineGraphicDataRepository {
|
|||||||
if (publishGi.getLineId() != null) {
|
if (publishGi.getLineId() != null) {
|
||||||
LayoutGraphicsProto.RtssGraphicStorage storage =
|
LayoutGraphicsProto.RtssGraphicStorage storage =
|
||||||
LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto());
|
LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto());
|
||||||
|
DeviceNameChanger.init(storage);
|
||||||
Map<String, Map<String, Builder>> lineDataMap = new HashMap<>();
|
Map<String, Map<String, Builder>> lineDataMap = new HashMap<>();
|
||||||
// 构建区段
|
// 构建区段
|
||||||
sectionInitLineGraph(publishGi.getLineId(), lineDataMap, storage);
|
sectionInitLineGraph(publishGi.getLineId(), lineDataMap, storage);
|
||||||
@ -57,7 +65,7 @@ public class LineGraphicDataRepository {
|
|||||||
/**
|
/**
|
||||||
* 获取线路上区段名为【sectionName】的公里标
|
* 获取线路上区段名为【sectionName】的公里标
|
||||||
*
|
*
|
||||||
* @param lineId 线路ID
|
* @param lineId 线路ID
|
||||||
* @param sectionName 区段名称
|
* @param sectionName 区段名称
|
||||||
* @return 公里标
|
* @return 公里标
|
||||||
*/
|
*/
|
||||||
@ -83,7 +91,9 @@ public class LineGraphicDataRepository {
|
|||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除线路绘图数据 */
|
/**
|
||||||
|
* 删除线路绘图数据
|
||||||
|
*/
|
||||||
public static void removeLineGraph(Integer id) {
|
public static void removeLineGraph(Integer id) {
|
||||||
lineGraphMap.remove(id);
|
lineGraphMap.remove(id);
|
||||||
}
|
}
|
||||||
@ -91,7 +101,7 @@ public class LineGraphicDataRepository {
|
|||||||
/**
|
/**
|
||||||
* 构建程序中的区段信息
|
* 构建程序中的区段信息
|
||||||
*
|
*
|
||||||
* @param lineId 线路ID
|
* @param lineId 线路ID
|
||||||
* @param dataMap 缓存数据
|
* @param dataMap 缓存数据
|
||||||
* @param storage 地图构建数据
|
* @param storage 地图构建数据
|
||||||
*/
|
*/
|
||||||
@ -120,7 +130,7 @@ public class LineGraphicDataRepository {
|
|||||||
/**
|
/**
|
||||||
* 构建道岔信息
|
* 构建道岔信息
|
||||||
*
|
*
|
||||||
* @param lineId 线路ID
|
* @param lineId 线路ID
|
||||||
* @param dataMap 缓存数据
|
* @param dataMap 缓存数据
|
||||||
* @param storage 地图构建数据
|
* @param storage 地图构建数据
|
||||||
*/
|
*/
|
||||||
@ -171,7 +181,7 @@ public class LineGraphicDataRepository {
|
|||||||
/**
|
/**
|
||||||
* 设置公里标
|
* 设置公里标
|
||||||
*
|
*
|
||||||
* @param lineId 线路ID
|
* @param lineId 线路ID
|
||||||
* @param dataMap 缓存数据
|
* @param dataMap 缓存数据
|
||||||
* @param storage 地图构建数据
|
* @param storage 地图构建数据
|
||||||
*/
|
*/
|
||||||
@ -222,7 +232,7 @@ public class LineGraphicDataRepository {
|
|||||||
/**
|
/**
|
||||||
* 初始化坐标转换对象
|
* 初始化坐标转换对象
|
||||||
*
|
*
|
||||||
* @param lineId 线路ID
|
* @param lineId 线路ID
|
||||||
* @param dataMap 设备集合
|
* @param dataMap 设备集合
|
||||||
* @param storage 地图信息
|
* @param storage 地图信息
|
||||||
*/
|
*/
|
||||||
@ -314,7 +324,9 @@ public class LineGraphicDataRepository {
|
|||||||
return convertorMap.get(convertorKey).convertorKilometer(kilometer, CoordinateEnum.MAIN_LINE);
|
return convertorMap.get(convertorKey).convertorKilometer(kilometer, CoordinateEnum.MAIN_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 坐标系枚举 */
|
/**
|
||||||
|
* 坐标系枚举
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private enum CoordinateEnum {
|
private enum CoordinateEnum {
|
||||||
MAIN_LINE("MAIN_LINE", List.of("YDK", "ZDK", "XDK", "SDK")),
|
MAIN_LINE("MAIN_LINE", List.of("YDK", "ZDK", "XDK", "SDK")),
|
||||||
@ -359,7 +371,9 @@ public class LineGraphicDataRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 坐标转换对象 */
|
/**
|
||||||
|
* 坐标转换对象
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private static class CoordinateConvertor {
|
private static class CoordinateConvertor {
|
||||||
|
|
||||||
@ -374,8 +388,8 @@ public class LineGraphicDataRepository {
|
|||||||
/**
|
/**
|
||||||
* 生成坐标转换对象
|
* 生成坐标转换对象
|
||||||
*
|
*
|
||||||
* @param configSystem 原配置坐标系信息
|
* @param configSystem 原配置坐标系信息
|
||||||
* @param convertorSystem 转换坐标系类型
|
* @param convertorSystem 转换坐标系类型
|
||||||
* @param convertorCoordinate 转换坐标
|
* @param convertorCoordinate 转换坐标
|
||||||
* @return 转换对象
|
* @return 转换对象
|
||||||
*/
|
*/
|
||||||
@ -427,7 +441,7 @@ public class LineGraphicDataRepository {
|
|||||||
* 将出入库公里标转换为正线标
|
* 将出入库公里标转换为正线标
|
||||||
*
|
*
|
||||||
* @param basisKilometer 出入库基准公里标
|
* @param basisKilometer 出入库基准公里标
|
||||||
* @param targetType 目标坐标系
|
* @param targetType 目标坐标系
|
||||||
* @return 正线公里标数字
|
* @return 正线公里标数字
|
||||||
*/
|
*/
|
||||||
public long convertorKilometer(KilometerSystem basisKilometer, CoordinateEnum targetType) {
|
public long convertorKilometer(KilometerSystem basisKilometer, CoordinateEnum targetType) {
|
||||||
|
@ -1,14 +1,28 @@
|
|||||||
package club.joylink.xiannccda.ats.message.line3;
|
package club.joylink.xiannccda.ats.message.line3;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||||
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
|
||||||
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RtssGraphicStorage;
|
||||||
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
|
||||||
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Signal;
|
||||||
|
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.protobuf.GeneratedMessageV3;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public abstract class DeviceNameChanger {
|
public abstract class DeviceNameChanger {
|
||||||
|
|
||||||
// abstract List<String> findAllDeviceName(JSONArray dataArray);
|
abstract void collectNames(LayoutGraphicsProto.RtssGraphicStorage graphicStorage);
|
||||||
|
|
||||||
abstract String changeDeviceName(String nccDeviceName);
|
abstract String changeDeviceName(String nccDeviceName, List<String> graphicNames);
|
||||||
|
|
||||||
static Map<DeviceType, DeviceNameChanger> NCC_DEVICE_TYPE_NAME_MAPPER = Maps.newHashMap();
|
static Map<DeviceType, DeviceNameChanger> NCC_DEVICE_TYPE_NAME_MAPPER = Maps.newHashMap();
|
||||||
|
|
||||||
@ -19,17 +33,36 @@ public abstract class DeviceNameChanger {
|
|||||||
// NCC_DEVICE_TYPE_NAME_MAPPER.put(DeviceType.DEVICE_TYPE_PLATFORM, "stationStandList");
|
// NCC_DEVICE_TYPE_NAME_MAPPER.put(DeviceType.DEVICE_TYPE_PLATFORM, "stationStandList");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final static Map<DeviceType, List<String>> DEVICE_NAMES = Maps.newHashMap();
|
||||||
|
|
||||||
|
|
||||||
|
public static void init(LayoutGraphicsProto.RtssGraphicStorage gs) {
|
||||||
|
for (DeviceNameChanger value : NCC_DEVICE_TYPE_NAME_MAPPER.values()) {
|
||||||
|
value.collectNames(gs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String nameMatch(DeviceType dt, String name) {
|
||||||
|
DeviceNameChanger nameChanger = NCC_DEVICE_TYPE_NAME_MAPPER.get(dt);
|
||||||
|
if (Objects.nonNull(nameChanger)) {
|
||||||
|
List<String> deviceNames = DEVICE_NAMES.get(dt);
|
||||||
|
nameChanger.changeDeviceName(name, deviceNames);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class SwitchDevice extends DeviceNameChanger {
|
public static class SwitchDevice extends DeviceNameChanger {
|
||||||
|
|
||||||
/* @Override
|
@Override
|
||||||
public List<String> findAllDeviceName(JSONArray dataArray) {
|
void collectNames(RtssGraphicStorage graphicStorage) {
|
||||||
List<String> mapDeviceNames = dataArray.stream().filter(d -> d instanceof JSONObject).map(d -> (JSONObject) d).map(d -> d.getString("name")).toList();
|
List<String> names = graphicStorage.getTurnoutsList().stream().map(Turnout::getCode).toList();
|
||||||
return mapDeviceNames;
|
DEVICE_NAMES.put(DeviceType.DEVICE_TYPE_SWITCH, names);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String changeDeviceName(String nccDeviceName) {
|
public String changeDeviceName(String nccDeviceName, List<String> graphicNames) {
|
||||||
if (nccDeviceName.length() < 3) {
|
if (nccDeviceName.length() < 3) {
|
||||||
return nccDeviceName;
|
return nccDeviceName;
|
||||||
}
|
}
|
||||||
@ -43,89 +76,105 @@ public abstract class DeviceNameChanger {
|
|||||||
|
|
||||||
public static class TrackDevice extends DeviceNameChanger {
|
public static class TrackDevice extends DeviceNameChanger {
|
||||||
|
|
||||||
/* @Override
|
|
||||||
List<String> findAllDeviceName(JSONArray dataArray) {
|
|
||||||
Map<String, JSONObject> jsonMap = dataArray.stream().filter(d -> d instanceof JSONObject).map(d -> (JSONObject) d).collect(Collectors.toMap((d) -> d.getString("code"), Function.identity()));
|
|
||||||
List<String> newNames = Lists.newArrayList();
|
|
||||||
for (JSONObject value : jsonMap.values()) {
|
|
||||||
// JSONArray hasLogic = value.getJSONArray("logicSectionList");
|
|
||||||
String physicsTrackCode = value.getString("parentCode");
|
|
||||||
String name = value.getString("name");
|
|
||||||
if (StringUtils.isEmpty(physicsTrackCode)) {
|
|
||||||
newNames.add(name);
|
|
||||||
} else {
|
|
||||||
JSONObject physicsTrack = jsonMap.get(physicsTrackCode);
|
|
||||||
String pn = physicsTrack.getString("name");
|
|
||||||
newNames.add(pn + name);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newNames;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String changeDeviceName(String nccDeviceName) {
|
void collectNames(RtssGraphicStorage graphicStorage) {
|
||||||
|
List<String> names = graphicStorage.getSectionList().stream().map(Section::getCode).toList();
|
||||||
|
DEVICE_NAMES.put(DeviceType.DEVICE_TYPE_TRACK, names);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String changeDeviceName(String nccDeviceName, List<String> graphicNames) {
|
||||||
if (nccDeviceName.length() < 4) {
|
if (nccDeviceName.length() < 4) {
|
||||||
return nccDeviceName;
|
return nccDeviceName;
|
||||||
}
|
}
|
||||||
if (nccDeviceName.startsWith("T") && nccDeviceName.contains("_")) {
|
Pattern regex = Pattern.compile("^([A-Za-z]{1,2})(.*?)$");
|
||||||
return nccDeviceName.substring(1);
|
Matcher matcher = regex.matcher(nccDeviceName);
|
||||||
} else if (nccDeviceName.matches("^[A-Za-z]{2}.*?")) {
|
String newName = "";
|
||||||
String head = nccDeviceName.substring(2, 4);
|
String code = "";
|
||||||
String tail = nccDeviceName.substring(5);
|
if (matcher.find()) {
|
||||||
String tailEnd = "";
|
code = matcher.group(2);
|
||||||
if (tail.matches(".*?[A-Z]$")) {
|
if (StringUtils.contains(code, "_")) {
|
||||||
tail = nccDeviceName.substring(4, nccDeviceName.length() - 1);
|
newName = code;
|
||||||
tailEnd = nccDeviceName.substring(nccDeviceName.length() - 1);
|
} else {
|
||||||
|
String head = code.substring(0, 2);
|
||||||
|
String end = code.substring(3);
|
||||||
|
String tail = "";
|
||||||
|
if (code.matches(".*?[A-Z]$")) {
|
||||||
|
tail = end.substring(end.length() - 1);
|
||||||
|
}
|
||||||
|
newName = end + head + tail;
|
||||||
}
|
}
|
||||||
return "G" + tail + head + tailEnd;
|
|
||||||
} else if (nccDeviceName.matches(".*?[A-Z]$")) {
|
|
||||||
String head = nccDeviceName.substring(1, 3);
|
|
||||||
String tail = nccDeviceName.substring(4);
|
|
||||||
String tailEnd = "";
|
|
||||||
if (tail.matches(".*?[A-Z]$")) {
|
|
||||||
tail = nccDeviceName.substring(4, nccDeviceName.length() - 1);
|
|
||||||
tailEnd = nccDeviceName.substring(nccDeviceName.length() - 1);
|
|
||||||
}
|
|
||||||
return "G" + tail + head + tailEnd;
|
|
||||||
} else {
|
|
||||||
return "S" + nccDeviceName;
|
|
||||||
}
|
}
|
||||||
|
final String finalName = newName;
|
||||||
|
final String finalCode = code;
|
||||||
|
String finder = graphicNames.stream().filter(d -> StringUtils.equals(d, finalName) || StringUtils.endsWithIgnoreCase(d, finalCode)).findFirst().orElse(null);
|
||||||
|
if (Objects.nonNull(finder)) {
|
||||||
|
return finder;
|
||||||
|
}
|
||||||
|
return nccDeviceName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class SignalDevice extends DeviceNameChanger {
|
public static class SignalDevice extends DeviceNameChanger {
|
||||||
|
|
||||||
/* @Override
|
@Override
|
||||||
List<String> findAllDeviceName(JSONArray dataArray) {
|
void collectNames(RtssGraphicStorage graphicStorage) {
|
||||||
List<String> mapDeviceNames = dataArray.stream().filter(d -> d instanceof JSONObject).map(d -> (JSONObject) d).map(d -> d.getString("name")).toList();
|
List<String> names = graphicStorage.getSignalsList().stream().map(Signal::getCode).toList();
|
||||||
return mapDeviceNames;
|
DEVICE_NAMES.put(DeviceType.DEVICE_TYPE_SIGNAL, names);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String changeDeviceName(String nccDeviceName) {
|
String changeDeviceName(String nccDeviceName, List<String> graphicNames) {
|
||||||
if (nccDeviceName.length() <= 3) {
|
if (nccDeviceName.length() <= 3) {
|
||||||
return nccDeviceName;
|
return nccDeviceName;
|
||||||
}
|
}
|
||||||
String started = nccDeviceName.substring(0, 1);
|
Pattern regex = Pattern.compile("^([A-Za-z]{1,2})(.*?)$");
|
||||||
String head = nccDeviceName.substring(1, 3);
|
Matcher matcher = regex.matcher(nccDeviceName);
|
||||||
String tail = nccDeviceName.substring(4);
|
String newName = "";
|
||||||
return started + tail + head;
|
String code = "";
|
||||||
|
if (matcher.find()) {
|
||||||
|
code = matcher.group(2);
|
||||||
|
if (StringUtils.contains(code, "_")) {
|
||||||
|
newName = code;
|
||||||
|
} else {
|
||||||
|
String head = code.substring(0, 2);
|
||||||
|
String end = code.substring(3);
|
||||||
|
String tail = "";
|
||||||
|
if (code.matches(".*?[A-Z]$")) {
|
||||||
|
tail = end.substring(end.length() - 1);
|
||||||
|
}
|
||||||
|
newName = end + head + tail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final String finalName = newName.replaceAll("_", "-");
|
||||||
|
final String finalCode = code.replaceAll("_", "-");
|
||||||
|
String finder = graphicNames.stream().filter(d -> StringUtils.equals(d, finalName) || StringUtils.endsWithIgnoreCase(d, finalCode)).findFirst().orElse(null);
|
||||||
|
if (Objects.nonNull(finder)) {
|
||||||
|
return finder;
|
||||||
|
}
|
||||||
|
return nccDeviceName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public static class PlatformDevice extends Device {
|
public static void main(String[] args) {
|
||||||
|
String nccDeviceName = "TP_2DG";
|
||||||
@Override
|
Pattern regex = Pattern.compile("^([A-Za-z]{1,2})(.*?)$");
|
||||||
List<String> findAllDeviceName(JSONArray dataArray) {
|
Matcher matcher = regex.matcher(nccDeviceName);
|
||||||
return null;
|
String newName = "";
|
||||||
|
String code = "";
|
||||||
|
if (matcher.find()) {
|
||||||
|
code = matcher.group(2);
|
||||||
|
String head = code.substring(0, 2);
|
||||||
|
String end = code.substring(3);
|
||||||
|
String tail = "";
|
||||||
|
if (code.matches(".*?[A-Z]$")) {
|
||||||
|
tail = end.substring(end.length() - 1);
|
||||||
|
}
|
||||||
|
newName = end + head + tail;
|
||||||
|
System.out.println(newName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
String changeDeviceName(String nccDeviceName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user