From bca7885be7c97199dde6795845836ef4d36426c4 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 28 Jun 2023 16:01:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=88=97=E8=BD=A6=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BD=AC=E6=8D=A2=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collect/DeviceStatusConvertorManager.java | 4 +- .../LineNetTrainRecordConvertor.java | 1 + .../LineNetTrainRemoveConvertor.java | 64 ++++++++++++++++++ .../LineNetTrainUpdateConvertor.java | 67 +++++++++++++++++++ .../service/LineDeviceStatusService.java | 12 +++- 5 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRemoveConvertor.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusConvertorManager.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusConvertorManager.java index 6234b30..73639a7 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusConvertorManager.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusConvertorManager.java @@ -20,9 +20,9 @@ public class DeviceStatusConvertorManager { * @param msgId 消息ID * @param convertor 转换对象 */ - public static void addStatusConvertor(MessageId msgId, DeviceStatusConvertor convertor) { + public static void addStatusConvertor(DeviceStatusConvertor convertor) { Map convertorMap = - CONVERTOR_MAP.computeIfAbsent(msgId, k -> new ConcurrentHashMap<>()); + CONVERTOR_MAP.computeIfAbsent(convertor.getMessageId(), k -> new ConcurrentHashMap<>()); convertorMap.put(convertor.getClass().getSimpleName(), convertor); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRecordConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRecordConvertor.java index 2a9a778..8f514b1 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRecordConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRecordConvertor.java @@ -42,6 +42,7 @@ public class LineNetTrainRecordConvertor extends DeviceStatusConvertor { offset.setGroupId(response.getGroupId()); // 车组号 offset.setDestinationId(response.getDestinationId()); // 目的地ID offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向 + offset.setShow(true); // 显示 // 获取到当前区段公里标 List kmCodeList = LineGraphicDataRepository.getSectionDefaultKmCodeList( diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRemoveConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRemoveConvertor.java new file mode 100644 index 0000000..54a47bc --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainRemoveConvertor.java @@ -0,0 +1,64 @@ +package club.joylink.xiannccda.ats.message.collect.convertor; + +import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository; +import club.joylink.xiannccda.ats.message.MessageData; +import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationRemoveResponse; +import club.joylink.xiannccda.dto.protos.WsMessageProto; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.common.collect.Lists; +import com.google.protobuf.GeneratedMessageV3.Builder; +import java.util.List; +import java.util.Objects; +import lombok.extern.slf4j.Slf4j; + +/** 列车信息移除时,线网信息处理 */ +@Slf4j +public class LineNetTrainRemoveConvertor extends DeviceStatusConvertor { + + final DeviceStatusData dataSource; + + public LineNetTrainRemoveConvertor(DeviceStatusData dataSource) { + this.dataSource = dataSource; + } + + @Override + public MessageId getMessageId() { + return MessageId.TRAIN_INDICATION_REMOVE; + } + + @Override + public void run(List messageDataList) { + try { + List buildList = Lists.newArrayList(); + for (MessageData data : messageDataList) { + if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致 + TrainIndicationRemoveResponse response = (TrainIndicationRemoveResponse) data; + WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset = + WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder(); + offset.setLineId(response.getLineId()); + offset.setGroupId(response.getGroupId()); + offset.setTrainIndex(response.getTrainIndex()); + offset.setShow(false); + // 获取到当前区段公里标 + if (DeviceType.DEVICE_TYPE_TRACK.equals(response.getDevType())) { + List kmCodeList = + LineGraphicDataRepository.getSectionDefaultKmCodeList( + response.getLineId(), response.getDevName()); + if (CollectionUtils.isNotEmpty(kmCodeList)) { + offset.setKilometerCode(kmCodeList.get(0)); + } + } + buildList.add(offset); + } + } + DeviceStatusDataOperate.addDevices(buildList, dataSource); + } catch (Exception e) { + log.error("移除列车信息", e); + } + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java new file mode 100644 index 0000000..a48af6f --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainUpdateConvertor.java @@ -0,0 +1,67 @@ +package club.joylink.xiannccda.ats.message.collect.convertor; + +import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository; +import club.joylink.xiannccda.ats.message.MessageData; +import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationRemoveResponse; +import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse; +import club.joylink.xiannccda.dto.protos.WsMessageProto; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.common.collect.Lists; +import com.google.protobuf.GeneratedMessageV3.Builder; +import java.util.List; +import java.util.Objects; +import lombok.extern.slf4j.Slf4j; + +/** 列车信息更新时,信息转换 */ +@Slf4j +public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor { + + final DeviceStatusData dataSource; + + public LineNetTrainUpdateConvertor(DeviceStatusData dataSource) { + this.dataSource = dataSource; + } + + @Override + public MessageId getMessageId() { + return MessageId.TRAIN_INDICATION_UPDATE; + } + + @Override + public void run(List messageDataList) { + try { + List buildList = Lists.newArrayList(); + for (MessageData data : messageDataList) { + if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致 + TrainIndicationUpdateResponse response = (TrainIndicationUpdateResponse) data; + WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset = + WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder(); + offset.setLineId(response.getLineId()); // 线路id + offset.setTrainIndex(response.getTrainIndex()); // 列车标示号,全线唯一 + offset.setGroupId(response.getGroupId()); // 车组号 + offset.setDestinationId(response.getDestinationId()); // 目的地ID + offset.setShow(true); // 是否显示 + offset.setDir(0); // 初始设置无运行方向 + // 获取到当前区段公里标 + if (DeviceType.DEVICE_TYPE_TRACK.equals(response.getDevType())) { + List kmCodeList = + LineGraphicDataRepository.getSectionDefaultKmCodeList( + response.getLineId(), response.getDevName()); + if (CollectionUtils.isNotEmpty(kmCodeList)) { + offset.setKilometerCode(kmCodeList.get(0)); + } + } + buildList.add(offset); + } + } + DeviceStatusDataOperate.addDevices(buildList, dataSource); + } catch (Exception e) { + log.error("移除列车信息", e); + } + } +} diff --git a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java index c95045b..dfa488f 100644 --- a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java +++ b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java @@ -7,6 +7,8 @@ import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainInitConvertor; import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRecordConvertor; +import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRemoveConvertor; +import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainUpdateConvertor; import club.joylink.xiannccda.mock.message.NccMockDataService; import club.joylink.xiannccda.ws.IMessageServer; import club.joylink.xiannccda.ws.LineDeviceMessageServer; @@ -44,10 +46,16 @@ public class LineDeviceStatusService { DeviceStatusData deviceStatusData = DeviceStatusDataRepository.getDeviceStatusData(DATA_KEY); // 添加初始化转换方法 LineNetTrainInitConvertor initConvertor = new LineNetTrainInitConvertor(deviceStatusData); - DeviceStatusConvertorManager.addStatusConvertor(initConvertor.getMessageId(), initConvertor); + DeviceStatusConvertorManager.addStatusConvertor(initConvertor); // 列车报点信息转换方法 LineNetTrainRecordConvertor recConvertor = new LineNetTrainRecordConvertor(deviceStatusData); - DeviceStatusConvertorManager.addStatusConvertor(recConvertor.getMessageId(), recConvertor); + DeviceStatusConvertorManager.addStatusConvertor(recConvertor); + // 列车更新转换方法 + LineNetTrainUpdateConvertor updateConvertor = new LineNetTrainUpdateConvertor(deviceStatusData); + DeviceStatusConvertorManager.addStatusConvertor(updateConvertor); + // 列车删除转换方法 + LineNetTrainRemoveConvertor removeConvertor = new LineNetTrainRemoveConvertor(deviceStatusData); + DeviceStatusConvertorManager.addStatusConvertor(removeConvertor); // websocket发送服务 IMessageServer iMessageServer = new LineNetMessageServer(deviceStatusData); wsMessageServerManager.registerMessageServer(iMessageServer);