From a50aaeaadf65f567b2db67a36f1fb9459d5a6f16 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Wed, 19 Jul 2023 10:10:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=90=8D=E7=A7=B0=E5=8F=98?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ats/cache/LineGraphicDataRepository.java | 42 ++++--- .../ats/message/OccMessageManage.java | 14 ++- .../ats/message/XianOccMessagingClient.java | 14 +-- .../ats/message/line3/DeviceNameChanger.java | 1 + .../changer/DeviceNameChangerManage.java | 115 ++++++++++++++++++ .../line3/changer/NameChangerFilter.java | 14 +++ .../message/line3/changer/SignalChanger.java | 63 ++++++++++ .../message/line3/changer/SwitchChanger.java | 26 ++++ .../message/line3/changer/TrackChanger.java | 96 +++++++++++++++ src/main/resources/application-dev.yml | 5 + src/main/resources/application-prod.yml | 8 +- src/main/resources/application.yml | 2 +- .../joylink/xiannccda/util/CollectorData.java | 24 ---- .../club/joylink/xiannccda/util/Device.java | 32 +---- 14 files changed, 381 insertions(+), 75 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/line3/changer/DeviceNameChangerManage.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/line3/changer/NameChangerFilter.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SignalChanger.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SwitchChanger.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/line3/changer/TrackChanger.java 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 82837e7..ec2d257 100644 --- a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java @@ -19,15 +19,21 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -/** 发布时缓存在内存中的线路数据 */ +/** + * 发布时缓存在内存中的线路数据 + */ @Slf4j public class LineGraphicDataRepository { - /** 线路数据信息 */ + /** + * 线路数据信息 + */ private static final Map>> lineGraphMap = new ConcurrentHashMap<>(); - /** 线路各坐标系转换关系 */ + /** + * 线路各坐标系转换关系 + */ private static final Map> lineCoordinateMain = new HashMap<>(); @@ -41,7 +47,7 @@ public class LineGraphicDataRepository { if (publishGi.getLineId() != null) { LayoutGraphicsProto.RtssGraphicStorage storage = LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto()); - DeviceNameChanger.init(storage); +// DeviceNameChanger.init(storage); Map> lineDataMap = new HashMap<>(); // 构建区段 sectionInitLineGraph(publishGi.getLineId(), lineDataMap, storage); @@ -59,7 +65,7 @@ public class LineGraphicDataRepository { /** * 获取线路上区段名为【sectionName】的公里标 * - * @param lineId 线路ID + * @param lineId 线路ID * @param sectionName 区段名称 * @return 公里标 */ @@ -85,7 +91,9 @@ public class LineGraphicDataRepository { return List.of(); } - /** 删除线路绘图数据 */ + /** + * 删除线路绘图数据 + */ public static void removeLineGraph(Integer id) { lineGraphMap.remove(id); } @@ -93,7 +101,7 @@ public class LineGraphicDataRepository { /** * 构建程序中的区段信息 * - * @param lineId 线路ID + * @param lineId 线路ID * @param dataMap 缓存数据 * @param storage 地图构建数据 */ @@ -123,7 +131,7 @@ public class LineGraphicDataRepository { /** * 构建道岔信息 * - * @param lineId 线路ID + * @param lineId 线路ID * @param dataMap 缓存数据 * @param storage 地图构建数据 */ @@ -174,7 +182,7 @@ public class LineGraphicDataRepository { /** * 设置公里标 * - * @param lineId 线路ID + * @param lineId 线路ID * @param dataMap 缓存数据 * @param storage 地图构建数据 */ @@ -225,7 +233,7 @@ public class LineGraphicDataRepository { /** * 初始化坐标转换对象 * - * @param lineId 线路ID + * @param lineId 线路ID * @param dataMap 设备集合 * @param storage 地图信息 */ @@ -317,7 +325,9 @@ public class LineGraphicDataRepository { return convertorMap.get(convertorKey).convertorKilometer(kilometer, CoordinateEnum.MAIN_LINE); } - /** 坐标系枚举 */ + /** + * 坐标系枚举 + */ @Getter private enum CoordinateEnum { MAIN_LINE("MAIN_LINE", List.of("YDK", "ZDK", "XDK", "SDK")), @@ -362,7 +372,9 @@ public class LineGraphicDataRepository { } } - /** 坐标转换对象 */ + /** + * 坐标转换对象 + */ @Getter private static class CoordinateConvertor { @@ -377,8 +389,8 @@ public class LineGraphicDataRepository { /** * 生成坐标转换对象 * - * @param configSystem 原配置坐标系信息 - * @param convertorSystem 转换坐标系类型 + * @param configSystem 原配置坐标系信息 + * @param convertorSystem 转换坐标系类型 * @param convertorCoordinate 转换坐标 * @return 转换对象 */ @@ -430,7 +442,7 @@ public class LineGraphicDataRepository { * 将出入库公里标转换为正线标 * * @param basisKilometer 出入库基准公里标 - * @param targetType 目标坐标系 + * @param targetType 目标坐标系 * @return 正线公里标数字 */ public long convertorKilometer(KilometerSystem basisKilometer, CoordinateEnum targetType) { diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java index b3a806d..158420d 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java @@ -1,8 +1,10 @@ package club.joylink.xiannccda.ats.message; +import club.joylink.xiannccda.ats.message.line3.changer.DeviceNameChangerManage; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; @@ -13,6 +15,15 @@ import org.springframework.stereotype.Component; @Component public class OccMessageManage implements ApplicationRunner { + + @Value("${occ.host}") + private String serverHost; + @Value("${occ.realPort}") + private Integer realPort; + @Value("${occ.unRealPort}") + private Integer unRealPort; + @Value("${occ.lineId}") + private Integer lineId; Map clientMap = new HashMap<>(); public void sendMsg(Integer lineId, MessageData md, boolean isRealTime) { @@ -29,8 +40,9 @@ public class OccMessageManage implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { + DeviceNameChangerManage.init(); // 读取数据配置,创建客户端 - this.registerClient(new XianOccMessagingClient(3, "localhost")); + this.registerClient(new XianOccMessagingClient(this.lineId, this.realPort, this.unRealPort, this.serverHost)); for (XianOccMessagingClient client : this.clientMap.values()) { client.connect(); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java index 0fb0c67..9c557c2 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java @@ -5,8 +5,8 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class XianOccMessagingClient { - final int realTimePortBase = 2600; - final int nonRealTimePortBase = 2700; + // final int realTimePortBase = 2600; + // final int nonRealTimePortBase = 2700; /** * 线路号 实时信息的侦听端口号为2600+line_id,非实时信息的侦听端口号为2700+line_id。 (如对于地铁1号线来说,实时信息的侦听端口号为2601,非实时信息的侦听端口号为2701) */ @@ -33,14 +33,14 @@ public class XianOccMessagingClient { } - public XianOccMessagingClient(int lineId, String host) { + public XianOccMessagingClient(int lineId, Integer realPort, Integer unRealPort, String host) { this.host = host; this.lineId = lineId; - final int realTimePort = realTimePortBase + lineId; - final int nonRealTimePort = nonRealTimePortBase + lineId; +// final int realTimePort = realTimePortBase + lineId; +// final int nonRealTimePort = nonRealTimePortBase + lineId; // 创建实时和非实时消息连接 - this.rtConnection = new OccTcpClientConnection(this, host, realTimePort); - this.nrtConnection = new OccTcpClientConnection(this, host, nonRealTimePort); + this.rtConnection = new OccTcpClientConnection(this, host, realPort); + this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/DeviceNameChanger.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/DeviceNameChanger.java index ea5e67f..ccfb0c2 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/DeviceNameChanger.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/DeviceNameChanger.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +@Deprecated public abstract class DeviceNameChanger implements NameChanger { diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/DeviceNameChangerManage.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/DeviceNameChangerManage.java new file mode 100644 index 0000000..b9141c7 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/DeviceNameChangerManage.java @@ -0,0 +1,115 @@ +package club.joylink.xiannccda.ats.message.line3.changer; + +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Lists; +import com.google.common.collect.Table; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.core.type.classreading.CachingMetadataReaderFactory; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; + +@Slf4j +public class DeviceNameChangerManage { + + final static Table> CHANGER_TABLE = HashBasedTable.create(); + + public static String findMatch(DeviceType deviceType, String occName) { + List filters = CHANGER_TABLE.get(3, deviceType); + if (CollectionUtils.isEmpty(filters)) { + log.error("未找到对应的转换的occName:[{}] debiceType[{}]", occName, deviceType); + return occName; + } + for (NameChangerFilter filter : filters) { + String newName = filter.changeDeviceName(occName); + if (Objects.nonNull(newName)) { + return newName; + } + } + log.error("不能转换的occName:[{}] debiceType[{}]", occName, deviceType); + return occName; + } + + public static void init() throws Exception { + List classes = getClassFQName("club.joylink.xiannccda.ats.message.line3.changer", NameChangerFilter.class); + List filters = Lists.newArrayList(); + for (Class clazz : classes) { + Object obj = clazz.getDeclaredConstructor().newInstance(); + filters.add((NameChangerFilter) obj); + } + Map> filteMaper = filters.stream().collect(Collectors.groupingBy(NameChangerFilter::deviceType)); + filteMaper.forEach((k, v) -> { + Collections.sort(v, Comparator.comparingInt(NameChangerFilter::filterIndex)); + CHANGER_TABLE.put(3, k, v); + }); + } + + private static List getClassFQName(String packgeName, Class clz) { +// final String BASE_PACKAGE = packgeName; + final String RESOURCE_PATTERN = "/**/*.class"; + List list = new ArrayList<>(); + if (packgeName == null || clz == null) { + return list; + } + //spring工具类,可以获取指定路径下的全部类 + ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); + try { + String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + + ClassUtils.convertClassNameToResourcePath(packgeName) + RESOURCE_PATTERN; + Resource[] resources = resourcePatternResolver.getResources(pattern); + //MetadataReader 的工厂类 + MetadataReaderFactory readerfactory = new CachingMetadataReaderFactory(resourcePatternResolver); + for (Resource resource : resources) { + //用于读取类信息 + MetadataReader reader = readerfactory.getMetadataReader((org.springframework.core.io.Resource) resource); + //扫描到的class + String classname = reader.getClassMetadata().getClassName(); + Class clazz = Class.forName(classname); + // 判断是否实现指定类型 + for (Class anInterface : clazz.getInterfaces()) { + if (anInterface == clz) { + list.add(clazz); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + + public static void main(String[] args) throws Exception { + DeviceNameChangerManage.init(); + String d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_TRACK, "T13301C"); + System.out.println(d); + d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_TRACK, "T06301C"); + System.out.println(d); + d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_TRACK, "T04325G"); + System.out.println(d); + /*d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_TRACK, "TD_2DG"); + System.out.println(d); + + d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_SWITCH, "P02309"); + System.out.println(d);*/ + d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_SIGNAL, "S03305"); + System.out.println(d); + /* d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_SIGNAL, "XR"); + System.out.println(d); + d = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_SIGNAL, "X1506_L2"); + System.out.println(d);*/ + } + +} + diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/NameChangerFilter.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/NameChangerFilter.java new file mode 100644 index 0000000..5891629 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/NameChangerFilter.java @@ -0,0 +1,14 @@ +package club.joylink.xiannccda.ats.message.line3.changer; + +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; + +public interface NameChangerFilter { + + default int filterIndex() { + return 0; + } + + DeviceType deviceType(); + + String changeDeviceName(String sourceName); +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SignalChanger.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SignalChanger.java new file mode 100644 index 0000000..9278f8a --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SignalChanger.java @@ -0,0 +1,63 @@ +package club.joylink.xiannccda.ats.message.line3.changer; + +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + +public class SignalChanger { + + public static class Signal1Changer implements NameChangerFilter { + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_SIGNAL; + } + + @Override + public String changeDeviceName(String sourceName) { + if (sourceName.length() <= 2) { + return sourceName; + } + Pattern regex = Pattern.compile("^([A-Za-z]{1,2})([\\d]{2})3?(.*?)$"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + String head = matcher.group(1); + String mid = matcher.group(2); + String tail = matcher.group(3); + return head + tail + mid; + } + return null; + } + } + + public static class Signal2Changer implements NameChangerFilter { + + @Override + public int filterIndex() { + return 2; + } + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_SIGNAL; + } + + @Override + public String changeDeviceName(String sourceName) { + + Pattern regex = Pattern.compile("^([A-Za-z]{0,2}.*?)(\\p{P})(.*?)$"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + String head = matcher.group(1); + String flag = matcher.group(2); + String tail = matcher.group(3); + if (StringUtils.equals(flag, "_")) { + flag = "-"; + } + return head + flag + tail; + } + return null; + } + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SwitchChanger.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SwitchChanger.java new file mode 100644 index 0000000..fa61b38 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/SwitchChanger.java @@ -0,0 +1,26 @@ +package club.joylink.xiannccda.ats.message.line3.changer; + +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class SwitchChanger implements NameChangerFilter { + + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_SWITCH; + } + + @Override + public String changeDeviceName(String sourceName) { + Pattern regex = Pattern.compile("^([A-Za-z]{1,2})(\\d{2})3(.*?)$"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + String head = matcher.group(2); + String tail = matcher.group(3); + return "P" + tail + head; + } + return null; + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/TrackChanger.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/TrackChanger.java new file mode 100644 index 0000000..53c8726 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/changer/TrackChanger.java @@ -0,0 +1,96 @@ +package club.joylink.xiannccda.ats.message.line3.changer; + +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TrackChanger { + + public static class Track1Changer implements NameChangerFilter { + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_TRACK; + } + + @Override + public String changeDeviceName(String sourceName) { + Pattern regex = Pattern.compile("^([A-Za-z]{1,2})([\\d]{1,2})3?(.*?)([A-Z])$"); +// Pattern regex = Pattern.compile("^([A-Za-z]{1,2})([\\d]{2})3(.*?)([A-Z])$"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + String head = matcher.group(2); + String tail = matcher.group(3); + String tailMeta = matcher.group(4); + return "G" + tail + head + tailMeta; + } + return null; + } + } + + public static class Track4Changer implements NameChangerFilter { + + @Override + public int filterIndex() { + return 3; + } + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_TRACK; + } + + @Override + public String changeDeviceName(String sourceName) { + Pattern regex = Pattern.compile("^[A-Za-z]{1,2}([\\d]{1,2})3(.*?)$"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + String head = matcher.group(1); + String tail = matcher.group(2); + return "G" + tail + head; + } + return null; + } + } + + public static class Track2Changer implements NameChangerFilter { + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_TRACK; + } + + @Override + public String changeDeviceName(String sourceName) { + Pattern regex = Pattern.compile("T([A-Za-z]{1}\\p{P}.*?)$"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + return matcher.group(1); + } + return null; + } + } + + public static class Track3Changer implements NameChangerFilter { + + @Override + public int filterIndex() { + return 99; + } + + @Override + public DeviceType deviceType() { + return DeviceType.DEVICE_TYPE_TRACK; + } + + @Override + public String changeDeviceName(String sourceName) { + Pattern regex = Pattern.compile("^T(\\d*$)"); + Matcher matcher = regex.matcher(sourceName); + if (matcher.find()) { + return "ST" + matcher.group(1); + } + return null; + } + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 3f8388d..5798982 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -11,3 +11,8 @@ logging: club.joylink.xiannccda.mapper: debug file: path: /usr/local/joylink/logs/xianncc +occ: + host: localhost + realPort: 123 + unRealPort: 123 + lineId: 3 \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 910c753..e56c5a2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -14,4 +14,10 @@ logging: file: path: /logs/xiannccda level: - root: "info" \ No newline at end of file + root: "info" + +occ: + host: 10.255.11.15 + realPort: 5603 + unRealPort: 5703 + lineId: 3 \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 011d8a7..70cfb10 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,7 +2,7 @@ server: port: 9081 spring: profiles: - active: dev + active: local banner: location: classpath:banner.txt datasource: diff --git a/src/test/java/club/joylink/xiannccda/util/CollectorData.java b/src/test/java/club/joylink/xiannccda/util/CollectorData.java index 7e10bfe..2db01c9 100644 --- a/src/test/java/club/joylink/xiannccda/util/CollectorData.java +++ b/src/test/java/club/joylink/xiannccda/util/CollectorData.java @@ -43,30 +43,6 @@ public class CollectorData { @Autowired NccMockDataService nccMockDataService; -/* @Test - public void dd() throws UnsupportedEncodingException { - - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); - queryWrapper.eq(NccMockData::getMsgId, "TRAIN_INDICATION_UPDATE"); - List datas = this.nccMockDataService.loadALLData(queryWrapper); - List bitmapResponses = datas.stream().map(d -> (TrainIndicationUpdateResponse) d).collect(Collectors.toList()); - Set sets = new HashSet<>(); - - for (TrainIndicationUpdateResponse bitmapRespons : bitmapResponses) { - ByteBuf buf = Unpooled.buffer(); - -// buf.writeInt(842413824); - buf.writeInt(bitmapRespons.getDestinationId()); - byte[] dd = new byte[4]; - buf.readBytes(dd); - String s = new String(dd, "utf-8"); - if (StringUtils.isEmpty(s.trim())) { - System.out.println(bitmapRespons); - } - sets.add(s); - } - System.out.println(sets); - }*/ @Test public void collector() { diff --git a/src/test/java/club/joylink/xiannccda/util/Device.java b/src/test/java/club/joylink/xiannccda/util/Device.java index 3a7ba73..8bd52f8 100644 --- a/src/test/java/club/joylink/xiannccda/util/Device.java +++ b/src/test/java/club/joylink/xiannccda/util/Device.java @@ -1,5 +1,6 @@ package club.joylink.xiannccda.util; +import club.joylink.xiannccda.ats.message.line3.changer.DeviceNameChangerManage; import club.joylink.xiannccda.ats.message.line3.device.DeviceType; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; @@ -85,14 +86,7 @@ public abstract class Device { @Override public String changeDeviceName(String nccDeviceName) { - if (nccDeviceName.length() < 3) { - return nccDeviceName; - } - - String started = nccDeviceName.substring(0, 1); - String head = nccDeviceName.substring(1, 3); - String tail = nccDeviceName.substring(4); - return started + tail + head; + return DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_SWITCH, nccDeviceName); } } @@ -120,18 +114,10 @@ public abstract class Device { @Override String changeDeviceName(String nccDeviceName) { - if (nccDeviceName.length() < 4) { - return nccDeviceName; + if (StringUtils.equals(nccDeviceName, "T13301C")) { + System.out.println("aaaaaaaaaaaaaa"); } - - 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; + return DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_TRACK, nccDeviceName); } } @@ -145,13 +131,7 @@ public abstract class Device { @Override String changeDeviceName(String nccDeviceName) { - if (nccDeviceName.length() <= 3) { - return nccDeviceName; - } - String started = nccDeviceName.substring(0, 1); - String head = nccDeviceName.substring(1, 3); - String tail = nccDeviceName.substring(4); - return started + tail + head; + return DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_SIGNAL, nccDeviceName); } }