From b9478a544f80e8756d849179f68e2109de97c65a Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 20 Jun 2023 11:11:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E5=88=A0=E9=99=A4=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E9=80=BB=E8=BE=91=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/collect/DeviceStatusCollect.java | 119 ------------------ .../ats/message/collect/DeviceStatusData.java | 6 +- .../collect/DeviceStatusDataOperate.java | 73 +++++++---- .../collect/DeviceStatusDataRepository.java | 65 ---------- .../xiannccda/ws/LineNetMessageServer.java | 6 +- .../xiannccda/ws/TestMessageServer.java | 7 +- .../xiannccda/ws/TestMessageServer2.java | 7 +- 7 files changed, 66 insertions(+), 217 deletions(-) delete mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusCollect.java diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusCollect.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusCollect.java deleted file mode 100644 index f6859d1..0000000 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusCollect.java +++ /dev/null @@ -1,119 +0,0 @@ -package club.joylink.xiannccda.ats.message.collect; - -import com.google.protobuf.Descriptors.FieldDescriptor.Type; -import com.google.protobuf.GeneratedMessageV3.Builder; -import com.google.protobuf.Message; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; -import org.springframework.util.CollectionUtils; - -/** 收集状态方法 */ -public abstract class DeviceStatusCollect { - /** - * 返回全量设备状态信息 - * - * @param builder 返回的消息类型 - * @param lineDataList 要处理的线路数据列表 - * @return 状态消息 - */ - public static Message collectAllStatus(Builder builder, List lineDataList) { - return commonCollectFunction( - builder, - (data, fieldType) -> { - Map> allDevice = data.getAllDeviceMap(); - Map deviceMap = allDevice.get(fieldType); - if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态,则全部放入 - return deviceMap.values().stream().map(Builder::build).toList(); - } - return List.of(); - }, - lineDataList); - } - - /** - * 返回增量设备状态信息 - * - * @param lineDataList 线路数据列表 - * @return 状态信息 - */ - public static Message collectIncrementStatus( - Builder builder, List lineDataList) { - return commonCollectFunction( - builder, - (data, fieldType) -> { - Map> allDevice = data.getAllDeviceMap(); - Map> statusDevice = data.getStatusVOMap(); - Map deviceMap = allDevice.get(fieldType); - if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态,则全部放入 - // 获取当前存储的状态 - Map statusMap = - statusDevice.computeIfAbsent(fieldType, key -> new HashMap<>(deviceMap.size())); - return compare(statusMap, deviceMap); - } - return List.of(); - }, - lineDataList); - } - - /** - * 对比获取设备变化了的状态信息并更新状态信息 - * - * @param curMap 原有的状态信息 - * @param newMap 采集到状态信息 - * @return 发生变化的状态信息 - */ - public static List compare(Map curMap, Map newMap) { - List messageList = new LinkedList<>(); - if (newMap != null) { - newMap.forEach( - (k, v) -> { - if (curMap.containsKey(k)) { // 包含状态,对比状态是否一致 - Message message = v.build(); - if (!curMap.get(k).build().equals(message)) { - curMap.get(k).mergeFrom(message); - messageList.add(message); - } - } else { // 不包含直接添加状态 - curMap.put(k, v.clone()); - messageList.add(curMap.get(k).build()); - } - }); - } - return messageList; - } - - /** - * 公共处理部分 - * - * @param builder 返回的builder对象 - * @param compareFun 额外的处理逻辑 - * @param lineDataList 线路数据 - * @return 消息内容 - */ - private static Message commonCollectFunction( - Builder builder, - BiFunction> compareFun, - List lineDataList) { - if (lineDataList == null || lineDataList.size() == 0) { - return builder.build(); - } - // 消息体字段列表 - builder.getDescriptorForType().getFields().stream() - .filter(f -> f.getType().equals(Type.MESSAGE)) - .forEach( - field -> { - String fieldType = field.getMessageType().getName(); // 字段类型 - List allDeviceList = new LinkedList<>(); - for (DeviceStatusData data : lineDataList) { // 循环传入的线路数据 - allDeviceList.addAll(compareFun.apply(data, fieldType)); - } - if (!CollectionUtils.isEmpty(allDeviceList)) { - builder.setField(field, allDeviceList); - } - }); - return builder.build(); - } -} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusData.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusData.java index 5f59962..dfa2389 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusData.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusData.java @@ -1,6 +1,8 @@ package club.joylink.xiannccda.ats.message.collect; import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.Message; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import lombok.Getter; @@ -15,8 +17,8 @@ public class DeviceStatusData { /** 所有设备状态信息 <设备类型【这里用的message的类名:Rtu、Signal等】,<设备主键,设备信息>> */ private Map> allDeviceMap = new ConcurrentHashMap<>(); - /** 当前所有设备状态信息 */ - private Map> statusVOMap = new ConcurrentHashMap<>(); + /** 增量的设备更新信息 */ + private Map> statusVOMap = new ConcurrentHashMap<>(); public DeviceStatusData(String lineCode) { this.lineCode = lineCode; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java index 337f448..4071261 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java @@ -1,10 +1,13 @@ package club.joylink.xiannccda.ats.message.collect; import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.Message; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import org.springframework.util.CollectionUtils; /** 线路设备操作方法 */ public abstract class DeviceStatusDataOperate { @@ -22,7 +25,7 @@ public abstract class DeviceStatusDataOperate { * @param builder 设备状态信息 * @return 状态类型 */ - public static String findType(Builder builder) { + private static String findType(Builder builder) { return builder.getDefaultInstanceForType().getClass().getSimpleName(); } @@ -32,7 +35,7 @@ public abstract class DeviceStatusDataOperate { * @param protoBuilder 数据信息 * @return 主键 */ - public static String getIdVal(Builder protoBuilder) { + private static String getIdVal(Builder protoBuilder) { String idName = DEVICE_ID_NAME_MAP.getOrDefault(findType(protoBuilder), DEFAULT_ID_NAME); return String.valueOf( protoBuilder.getField(protoBuilder.getDescriptorForType().findFieldByName(idName))); @@ -48,38 +51,29 @@ public abstract class DeviceStatusDataOperate { if (data == null || builders == null) { return; } - Map> map = data.getAllDeviceMap(); + // 获取全量数据 + Map> allDeviceMap = data.getAllDeviceMap(); + // 最后增量数据 + Map> statusVOMap = new ConcurrentHashMap<>(); builders.stream() .collect(Collectors.groupingBy(DeviceStatusDataOperate::findType)) .forEach( (k, v) -> { + // 当前的设备状态 Map deviceStatusMap = - map.computeIfAbsent(k, key -> new ConcurrentHashMap<>(v.size())); + allDeviceMap.computeIfAbsent(k, key -> new ConcurrentHashMap<>(v.size())); + // 新的设备状态 Map newDeviceMap = v.stream().collect(Collectors.toMap(DeviceStatusDataOperate::getIdVal, b -> b)); - deviceStatusMap.putAll(newDeviceMap); + // 对比结果 + List compareList = compare(deviceStatusMap, newDeviceMap); + if (CollectionUtils.isEmpty(compareList)) { + statusVOMap.put(k, compareList); + } }); - } - - /** - * 将采集到的设备状态放入内存中 - * - * @param builder 设备状态信息 - * @param data 线路的设备信息 - * @return 包装的设备状态 - */ - public static void addDevice(Builder builder, DeviceStatusData data) { - if (data == null || builder == null) { - return; - } - Map> map = data.getAllDeviceMap(); - String buildType = findType(builder); - Map deviceStatusMap = map.get(buildType); - if (deviceStatusMap == null) { - deviceStatusMap = new ConcurrentHashMap<>(); - map.put(buildType, deviceStatusMap); - } - deviceStatusMap.put(getIdVal(builder), builder); + // 清空上次的增量数据 + data.getStatusVOMap().clear(); + data.getStatusVOMap().putAll(statusVOMap); } /** @@ -94,4 +88,31 @@ public abstract class DeviceStatusDataOperate { data.getAllDeviceMap().clear(); data.getStatusVOMap().clear(); } + + /** + * 对比获取设备变化了的状态信息并更新状态信息 + * + * @param curMap 原有的状态信息 + * @param newMap 采集到状态信息 + * @return 发生变化的状态信息 + */ + public static List compare(Map curMap, Map newMap) { + List messageList = new LinkedList<>(); + if (newMap != null) { + newMap.forEach( + (k, v) -> { + if (curMap.containsKey(k)) { // 包含状态,对比状态是否一致 + Message message = v.build(); + if (!curMap.get(k).build().equals(message)) { + curMap.get(k).mergeFrom(message); + messageList.add(message); + } + } else { // 不包含直接添加状态 + curMap.put(k, v.clone()); + messageList.add(curMap.get(k).build()); + } + }); + } + return messageList; + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java index a255dd5..a842c5c 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java @@ -1,9 +1,6 @@ package club.joylink.xiannccda.ats.message.collect; -import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineMessage; -import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage; import com.google.protobuf.GeneratedMessageV3.Builder; -import com.google.protobuf.Message; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -39,68 +36,6 @@ public abstract class DeviceStatusDataRepository { DeviceStatusDataOperate.addDevices(builders, data); } - /** - * 添加单个设备数据 - * - * @param lineCode 线路编号 - * @param builder 设备消息 - */ - public static void addDeviceStatusData(String lineCode, Builder builder) { - DeviceStatusData data = lineStatusDataMap.computeIfAbsent(lineCode, DeviceStatusData::new); - DeviceStatusDataOperate.addDevice(builder, data); - } - - /** - * 采集线路状态数据 - * - * @param lineCode 线路编码 - * @return 消息数据 - */ - public static Message collectLineAllMessage(String lineCode) { - return DeviceStatusCollect.collectAllStatus( - WsLineMessage.newBuilder(), List.of(lineStatusDataMap.get(lineCode))); - } - - /** - * 采集增量线路数据 - * - * @param lineCode 线路编码 - * @return 消息数据 - */ - public static Message collectLineMessage(String lineCode) { - return DeviceStatusCollect.collectIncrementStatus( - WsLineMessage.newBuilder(), List.of(lineStatusDataMap.get(lineCode))); - } - - /** - * 发送线网消息数据 - * - * @return 消息数据 - */ - public static Message collectLineNetAllMessage() { - return DeviceStatusCollect.collectAllStatus( - WsLineNetMessage.newBuilder(), lineStatusDataMap.values().stream().toList()); - } - - /** - * 发送线网增量消息数据 - * - * @return 消息数据 - */ - public static Message collectLineNetMessage() { - return DeviceStatusCollect.collectIncrementStatus( - WsLineNetMessage.newBuilder(), lineStatusDataMap.values().stream().toList()); - } - - /** - * 获取现在存在的线路编码列表 - * - * @return 线路编码列表 - */ - public static List getLineCodeList() { - return lineStatusDataMap.keySet().stream().toList(); - } - /** * 获取线路总数据 * diff --git a/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java index b6271fa..bfa022b 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java @@ -12,13 +12,13 @@ public class LineNetMessageServer implements IMessageServer { @Override public String getDestinationPattern() { - return "/queue/line/all"; + return "/queue/lineNet"; } @Override public Object onSubscription(String destination, Map paramMap) { log.info("【线网订阅】发布全量数据"); - byte[] bytes = DeviceStatusDataRepository.collectLineNetAllMessage().toByteArray(); + byte[] bytes = new byte[1]; log.info("【线网订阅】全量数据量:" + bytes.length); return bytes; } @@ -31,7 +31,7 @@ public class LineNetMessageServer implements IMessageServer { @Override public List onTick() { List topicMessages = new ArrayList<>(); - byte[] bytes = DeviceStatusDataRepository.collectLineNetMessage().toByteArray(); + byte[] bytes = new byte[1]; log.info("【线网订阅】数据状态变化量:" + bytes.length); topicMessages.add(new TopicMessage(this.getDestinationPattern(), bytes)); return topicMessages; diff --git a/src/main/java/club/joylink/xiannccda/ws/TestMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/TestMessageServer.java index c4b7225..ea4c566 100644 --- a/src/main/java/club/joylink/xiannccda/ws/TestMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/TestMessageServer.java @@ -29,7 +29,12 @@ public class TestMessageServer implements IMessageServer { String lineId = paramMap.get(LineIdPathKey); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(lineId); log.info("线路lineId={}订阅,发布全量数据", lineId); - byte[] bytes = DeviceStatusDataRepository.collectLineAllMessage(lineId).toByteArray(); + Builder builder = WsLineMessage.newBuilder(); + builder.addRtu(Rtu.newBuilder().setId("rtu1").setIpRtuStusInCentralCtrl(true).build()); + builder.addSignal( + Signal.newBuilder().setId("signal1").setRedOpen(true).setAutoMode(true).build()); + + byte[] bytes = builder.build().toByteArray(); System.out.println(JSON.toJSONString(bytes)); return bytes; } diff --git a/src/main/java/club/joylink/xiannccda/ws/TestMessageServer2.java b/src/main/java/club/joylink/xiannccda/ws/TestMessageServer2.java index 1ab1920..7a05227 100644 --- a/src/main/java/club/joylink/xiannccda/ws/TestMessageServer2.java +++ b/src/main/java/club/joylink/xiannccda/ws/TestMessageServer2.java @@ -34,7 +34,12 @@ public class TestMessageServer2 implements IMessageServer { @Override public Object onSubscription(String destination, Map paramMap) { log.info("线路lineId={}订阅,发布全量数据", lineId); - byte[] bytes = DeviceStatusDataRepository.collectLineAllMessage(lineId).toByteArray(); + Builder builder = WsLineMessage.newBuilder(); + builder.addRtu(Rtu.newBuilder().setId("rtu1").setIpRtuStusInCentralCtrl(true).build()); + builder.addSignal( + Signal.newBuilder().setId("signal1").setRedOpen(true).setAutoMode(true).build()); + + byte[] bytes = builder.build().toByteArray(); System.out.println(JSON.toJSONString(bytes)); return bytes; } From 1e12a5381c3aff006e3ef087332673c6e7d36c05 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 20 Jun 2023 15:22:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E3=80=90=E7=BA=BF=E7=BD=91websocket?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collect/DeviceStatusDataOperate.java | 4 +- .../collect/DeviceStatusDataRepository.java | 12 -- .../service/LineDeviceStatusService.java | 202 +++++++++++------- .../xiannccda/ws/LineNetMessageServer.java | 54 ++++- .../xiannccda/ws/WsMessageServerManager.java | 5 - 5 files changed, 172 insertions(+), 105 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java index 4071261..95b6914 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java @@ -67,12 +67,10 @@ public abstract class DeviceStatusDataOperate { v.stream().collect(Collectors.toMap(DeviceStatusDataOperate::getIdVal, b -> b)); // 对比结果 List compareList = compare(deviceStatusMap, newDeviceMap); - if (CollectionUtils.isEmpty(compareList)) { + if (!CollectionUtils.isEmpty(compareList)) { statusVOMap.put(k, compareList); } }); - // 清空上次的增量数据 - data.getStatusVOMap().clear(); data.getStatusVOMap().putAll(statusVOMap); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java index a842c5c..f290d9a 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataRepository.java @@ -13,18 +13,6 @@ public abstract class DeviceStatusDataRepository { /** 线路设备状态信息集合 */ private static final Map lineStatusDataMap = new ConcurrentHashMap<>(); - /** - * 添加所属线路的设备信息 - * - * @param lineCode 线路编号 - * @param builders 设备信息 - */ - public static void addAllDeviceStatusData(String lineCode, List builders) { - DeviceStatusData data = lineStatusDataMap.computeIfAbsent(lineCode, DeviceStatusData::new); - DeviceStatusDataOperate.resetDevice(data); - DeviceStatusDataOperate.addDevices(builders, data); - } - /** * 批量增加 * diff --git a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java index 3bd0277..17fa220 100644 --- a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java +++ b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java @@ -1,15 +1,18 @@ package club.joylink.xiannccda.service; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; +import club.joylink.xiannccda.ws.IMessageServer; +import club.joylink.xiannccda.ws.LineNetMessageServer; +import club.joylink.xiannccda.ws.WsMessageServerManager; import com.google.protobuf.GeneratedMessageV3.Builder; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Train; import club.joylink.xiannccda.ats.message.line3.device.DeviceType; import jakarta.annotation.PostConstruct; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -21,89 +24,100 @@ import org.springframework.stereotype.Service; @Service public class LineDeviceStatusService { + private String dataKey = "lineNet"; + + private List rightPathList = + List.of( + "G0105A", "G0105B", "G0105C", "DG0107", "G0109A", "G0109B", "G0109C", "G0109D", "G0109E", + "G0201A", "G0201B", "G0201C", "G0201D", "G0201E", "G0201F", "G0203A", "G0203B", "G0203C", + "G0203D", "G0301A", "G0301B", "G0301C", "G0301D", "G0301E", "DG0303", "G0401A", "G0401B", + "G0401C", "G0401D", "G0401E", "G0401F", "G0401G", "G0401H", "G0403A", "G0403B", "G0403C", + "G0403D", "G0501A", "G0501B", "G0501C", "G0501D", "DG0503", "DG0505", "G0507A", "G0507B", + "G0507C", "G0507D", "G0601A", "G0601B", "G0601C", "G0601D", "G0601E", "G0601F", "G0601G", + "G0601H", "G0603A", "G0603B", "G0603C", "G0603D", "G0701A", "G0701B", "G0701C", "G0701D", + "G0701E", "G0701F", "G0703A", "G0703B", "G0703C", "G0703D", "G0703E", "DG0705", "G0801A", + "G0801B", "G0801C", "G0801D", "G0801E", "G0801F", "G0803A", "G0803B", "G0803C", "G0803D", + "G0901A", "G0901B", "G0901C", "G0901D", "G0901E", "G0901F", "G0903A", "G0903B", "G0903C", + "G0903D", "DG0905", "G1001A", "G1001B", "G1001C", "G1001D", "G1001E", "G1001F", "G1001G", + "G1001H", "G1003A", "G1003B", "G1003C", "G1003D", "G1101A", "G1101B", "G1101C", "G1101D", + "G1101E", "G1101F", "G1101G", "G1101H", "G1101I", "G1103A", "G1103B", "G1103C", "G1103D", + "G1201A", "G1201B", "G1201C", "DG1203", "G1205A", "G1205B", "G1205C", "G1205D", "G1301A", + "G1301B", "G1301C", "G1301D", "G1301E", "G1303A", "G1303B", "G1303C", "G1303D", "G1401A", + "G1401B", "G1401C", "G1401D", "G1403A", "G1403B", "G1403C", "G1403D", "G1501A", "G1501B", + "G1501C", "G1501D", "G1503A", "G1503B", "G1503C", "G1503D", "DG1505", "G1601A", "G1601B", + "G1601C", "G1601D", "G1601E", "G1601F", "G1601G", "G1603A", "G1603B", "G1603C", "G1603D", + "G1701A", "G1701B", "G1701C", "G1701D", "G1701E", "G1701F", "G1701G", "G1703A", "G1703B", + "G1703C", "G1703D", "G1801A", "G1801B", "G1801C", "G1801D", "G1801E", "G1801F", "G1801G", + "G1801H", "G1801I", "DG1803", "G1805A", "G1805B", "G1805C", "G1805D", "G1901A", "G1901B", + "G1901C", "G1901D", "G1901E", "G1901F", "G1901G", "G1901H", "G1901I", "G1903A", "G1903B", + "G1903C", "G1903D", "G2001A", "G2001B", "G2001C", "G2001D", "G2001E", "G2001F", "G2001G", + "G2003A", "G2003B", "G2003C", "G2003D", "G2101A", "G2101B", "G2101C", "G2101D", "G2101E", + "G2101F", "G2101G", "G2103A", "G2103B", "G2103C", "G2103D", "DG2105", "G2107A", "G2107B", + "DG2109", "G2201A", "G2201B", "G2201C", "G2201D", "G2201E", "G2201F", "G2201G", "G2201H", + "G2201I", "G2203A", "G2203B", "G2203C", "G2203D", "G2301A", "G2301B", "G2301C", "G2301D", + "G2301E", "G2301F", "G2301G", "G2301H", "G2301I", "G2301J", "G2301K", "G2303A", "G2303B", + "G2303C", "G2303D", "G2401A", "G2401B", "G2401C", "G2401D", "G2401E", "G2401F", "DG2403", + "G2405A", "G2405B", "G2405C", "G2405D", "G2501A", "G2501B", "G2501C", "G2501D", "G2501E", + "G2503A", "G2503B", "G2503C", "G2503D", "G2601A", "G2601B", "G2601C", "G2601D", "G2601E", + "G2601F", "DG2603", "G2605A", "G2605B", "G2605C", "DG2607", "DG2609", "G2611A", "G2611B", + "G2611C"); + + private List leftPathList = + List.of( + "G2610A", "G2610B", "G2610C", "DG2608", "DG2606", "G2604A", "G2604B", "G2604C", "DG2602", + "G2504A", "G2504B", "G2504C", "G2504D", "G2504E", "G2504F", "G2502A", "G2502B", "G2502C", + "G2502D", "G2406A", "G2406B", "G2406C", "G2406D", "G2406E", "G2404A", "G2404B", "G2404C", + "G2404D", "DG2402", "G2304A", "G2304B", "G2304C", "G2304D", "G2304E", "G2304F", "G2304G", + "G2302A", "G2302B", "G2302C", "G2302D", "G2204A", "G2204B", "G2204C", "G2204D", "G2204E", + "G2204F", "G2204G", "G2204H", "G2204I", "G2204J", "G2204K", "G2202A", "G2202B", "G2202C", + "G2202D", "G2110A", "G2110B", "G2110C", "G2110D", "G2110E", "G2110F", "G2110G", "G2110H", + "G2110I", "DG2108", "G2106A", "G2106B", "DG2104", "G2102A", "G2102B", "G2102C", "G2102D", + "G2004A", "G2004B", "G2004C", "G2004D", "G2004E", "G2004F", "G2004G", "G2002A", "G2002B", + "G2002C", "G2002D", "G1904A", "G1904B", "G1904C", "G1904D", "G1904E", "G1904F", "G1904G", + "G1902A", "G1902B", "G1902C", "G1902D", "G1806A", "G1806B", "G1806C", "G1806D", "G1806E", + "G1806F", "G1806G", "G1806H", "G1804A", "G1804B", "G1804C", "G1804D", "DG1802", "G1704A", + "G1704B", "G1704C", "G1704D", "G1704E", "G1704F", "G1704G", "G1704H", "G1704I", "G1704J", + "G1702A", "G1702B", "G1702C", "G1702D", "G1604A", "G1604B", "G1604C", "G1604D", "G1604E", + "G1604F", "G1604G", "G1602A", "G1602B", "G1602C", "G1602D", "G1508A", "G1508B", "G1508C", + "G1508D", "G1508E", "DG1506", "DG1504", "G1502A", "G1502B", "G1502C", "G1502D", "G1404A", + "G1404B", "G1404C", "G1404D", "G1402A", "G1402B", "G1402C", "G1402D", "G1304A", "G1304B", + "G1304C", "G1304D", "G1302A", "G1302B", "G1302C", "G1302D", "G1206A", "G1206B", "G1206C", + "G1206D", "G1206E", "G1204A", "G1204B", "G1204C", "G1204D", "DG1202", "G1104A", "G1104B", + "G1104C", "G1102A", "G1102B", "G1102C", "G1102D", "G1004A", "G1004B", "G1004C", "G1004D", + "G1004E", "G1004F", "G1004G", "G1004H", "G1004I", "G1002A", "G1002B", "G1002C", "G1002D", + "G0908A", "G0908B", "G0908C", "G0908D", "G0908E", "G0908F", "G0908G", "DG0906", "DG0904", + "G0902A", "G0902B", "G0902C", "G0902D", "G0804A", "G0804B", "G0804C", "G0804D", "G0804E", + "G0804F", "G0802A", "G0802B", "G0802C", "G0802D", "G0710A", "G0710B", "G0710C", "G0710D", + "G0710E", "G0710F", "DG0708", "DG0704", "G0702A", "G0702B", "G0702C", "G0702D", "G0604A", + "G0604B", "G0604C", "G0604D", "G0604E", "G0604F", "G0602A", "G0602B", "G0602C", "G0602D", + "G0506A", "G0506B", "G0506C", "G0506D", "G0506E", "G0506F", "G0506G", "G0504A", "G0504B", + "G0504C", "G0504D", "DG0502", "G0404A", "G0404B", "G0404C", "G0404D", "G0404E", "G0404F", + "G0402A", "G0402B", "G0402C", "G0402D", "G0306A", "G0306B", "G0306C", "G0306D", "G0306E", + "G0306F", "G0306G", "G0306H", "G0304A", "G0304B", "G0304C", "G0304D", "DG0302", "G0206A", + "G0206B", "G0206C", "G0206D", "G0206E", "G0204A", "G0204B", "G0204C", "G0204D", "G0202A", + "G0202B", "G0202C", "G0202D", "G0202E", "G0110A", "G0110B", "G0110C", "G0110D", "G0110E", + "DG0108", "G0106A", "G0106B", "G0106C", "DG0104"); + + private List trainList = + new ArrayList<>( + List.of( + "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312")); + + private final WsMessageServerManager wsMessageServerManager; + + public LineDeviceStatusService(WsMessageServerManager wsMessageServerManager) { + this.wsMessageServerManager = wsMessageServerManager; + } + @PostConstruct public void deviceStatusRefresh() { - List rightPathList = - List.of( - "G0105A", "G0105B", "G0105C", "DG0107", "G0109A", "G0109B", "G0109C", "G0109D", - "G0109E", "G0201A", "G0201B", "G0201C", "G0201D", "G0201E", "G0201F", "G0203A", - "G0203B", "G0203C", "G0203D", "G0301A", "G0301B", "G0301C", "G0301D", "G0301E", - "DG0303", "G0401A", "G0401B", "G0401C", "G0401D", "G0401E", "G0401F", "G0401G", - "G0401H", "G0403A", "G0403B", "G0403C", "G0403D", "G0501A", "G0501B", "G0501C", - "G0501D", "DG0503", "DG0505", "G0507A", "G0507B", "G0507C", "G0507D", "G0601A", - "G0601B", "G0601C", "G0601D", "G0601E", "G0601F", "G0601G", "G0601H", "G0603A", - "G0603B", "G0603C", "G0603D", "G0701A", "G0701B", "G0701C", "G0701D", "G0701E", - "G0701F", "G0703A", "G0703B", "G0703C", "G0703D", "G0703E", "DG0705", "G0801A", - "G0801B", "G0801C", "G0801D", "G0801E", "G0801F", "G0803A", "G0803B", "G0803C", - "G0803D", "G0901A", "G0901B", "G0901C", "G0901D", "G0901E", "G0901F", "G0903A", - "G0903B", "G0903C", "G0903D", "DG0905", "G1001A", "G1001B", "G1001C", "G1001D", - "G1001E", "G1001F", "G1001G", "G1001H", "G1003A", "G1003B", "G1003C", "G1003D", - "G1101A", "G1101B", "G1101C", "G1101D", "G1101E", "G1101F", "G1101G", "G1101H", - "G1101I", "G1103A", "G1103B", "G1103C", "G1103D", "G1201A", "G1201B", "G1201C", - "DG1203", "G1205A", "G1205B", "G1205C", "G1205D", "G1301A", "G1301B", "G1301C", - "G1301D", "G1301E", "G1303A", "G1303B", "G1303C", "G1303D", "G1401A", "G1401B", - "G1401C", "G1401D", "G1403A", "G1403B", "G1403C", "G1403D", "G1501A", "G1501B", - "G1501C", "G1501D", "G1503A", "G1503B", "G1503C", "G1503D", "DG1505", "G1601A", - "G1601B", "G1601C", "G1601D", "G1601E", "G1601F", "G1601G", "G1603A", "G1603B", - "G1603C", "G1603D", "G1701A", "G1701B", "G1701C", "G1701D", "G1701E", "G1701F", - "G1701G", "G1703A", "G1703B", "G1703C", "G1703D", "G1801A", "G1801B", "G1801C", - "G1801D", "G1801E", "G1801F", "G1801G", "G1801H", "G1801I", "DG1803", "G1805A", - "G1805B", "G1805C", "G1805D", "G1901A", "G1901B", "G1901C", "G1901D", "G1901E", - "G1901F", "G1901G", "G1901H", "G1901I", "G1903A", "G1903B", "G1903C", "G1903D", - "G2001A", "G2001B", "G2001C", "G2001D", "G2001E", "G2001F", "G2001G", "G2003A", - "G2003B", "G2003C", "G2003D", "G2101A", "G2101B", "G2101C", "G2101D", "G2101E", - "G2101F", "G2101G", "G2103A", "G2103B", "G2103C", "G2103D", "DG2105", "G2107A", - "G2107B", "DG2109", "G2201A", "G2201B", "G2201C", "G2201D", "G2201E", "G2201F", - "G2201G", "G2201H", "G2201I", "G2203A", "G2203B", "G2203C", "G2203D", "G2301A", - "G2301B", "G2301C", "G2301D", "G2301E", "G2301F", "G2301G", "G2301H", "G2301I", - "G2301J", "G2301K", "G2303A", "G2303B", "G2303C", "G2303D", "G2401A", "G2401B", - "G2401C", "G2401D", "G2401E", "G2401F", "DG2403", "G2405A", "G2405B", "G2405C", - "G2405D", "G2501A", "G2501B", "G2501C", "G2501D", "G2501E", "G2503A", "G2503B", - "G2503C", "G2503D", "G2601A", "G2601B", "G2601C", "G2601D", "G2601E", "G2601F", - "DG2603", "G2605A", "G2605B", "G2605C", "DG2607", "DG2609", "G2611A", "G2611B", - "G2611C"); + IMessageServer iMessageServer = + new LineNetMessageServer(DeviceStatusDataRepository.getDeviceStatusData(dataKey)); + wsMessageServerManager.registerMessageServer(iMessageServer); + refreshTestData(); + } - List leftPathList = - List.of( - "G2610A", "G2610B", "G2610C", "DG2608", "DG2606", "G2604A", "G2604B", "G2604C", - "DG2602", "G2504A", "G2504B", "G2504C", "G2504D", "G2504E", "G2504F", "G2502A", - "G2502B", "G2502C", "G2502D", "G2406A", "G2406B", "G2406C", "G2406D", "G2406E", - "G2404A", "G2404B", "G2404C", "G2404D", "DG2402", "G2304A", "G2304B", "G2304C", - "G2304D", "G2304E", "G2304F", "G2304G", "G2302A", "G2302B", "G2302C", "G2302D", - "G2204A", "G2204B", "G2204C", "G2204D", "G2204E", "G2204F", "G2204G", "G2204H", - "G2204I", "G2204J", "G2204K", "G2202A", "G2202B", "G2202C", "G2202D", "G2110A", - "G2110B", "G2110C", "G2110D", "G2110E", "G2110F", "G2110G", "G2110H", "G2110I", - "DG2108", "G2106A", "G2106B", "DG2104", "G2102A", "G2102B", "G2102C", "G2102D", - "G2004A", "G2004B", "G2004C", "G2004D", "G2004E", "G2004F", "G2004G", "G2002A", - "G2002B", "G2002C", "G2002D", "G1904A", "G1904B", "G1904C", "G1904D", "G1904E", - "G1904F", "G1904G", "G1902A", "G1902B", "G1902C", "G1902D", "G1806A", "G1806B", - "G1806C", "G1806D", "G1806E", "G1806F", "G1806G", "G1806H", "G1804A", "G1804B", - "G1804C", "G1804D", "DG1802", "G1704A", "G1704B", "G1704C", "G1704D", "G1704E", - "G1704F", "G1704G", "G1704H", "G1704I", "G1704J", "G1702A", "G1702B", "G1702C", - "G1702D", "G1604A", "G1604B", "G1604C", "G1604D", "G1604E", "G1604F", "G1604G", - "G1602A", "G1602B", "G1602C", "G1602D", "G1508A", "G1508B", "G1508C", "G1508D", - "G1508E", "DG1506", "DG1504", "G1502A", "G1502B", "G1502C", "G1502D", "G1404A", - "G1404B", "G1404C", "G1404D", "G1402A", "G1402B", "G1402C", "G1402D", "G1304A", - "G1304B", "G1304C", "G1304D", "G1302A", "G1302B", "G1302C", "G1302D", "G1206A", - "G1206B", "G1206C", "G1206D", "G1206E", "G1204A", "G1204B", "G1204C", "G1204D", - "DG1202", "G1104A", "G1104B", "G1104C", "G1102A", "G1102B", "G1102C", "G1102D", - "G1004A", "G1004B", "G1004C", "G1004D", "G1004E", "G1004F", "G1004G", "G1004H", - "G1004I", "G1002A", "G1002B", "G1002C", "G1002D", "G0908A", "G0908B", "G0908C", - "G0908D", "G0908E", "G0908F", "G0908G", "DG0906", "DG0904", "G0902A", "G0902B", - "G0902C", "G0902D", "G0804A", "G0804B", "G0804C", "G0804D", "G0804E", "G0804F", - "G0802A", "G0802B", "G0802C", "G0802D", "G0710A", "G0710B", "G0710C", "G0710D", - "G0710E", "G0710F", "DG0708", "DG0704", "G0702A", "G0702B", "G0702C", "G0702D", - "G0604A", "G0604B", "G0604C", "G0604D", "G0604E", "G0604F", "G0602A", "G0602B", - "G0602C", "G0602D", "G0506A", "G0506B", "G0506C", "G0506D", "G0506E", "G0506F", - "G0506G", "G0504A", "G0504B", "G0504C", "G0504D", "DG0502", "G0404A", "G0404B", - "G0404C", "G0404D", "G0404E", "G0404F", "G0402A", "G0402B", "G0402C", "G0402D", - "G0306A", "G0306B", "G0306C", "G0306D", "G0306E", "G0306F", "G0306G", "G0306H", - "G0304A", "G0304B", "G0304C", "G0304D", "DG0302", "G0206A", "G0206B", "G0206C", - "G0206D", "G0206E", "G0204A", "G0204B", "G0204C", "G0204D", "G0202A", "G0202B", - "G0202C", "G0202D", "G0202E", "G0110A", "G0110B", "G0110C", "G0110D", "G0110E", - "DG0108", "G0106A", "G0106B", "G0106C", "DG0104"); - List trainList = - List.of("301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312"); + private void refreshTestData() { Map offsetMap = new HashMap<>(trainList.size()); // 列车到达位置 Map trainInfoMap = new HashMap<>(trainList.size()); // 列车信息集合 for (int i = 0, len = trainList.size(); i < len; i++) { @@ -126,12 +140,18 @@ public class LineDeviceStatusService { offsetMap.put(code, offset); trainInfoMap.put(code, builder); } + AtomicInteger count = new AtomicInteger(0); Executors.newSingleThreadScheduledExecutor() .scheduleWithFixedDelay( () -> { + log.info("数据处理第" + count.incrementAndGet() + "次"); + List codeList = randomTrainList(); List builders = new LinkedList<>(); trainInfoMap.forEach( (k, v) -> { + if (!codeList.contains(k)) { + return; + } List path = v.getDirection() % 2 == 0 ? rightPathList : leftPathList; // 如果已经到达目的地 if (offsetMap.get(k) == v.getDestinationId()) { @@ -146,10 +166,28 @@ public class LineDeviceStatusService { } builders.add(v.clone()); }); - DeviceStatusDataRepository.addDeviceStatusDataList("3", builders); + DeviceStatusDataRepository.addDeviceStatusDataList(dataKey, builders); }, 1500, 1500, TimeUnit.MILLISECONDS); } + + public List randomTrainList() { + int num = (int) (Math.random() * trainList.size()); + List codeList = new ArrayList<>(num); + try { + for (int i = 0, len = trainList.size(); i < num; i++, len--) { + int index = (int) (Math.random() * len); + String code = trainList.get(index); + trainList.set(index, trainList.get(trainList.size() - 1)); + trainList.set(trainList.size() - 1, code); + codeList.add(code); + } + } catch (Exception e) { + log.error("获取列车列表出错", e); + } + + return codeList; + } } diff --git a/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java index bfa022b..ed87205 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java @@ -1,15 +1,27 @@ package club.joylink.xiannccda.ws; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; +import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage; +import com.google.protobuf.Descriptors.FieldDescriptor.Type; +import com.google.protobuf.Message; +import com.google.protobuf.GeneratedMessageV3.Builder; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Function; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.CollectionUtils; /** 线网图websocket消息服务 */ @Slf4j public class LineNetMessageServer implements IMessageServer { + final DeviceStatusData dataSource; + + public LineNetMessageServer(DeviceStatusData dataSource) { + this.dataSource = dataSource; + } + @Override public String getDestinationPattern() { return "/queue/lineNet"; @@ -18,7 +30,16 @@ public class LineNetMessageServer implements IMessageServer { @Override public Object onSubscription(String destination, Map paramMap) { log.info("【线网订阅】发布全量数据"); - byte[] bytes = new byte[1]; + WsLineNetMessage message = + commonCollectFunction( + (fieldType) -> { + Map deviceMap = dataSource.getAllDeviceMap().get(fieldType); + if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态,则全部放入 + return deviceMap.values().stream().map(Builder::build).toList(); + } + return List.of(); + }); + byte[] bytes = message.toByteArray(); log.info("【线网订阅】全量数据量:" + bytes.length); return bytes; } @@ -31,9 +52,36 @@ public class LineNetMessageServer implements IMessageServer { @Override public List onTick() { List topicMessages = new ArrayList<>(); - byte[] bytes = new byte[1]; + WsLineNetMessage message = + commonCollectFunction( + (fieldType) -> dataSource.getStatusVOMap().getOrDefault(fieldType, List.of())); + byte[] bytes = message.toByteArray(); + // 清空增量 + dataSource.getStatusVOMap().clear(); log.info("【线网订阅】数据状态变化量:" + bytes.length); topicMessages.add(new TopicMessage(this.getDestinationPattern(), bytes)); return topicMessages; } + + /** + * 公共处理部分 + * + * @param compareFun 额外的处理逻辑 + * @return 消息内容 + */ + public WsLineNetMessage commonCollectFunction(Function> compareFun) { + WsLineNetMessage.Builder builder = WsLineNetMessage.newBuilder(); + // 消息体字段列表 + builder.getDescriptorForType().getFields().stream() + .filter(f -> f.getType().equals(Type.MESSAGE)) + .forEach( + field -> { + String fieldType = field.getMessageType().getName(); // 字段类型 + List allDeviceList = compareFun.apply(fieldType); + if (!CollectionUtils.isEmpty(allDeviceList)) { + builder.setField(field, allDeviceList); + } + }); + return builder.build(); + } } diff --git a/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java b/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java index c74f841..b224642 100644 --- a/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java +++ b/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java @@ -33,11 +33,6 @@ public class WsMessageServerManager { public WsMessageServerManager(SimpMessagingTemplate smt) { this.smt = smt; - // 注册线网消息服务 - registerMessageServer(new LineNetMessageServer()); - - registerMessageServer( - new TestMessageServer2("3", DeviceStatusDataRepository.getDeviceStatusData("3"))); } public void registerMessageServer(IMessageServer messageServer) { From ea14a277d0f767f9f3908e6a660e04fce4822a2f Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 20 Jun 2023 15:53:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E3=80=90=E5=88=97=E8=BD=A6websocket?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E6=AE=B5=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/protos/DeviceStatusProto.java | 249 +++--------------- 1 file changed, 42 insertions(+), 207 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/dto/protos/DeviceStatusProto.java b/src/main/java/club/joylink/xiannccda/dto/protos/DeviceStatusProto.java index 521f71c..5aea293 100644 --- a/src/main/java/club/joylink/xiannccda/dto/protos/DeviceStatusProto.java +++ b/src/main/java/club/joylink/xiannccda/dto/protos/DeviceStatusProto.java @@ -19201,27 +19201,10 @@ public final class DeviceStatusProto { * 列车状态 * * - * .state.TrainMode mode = 16; - * @return Whether the mode field is set. - */ - boolean hasMode(); - /** - *
-     * 列车状态
-     * 
- * - * .state.TrainMode mode = 16; + * int32 mode = 16; * @return The mode. */ - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode getMode(); - /** - *
-     * 列车状态
-     * 
- * - * .state.TrainMode mode = 16; - */ - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder getModeOrBuilder(); + int getMode(); /** *
@@ -19747,41 +19730,18 @@ public final class DeviceStatusProto {
     }
 
     public static final int MODE_FIELD_NUMBER = 16;
-    private club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode mode_;
+    private int mode_ = 0;
     /**
      * 
      * 列车状态
      * 
* - * .state.TrainMode mode = 16; - * @return Whether the mode field is set. - */ - @java.lang.Override - public boolean hasMode() { - return mode_ != null; - } - /** - *
-     * 列车状态
-     * 
- * - * .state.TrainMode mode = 16; + * int32 mode = 16; * @return The mode. */ @java.lang.Override - public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode getMode() { - return mode_ == null ? club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_; - } - /** - *
-     * 列车状态
-     * 
- * - * .state.TrainMode mode = 16; - */ - @java.lang.Override - public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder getModeOrBuilder() { - return mode_ == null ? club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_; + public int getMode() { + return mode_; } public static final int NCCWINDOW_FIELD_NUMBER = 17; @@ -19995,8 +19955,8 @@ public final class DeviceStatusProto { if (routeId_ != 0) { output.writeInt32(15, routeId_); } - if (mode_ != null) { - output.writeMessage(16, getMode()); + if (mode_ != 0) { + output.writeInt32(16, mode_); } if (nccWindow_ != 0) { output.writeInt32(17, nccWindow_); @@ -20086,9 +20046,9 @@ public final class DeviceStatusProto { size += com.google.protobuf.CodedOutputStream .computeInt32Size(15, routeId_); } - if (mode_ != null) { + if (mode_ != 0) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(16, getMode()); + .computeInt32Size(16, mode_); } if (nccWindow_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -20167,11 +20127,8 @@ public final class DeviceStatusProto { .equals(other.getDriverId())) return false; if (getRouteId() != other.getRouteId()) return false; - if (hasMode() != other.hasMode()) return false; - if (hasMode()) { - if (!getMode() - .equals(other.getMode())) return false; - } + if (getMode() + != other.getMode()) return false; if (getNccWindow() != other.getNccWindow()) return false; if (getNccWindowOffset() @@ -20232,10 +20189,8 @@ public final class DeviceStatusProto { hash = (53 * hash) + getDriverId().hashCode(); hash = (37 * hash) + ROUTEID_FIELD_NUMBER; hash = (53 * hash) + getRouteId(); - if (hasMode()) { - hash = (37 * hash) + MODE_FIELD_NUMBER; - hash = (53 * hash) + getMode().hashCode(); - } + hash = (37 * hash) + MODE_FIELD_NUMBER; + hash = (53 * hash) + getMode(); hash = (37 * hash) + NCCWINDOW_FIELD_NUMBER; hash = (53 * hash) + getNccWindow(); hash = (37 * hash) + NCCWINDOWOFFSET_FIELD_NUMBER; @@ -20403,11 +20358,7 @@ public final class DeviceStatusProto { recordTime_ = 0L; driverId_ = ""; routeId_ = 0; - mode_ = null; - if (modeBuilder_ != null) { - modeBuilder_.dispose(); - modeBuilder_ = null; - } + mode_ = 0; nccWindow_ = 0; nccWindowOffset_ = 0; rate_ = 0; @@ -20495,9 +20446,7 @@ public final class DeviceStatusProto { result.routeId_ = routeId_; } if (((from_bitField0_ & 0x00008000) != 0)) { - result.mode_ = modeBuilder_ == null - ? mode_ - : modeBuilder_.build(); + result.mode_ = mode_; } if (((from_bitField0_ & 0x00010000) != 0)) { result.nccWindow_ = nccWindow_; @@ -20592,8 +20541,8 @@ public final class DeviceStatusProto { if (other.getRouteId() != 0) { setRouteId(other.getRouteId()); } - if (other.hasMode()) { - mergeMode(other.getMode()); + if (other.getMode() != 0) { + setMode(other.getMode()); } if (other.getNccWindow() != 0) { setNccWindow(other.getNccWindow()); @@ -20722,13 +20671,11 @@ public final class DeviceStatusProto { bitField0_ |= 0x00004000; break; } // case 120 - case 130: { - input.readMessage( - getModeFieldBuilder().getBuilder(), - extensionRegistry); + case 128: { + mode_ = input.readInt32(); bitField0_ |= 0x00008000; break; - } // case 130 + } // case 128 case 136: { nccWindow_ = input.readInt32(); bitField0_ |= 0x00010000; @@ -21694,51 +21641,31 @@ public final class DeviceStatusProto { return this; } - private club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode mode_; - private com.google.protobuf.SingleFieldBuilderV3< - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder> modeBuilder_; + private int mode_ ; /** *
        * 列车状态
        * 
* - * .state.TrainMode mode = 16; - * @return Whether the mode field is set. - */ - public boolean hasMode() { - return ((bitField0_ & 0x00008000) != 0); - } - /** - *
-       * 列车状态
-       * 
- * - * .state.TrainMode mode = 16; + * int32 mode = 16; * @return The mode. */ - public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode getMode() { - if (modeBuilder_ == null) { - return mode_ == null ? club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_; - } else { - return modeBuilder_.getMessage(); - } + @java.lang.Override + public int getMode() { + return mode_; } /** *
        * 列车状态
        * 
* - * .state.TrainMode mode = 16; + * int32 mode = 16; + * @param value The mode to set. + * @return This builder for chaining. */ - public Builder setMode(club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode value) { - if (modeBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - mode_ = value; - } else { - modeBuilder_.setMessage(value); - } + public Builder setMode(int value) { + + mode_ = value; bitField0_ |= 0x00008000; onChanged(); return this; @@ -21748,106 +21675,15 @@ public final class DeviceStatusProto { * 列车状态 *
* - * .state.TrainMode mode = 16; - */ - public Builder setMode( - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder builderForValue) { - if (modeBuilder_ == null) { - mode_ = builderForValue.build(); - } else { - modeBuilder_.setMessage(builderForValue.build()); - } - bitField0_ |= 0x00008000; - onChanged(); - return this; - } - /** - *
-       * 列车状态
-       * 
- * - * .state.TrainMode mode = 16; - */ - public Builder mergeMode(club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode value) { - if (modeBuilder_ == null) { - if (((bitField0_ & 0x00008000) != 0) && - mode_ != null && - mode_ != club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance()) { - getModeBuilder().mergeFrom(value); - } else { - mode_ = value; - } - } else { - modeBuilder_.mergeFrom(value); - } - bitField0_ |= 0x00008000; - onChanged(); - return this; - } - /** - *
-       * 列车状态
-       * 
- * - * .state.TrainMode mode = 16; + * int32 mode = 16; + * @return This builder for chaining. */ public Builder clearMode() { bitField0_ = (bitField0_ & ~0x00008000); - mode_ = null; - if (modeBuilder_ != null) { - modeBuilder_.dispose(); - modeBuilder_ = null; - } + mode_ = 0; onChanged(); return this; } - /** - *
-       * 列车状态
-       * 
- * - * .state.TrainMode mode = 16; - */ - public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder getModeBuilder() { - bitField0_ |= 0x00008000; - onChanged(); - return getModeFieldBuilder().getBuilder(); - } - /** - *
-       * 列车状态
-       * 
- * - * .state.TrainMode mode = 16; - */ - public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder getModeOrBuilder() { - if (modeBuilder_ != null) { - return modeBuilder_.getMessageOrBuilder(); - } else { - return mode_ == null ? - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_; - } - } - /** - *
-       * 列车状态
-       * 
- * - * .state.TrainMode mode = 16; - */ - private com.google.protobuf.SingleFieldBuilderV3< - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder> - getModeFieldBuilder() { - if (modeBuilder_ == null) { - modeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder>( - getMode(), - getParentForChildren(), - isClean()); - mode_ = null; - } - return modeBuilder_; - } private int nccWindow_ ; /** @@ -22508,20 +22344,19 @@ public final class DeviceStatusProto { "ipModeTrainDriveModeRmr\030! \001(\010\022 \n\030ipModeT" + "rainDriveModeWash\030\" \001(\010\022\n\n\002id\030# \001(\t\".\n\020O" + "ccNccFepNetwork\022\n\n\002id\030\001 \001(\t\022\016\n\006active\030\002 " + - "\001(\010\"\311\003\n\005Train\022\017\n\007trainId\030\001 \001(\t\022\020\n\010global" + + "\001(\010\"\267\003\n\005Train\022\017\n\007trainId\030\001 \001(\t\022\020\n\010global" + "Id\030\002 \001(\t\022\017\n\007groupId\030\003 \001(\t\022\022\n\nlocalSubId\030" + "\004 \001(\005\022\021\n\ttrainType\030\005 \001(\005\022\r\n\005speed\030\006 \001(\002\022" + "\021\n\tdirection\030\007 \001(\005\022\025\n\rdestinationId\030\010 \001(" + "\005\022\021\n\tstationId\030\t \001(\005\022\016\n\006sideId\030\n \001(\005\022\021\n\t" + "trackName\030\013 \001(\t\022\022\n\nrecordType\030\014 \001(\010\022\022\n\nr" + "ecordTime\030\r \001(\003\022\020\n\010driverId\030\016 \001(\t\022\017\n\007rou" + - "teId\030\017 \001(\005\022\036\n\004mode\030\020 \001(\0132\020.state.TrainMo" + - "de\022\021\n\tnccWindow\030\021 \001(\005\022\027\n\017nccWindowOffset" + - "\030\022 \001(\005\022\014\n\004rate\030\023 \001(\005\022\017\n\007devType\030\024 \001(\005\022\017\n" + - "\007devName\030\025 \001(\t\022\021\n\tblockFlag\030\026 \001(\005\022\014\n\004sho" + - "w\030\027 \001(\010\022\016\n\006lineId\030\030 \001(\005B6\n!club.joylink." + - "xiannccda.dto.protosB\021DeviceStatusProtob" + - "\006proto3" + "teId\030\017 \001(\005\022\014\n\004mode\030\020 \001(\005\022\021\n\tnccWindow\030\021 " + + "\001(\005\022\027\n\017nccWindowOffset\030\022 \001(\005\022\014\n\004rate\030\023 \001" + + "(\005\022\017\n\007devType\030\024 \001(\005\022\017\n\007devName\030\025 \001(\t\022\021\n\t" + + "blockFlag\030\026 \001(\005\022\014\n\004show\030\027 \001(\010\022\016\n\006lineId\030" + + "\030 \001(\005B6\n!club.joylink.xiannccda.dto.prot" + + "osB\021DeviceStatusProtob\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData,