From e51f673364728f3d8dc6552d5c8234899e75be67 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Fri, 30 Jun 2023 13:53:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ats/message/MessageResponse.java | 2 + .../message/collect/DeviceDataRepository.java | 57 +++++++++++++++ .../ats/message/collect/DeviceStatusData.java | 30 -------- .../collect/DeviceStatusDataOperate.java | 15 +++- .../collect/DeviceStatusDataRepository.java | 16 +--- .../convertor/LineNetTrainInitConvertor.java | 7 +- .../LineNetTrainRecordConvertor.java | 3 +- .../LineNetTrainRemoveConvertor.java | 7 +- .../LineNetTrainUpdateConvertor.java | 7 +- .../collect/datasource/AbstractData.java | 19 +++++ .../collect/datasource/DeviceStatusData.java | 48 ++++++++++++ .../TrainDataSource.java} | 70 +++++++++--------- .../convertor/DeviceStatusConvertor.java | 46 ++++++------ .../{rep => device}/ScheduleSubIdType.java | 2 +- .../line3/rep/HistoryScheduleResponse.java | 2 +- .../line3/rep/InusedScheduleResponse.java | 2 +- .../line3/rep/NetworkAliveStatusResponse.java | 4 +- .../rep/TrainIndicationUpdateResponse.java | 4 +- .../line3/rep/TrainRecordResponse.java | 73 +++++++++++-------- .../xiannccda/configuration/JsonConfig.java | 5 ++ .../mock/message/MockAppContext.java | 4 +- .../xiannccda/mock/message/MockLoadData.java | 31 ++++---- .../xiannccda/mock/message/NccMockData.java | 4 + .../mock/message/NccMockDataService.java | 20 +++-- .../message/event/MockMessageDataHandle.java | 20 +++-- .../service/LineDeviceStatusService.java | 8 +- .../xiannccda/ws/LineDeviceMessageServer.java | 14 ++-- .../xiannccda/ws/LineNetMessageServer.java | 7 +- .../xiannccda/ws/LineTrainMessageServer.java | 12 ++- .../xiannccda/ws/WsMessageServerManager.java | 4 - .../xiannccda/device/DeviceStatusTest.java | 5 +- .../xiannccda/device/TrainDataTest.java | 5 +- .../xiannccda/service/MockMsgTest.java | 5 +- xian-ncc-da-message | 2 +- 34 files changed, 357 insertions(+), 203 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceDataRepository.java delete mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusData.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/AbstractData.java create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/DeviceStatusData.java rename src/main/java/club/joylink/xiannccda/ats/message/collect/{TrainInfoData.java => datasource/TrainDataSource.java} (51%) rename src/main/java/club/joylink/xiannccda/ats/message/line3/{rep => device}/ScheduleSubIdType.java (85%) diff --git a/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java index e61dbf0..b1e3adc 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java @@ -10,6 +10,8 @@ public abstract class MessageResponse extends MessageData { public void encode2(ByteBuf buf) { } + public abstract Short getLineId(); + @Override public List generateProto() throws Exception { return null; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceDataRepository.java new file mode 100644 index 0000000..e3b6e39 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceDataRepository.java @@ -0,0 +1,57 @@ +package club.joylink.xiannccda.ats.message.collect; + +import club.joylink.xiannccda.ats.message.collect.datasource.AbstractData; +import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData; +import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource; +import com.google.common.collect.Maps; +import com.google.protobuf.GeneratedMessageV3.Builder; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; + +/** + * 状态信息初始化 + */ +@Getter +public class DeviceDataRepository { + + static Map device_data = Maps.newConcurrentMap(); + + + private static synchronized AbstractData find(String lineId, DataTypeEnum dataTypeEnum) { + AbstractData ad = device_data.get(lineId); + if (Objects.isNull(ad)) { + try { + ad = dataTypeEnum.clazz.getDeclaredConstructor(String.class).newInstance(lineId); + device_data.put(lineId, ad); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return ad; + } + + public static void add(String lineId, List data, DataTypeEnum dataTypeEnum) { + AbstractData ad = find(lineId, dataTypeEnum); + ad.addDevice(data); + } + + public static T findDataSouce(String lineId, DataTypeEnum dataType) { + AbstractData data = find(lineId, dataType); + return (T) data; + } + + public enum DataTypeEnum { + DEVICE(DeviceStatusData.class), TRAIN(TrainDataSource.class), + ; + + Class clazz; + + DataTypeEnum(Class clazz) { + this.clazz = clazz; + + } + + } +} 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 deleted file mode 100644 index cae4a26..0000000 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusData.java +++ /dev/null @@ -1,30 +0,0 @@ -package club.joylink.xiannccda.ats.message.collect; - -import com.google.protobuf.GeneratedMessageV3.Builder; -import com.google.protobuf.Message; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; -import lombok.Getter; - -/** 线路设备状态信息 */ -@Getter -public class DeviceStatusData { - - /** 线路号 */ - private String lineCode; - - /** 所有设备状态信息 <设备类型【这里用的message的类名:Rtu、Signal等】,<设备主键,设备信息>> */ - private Map> allDeviceMap = new ConcurrentHashMap<>(); - - /** 增量的设备更新信息 */ - private Map> statusVOMap = new ConcurrentHashMap<>(); - - /** 同步锁 */ - private Lock lock = new ReentrantLock(); - - 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 65b74c2..11a43ca 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,5 +1,6 @@ package club.joylink.xiannccda.ats.message.collect; +import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData; import com.google.protobuf.GeneratedMessageV3.Builder; import com.google.protobuf.Message; import java.util.HashMap; @@ -10,13 +11,19 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import org.springframework.util.CollectionUtils; -/** 线路设备操作方法 */ +/** + * 线路设备操作方法 + */ public abstract class DeviceStatusDataOperate { - /** 默认的主键名称 */ + /** + * 默认的主键名称 + */ private static final String DEFAULT_ID_NAME = "id"; - /** 设备主键名称映射 */ + /** + * 设备主键名称映射 + */ private static final Map DEVICE_ID_NAME_MAP = Map.of( "LineNetTrainOffsetDiagram", @@ -30,7 +37,7 @@ public abstract class DeviceStatusDataOperate { * 批量放入设备状态 * * @param builders 要添加的设备状态列表 - * @param data 存储内存 + * @param data 存储内存 */ public static void addDevices(List builders, DeviceStatusData data) { if (data == null || builders == null) { 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 c5d9c99..acfec30 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,5 +1,6 @@ package club.joylink.xiannccda.ats.message.collect; +import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData; import com.google.protobuf.GeneratedMessageV3.Builder; import java.util.List; import java.util.Map; @@ -17,21 +18,6 @@ public abstract class DeviceStatusDataRepository { */ private static final Map lineStatusDataMap = new ConcurrentHashMap<>(); - private static final Map trainDataMap = new ConcurrentHashMap<>(); - - - public static void addTrain(String lineCode, List builders) { - TrainInfoData data = getAllTrainInfo(lineCode); - for (Builder builder : builders) { - data.addTrain(builder); - } - } - - - public static TrainInfoData getAllTrainInfo(String lineId) { - return trainDataMap.computeIfAbsent(lineId, TrainInfoData::new); - } - /** * 批量增加 diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java index 694e8da..8af595f 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/LineNetTrainInitConvertor.java @@ -4,8 +4,9 @@ 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.collect.datasource.DeviceStatusData; import club.joylink.xiannccda.ats.message.line3.device.DeviceType; import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationInitResponse; import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationInitResponse.TrainCell; @@ -17,7 +18,9 @@ import java.util.List; import java.util.Objects; import lombok.extern.slf4j.Slf4j; -/** 接收列车初始化消息,就收转换线网的列车数据 */ +/** + * 接收列车初始化消息,就收转换线网的列车数据 + */ @Slf4j public class LineNetTrainInitConvertor extends DeviceStatusConvertor { 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 5e7472a..2772cc1 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 @@ -4,8 +4,9 @@ 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.collect.datasource.DeviceStatusData; import club.joylink.xiannccda.ats.message.line3.rep.TrainRecordResponse; import club.joylink.xiannccda.dto.protos.WsMessageProto; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 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 index bf93bf5..90b308f 100644 --- 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 @@ -4,8 +4,9 @@ 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.collect.datasource.DeviceStatusData; 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; @@ -16,7 +17,9 @@ import java.util.List; import java.util.Objects; import lombok.extern.slf4j.Slf4j; -/** 列车信息移除时,线网信息处理 */ +/** + * 列车信息移除时,线网信息处理 + */ @Slf4j public class LineNetTrainRemoveConvertor extends DeviceStatusConvertor { 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 index de49f67..891da14 100644 --- 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 @@ -4,8 +4,9 @@ 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.collect.datasource.DeviceStatusData; 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; @@ -17,7 +18,9 @@ import java.util.List; import java.util.Objects; import lombok.extern.slf4j.Slf4j; -/** 列车信息更新时,信息转换 */ +/** + * 列车信息更新时,信息转换 + */ @Slf4j public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor { diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/AbstractData.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/AbstractData.java new file mode 100644 index 0000000..7e197b4 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/AbstractData.java @@ -0,0 +1,19 @@ +package club.joylink.xiannccda.ats.message.collect.datasource; + +import club.joylink.xiannccda.ats.message.MessageData; +import com.google.protobuf.GeneratedMessageV3; +import java.util.List; + +public abstract class AbstractData { + + public final String lineId; + + public AbstractData(String lineId) { + this.lineId = lineId; + } + + public abstract void addDevice(List dataList); + + public abstract void clear(); + +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/DeviceStatusData.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/DeviceStatusData.java new file mode 100644 index 0000000..fab4fe9 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/DeviceStatusData.java @@ -0,0 +1,48 @@ +package club.joylink.xiannccda.ats.message.collect.datasource; + +import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; +import com.google.protobuf.GeneratedMessageV3; +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 java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import lombok.Getter; + +@Getter +public class DeviceStatusData extends AbstractData { + + /** + * 所有设备状态信息 <设备类型【这里用的message的类名:Rtu、Signal等】,<设备主键,设备信息>> + */ + private Map> allDeviceMap = new ConcurrentHashMap<>(); + + /** + * 增量的设备更新信息 + */ + private Map> statusVOMap = new ConcurrentHashMap<>(); + + /** + * 同步锁 + */ + private Lock lock = new ReentrantLock(); + + + public DeviceStatusData(String lineId) { + super(lineId); + } + + @Override + public void addDevice(List dataList) { + + DeviceStatusDataOperate.addDevices(dataList, this); + } + + @Override + public void clear() { + this.allDeviceMap.clear(); + this.statusVOMap.clear(); + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/TrainInfoData.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/TrainDataSource.java similarity index 51% rename from src/main/java/club/joylink/xiannccda/ats/message/collect/TrainInfoData.java rename to src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/TrainDataSource.java index 5d5fa7e..8d1f4c6 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/TrainInfoData.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/datasource/TrainDataSource.java @@ -1,33 +1,27 @@ -package club.joylink.xiannccda.ats.message.collect; +package club.joylink.xiannccda.ats.message.collect.datasource; +import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo; +import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo.Builder; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Maps; import com.google.common.collect.Table; import com.google.common.collect.Tables; import com.google.protobuf.Descriptors.FieldDescriptor; -import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.Message; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.Objects; import org.apache.commons.lang3.StringUtils; -/** - * 线路设备状态信息 - */ - -public class TrainInfoData { - - /** - * 线路号 - */ - private final String lineCode; +public class TrainDataSource extends AbstractData { /** * 所有设备状态信息 <列车类型 【这里用的message的类名:TrainInfo等】,<车组号,列车信息>> */ - private Map allTrainInfoMaper = Maps.newConcurrentMap(); + private Map allTrainInfoMaper = Maps.newConcurrentMap(); /** * 增量的设备更新信息 @@ -36,30 +30,32 @@ public class TrainInfoData { private final static String TRAIN_INFO_NAME = "TrainInfo"; private final static String TRAIN_INFO_ID = "groupId"; - public TrainInfoData(String lineCode) { - this.lineCode = lineCode; + public TrainDataSource(String lineId) { + super(lineId); } - - public void addTrain(Builder builder) { - Object idVal = builder.getField(builder.getDescriptorForType().findFieldByName(TRAIN_INFO_ID)); - String typeName = builder.getDescriptorForType().getName(); - Message message = builder.build(); - if (StringUtils.equals(typeName, TRAIN_INFO_NAME)) { - Builder trainBuild = allTrainInfoMaper.get(idVal.toString()); - if (Objects.isNull(trainBuild)) { - trainBuild = builder; + @Override + public void addDevice(List dataList) { + for (GeneratedMessageV3.Builder builder : dataList) { + Object idVal = builder.getField(builder.getDescriptorForType().findFieldByName(TRAIN_INFO_ID)); + String typeName = builder.getDescriptorForType().getName(); + Message message = builder.build(); + if (StringUtils.equals(typeName, TRAIN_INFO_NAME)) { + GeneratedMessageV3.Builder trainBuild = allTrainInfoMaper.get(idVal.toString()); + if (Objects.isNull(trainBuild)) { + trainBuild = builder; + } else { + trainBuild.mergeFrom(message); + } + if (trainBuild instanceof TrainInfo.Builder trainInfo) { + trainInfo.clearBlock(); + trainInfo.clearRemove(); + trainInfo.clearRecord(); + allTrainInfoMaper.put(idVal.toString(), trainInfo); + } } else { - trainBuild.mergeFrom(message); + trainUpdate.put(typeName, idVal.toString(), message); } - if (trainBuild instanceof TrainInfo.Builder trainInfo) { - trainInfo.clearBlock(); - trainInfo.clearRemove(); - trainInfo.clearRecord(); - allTrainInfoMaper.put(idVal.toString(), trainInfo); - } - } else { - trainUpdate.put(typeName, idVal.toString(), message); } } @@ -82,7 +78,13 @@ public class TrainInfoData { } } - public Collection getAllTrain() { + public Collection getAllTrain() { return this.allTrainInfoMaper.values(); } + + @Override + public void clear() { + this.allTrainInfoMaper.clear(); + this.trainUpdate.clear(); + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/convertor/DeviceStatusConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/convertor/DeviceStatusConvertor.java index b070298..e1ada56 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/convertor/DeviceStatusConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/convertor/DeviceStatusConvertor.java @@ -2,6 +2,8 @@ package club.joylink.xiannccda.ats.message.convertor; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus; +import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.SIGNAL; +import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.Status; import club.joylink.xiannccda.ats.message.line3.device.DeviceType; import club.joylink.xiannccda.dto.protos.DeviceStatusProto; import com.google.protobuf.Descriptors.FieldDescriptor; @@ -102,14 +104,14 @@ public class DeviceStatusConvertor { * @param deviceStatusEnum 如DeviceStatus.SIGNAL.class * @param statusBitMap 该设备的符合状态位图 */ - public static T convert(final Class deviceStatusEnum, final int statusBitMap) throws Exception { + public static T convert(final Class deviceStatusEnum, final int statusBitMap) throws Exception { final GeneratedMessageV3.Builder to = findBy(deviceStatusEnum); convert(deviceStatusEnum, statusBitMap, to); return (T) to; } public static T convert(DeviceType deviceType, final int statusBitMap) throws Exception { - Class deviceStatusEnum = findByEnum(deviceType); + Class deviceStatusEnum = findByEnum(deviceType); return convert(deviceStatusEnum, statusBitMap); } @@ -118,19 +120,16 @@ public class DeviceStatusConvertor { build.setField(fieldId, vals); } - public static void copyAttr(GeneratedMessageV3.Builder build, String attrName, Object... vals) { - Class targetClass = build.getClass(); - Optional optional = Arrays.stream(targetClass.getMethods()).filter(d -> StringUtils.startsWith(d.getName(), "set") && StringUtils.endsWithIgnoreCase(d.getName(), attrName)).findFirst(); - if (optional.isEmpty()) { - //TODO + +/* public static void convert(DeviceStatus.Status deviceStatusEnum, final int statusBitMap, final GeneratedMessageV3.Builder to) { + for (Status status : deviceStatusEnum.vals()) { + final String enumUnitName = status.toString(); + final int devStateMask = status.mask(); + final String fieldName = toFieldName(enumUnitName); + FieldDescriptor fieldDescriptor = to.getDescriptorForType().findFieldByName(fieldName); + to.setField(fieldDescriptor, devStateMask == (statusBitMap & devStateMask)); } - Method method = optional.get(); - try { - method.invoke(build, vals); - } catch (Exception e) { - throw new RuntimeException("拷贝数据错误 name=" + attrName, e); - } - } + }*/ /** * 把设备位图状态转换为proto定义的设备状态 @@ -139,8 +138,8 @@ public class DeviceStatusConvertor { * @param statusBitMap 该设备的符合状态位图 * @param to proto设备状态 */ - public static void convert(final Class deviceStatusEnum, final int statusBitMap, final GeneratedMessageV3.Builder to) throws Exception { - final Class toClass = to.getClass(); + public static void convert(final Class deviceStatusEnum, final int statusBitMap, final GeneratedMessageV3.Builder to) throws Exception { +// final Class toClass = to.getClass(); final Method enumValues = deviceStatusEnum.getMethod("values"); final Object values = enumValues.invoke(deviceStatusEnum); final int len = Array.getLength(values); @@ -148,9 +147,12 @@ public class DeviceStatusConvertor { final DeviceStatus.Status devStateEnum = (DeviceStatus.Status) Array.get(values, i); final String enumUnitName = devStateEnum.toString(); final int devStateMask = devStateEnum.mask(); - final String setName = toSetName(enumUnitName); - final Method setMethod = toClass.getMethod(setName, boolean.class); - setMethod.invoke(to, devStateMask == (statusBitMap & devStateMask)); + String fieldName = toFieldName(enumUnitName); + FieldDescriptor toFieldDescName = to.getDescriptorForType().findFieldByName(fieldName); + to.setField(toFieldDescName, devStateMask == (statusBitMap & devStateMask)); +// final String setName = toSetName(enumUnitName); +// final Method setMethod = toClass.getMethod(setName, boolean.class); +// setMethod.invoke(to, devStateMask == (statusBitMap & devStateMask)); } } @@ -159,8 +161,10 @@ public class DeviceStatusConvertor { */ public static void main(String[] args) throws Exception { final int bitMap = DeviceStatus.SIGNAL.GREEN_OPEN.mask() | DeviceStatus.SIGNAL.GREEN_FLASH.mask(); - final DeviceStatusProto.Signal.Builder signal = convert(DeviceStatus.SIGNAL.class, bitMap); + DeviceStatusProto.Signal.Builder signal = convert(DeviceStatus.SIGNAL.class, bitMap); System.out.println(String.format("==>>greenOpen = %s greenFlash = %s blueFlash = %s", signal.getGreenOpen(), signal.getGreenFlash(), signal.getBlueFlash())); +// signal = convert(, bitMap); +// System.out.println(String.format("==>>greenOpen = %s greenFlash = %s blueFlash = %s", signal.getGreenOpen(), signal.getGreenFlash(), signal.getBlueFlash())); } /** @@ -183,7 +187,7 @@ public class DeviceStatusConvertor { } } - public static Class findByEnum(DeviceType deviceType) { + public static Class findByEnum(DeviceType deviceType) { switch (deviceType) { case DEVICE_TYPE_SWITCH: return DeviceStatus.SWITCH.class; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/ScheduleSubIdType.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/device/ScheduleSubIdType.java similarity index 85% rename from src/main/java/club/joylink/xiannccda/ats/message/line3/rep/ScheduleSubIdType.java rename to src/main/java/club/joylink/xiannccda/ats/message/line3/device/ScheduleSubIdType.java index b7c9ce4..69f90fd 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/ScheduleSubIdType.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/device/ScheduleSubIdType.java @@ -1,4 +1,4 @@ -package club.joylink.xiannccda.ats.message.line3.rep; +package club.joylink.xiannccda.ats.message.line3.device; import java.util.Arrays; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/HistoryScheduleResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/HistoryScheduleResponse.java index ab27c66..47566b8 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/HistoryScheduleResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/HistoryScheduleResponse.java @@ -1,8 +1,8 @@ package club.joylink.xiannccda.ats.message.line3.rep; -import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.ats.message.line3.DateTimeUtil; +import club.joylink.xiannccda.ats.message.line3.device.ScheduleSubIdType; import club.joylink.xiannccda.ats.message.line3.rep.EntityParseUtil.ReadData; import io.netty.buffer.ByteBuf; import java.time.LocalDateTime; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java index ca444cc..832539d 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java @@ -1,8 +1,8 @@ package club.joylink.xiannccda.ats.message.line3.rep; -import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.ats.message.line3.DateTimeUtil; +import club.joylink.xiannccda.ats.message.line3.device.ScheduleSubIdType; import club.joylink.xiannccda.ats.message.line3.rep.EntityParseUtil.ReadData; import io.netty.buffer.ByteBuf; import java.time.LocalDateTime; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/NetworkAliveStatusResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/NetworkAliveStatusResponse.java index 4259cf0..88e8e24 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/NetworkAliveStatusResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/NetworkAliveStatusResponse.java @@ -21,7 +21,7 @@ public class NetworkAliveStatusResponse extends MessageResponse { /** * 线路号(2) */ - private Short linId; + private Short lineId; /** * 状态字节(1): @@ -38,7 +38,7 @@ public class NetworkAliveStatusResponse extends MessageResponse { @Override public void decode2(ByteBuf buf) throws Exception { - this.linId = buf.readShort(); + this.lineId = buf.readShort(); this.connect = buf.readByte() == 1; } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationUpdateResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationUpdateResponse.java index 51de5c1..8c70cf0 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationUpdateResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationUpdateResponse.java @@ -140,8 +140,8 @@ public class TrainIndicationUpdateResponse extends MessageResponse { train.setTrainIndex(this.trainIndex); train.setRollingStock(this.getRollingStock()); train.setOtpTime(this.optTime); - train.setArriveTime(this.arriveTime.toEpochSecond(ZoneOffset.ofHours(8)) * 1000); - train.setDepartTime(this.departTime.toEpochSecond(ZoneOffset.ofHours(8)) * 1000); + train.setArriveTime(this.arriveTime.toEpochSecond(ZoneOffset.ofHours(8))); + train.setDepartTime(this.departTime.toEpochSecond(ZoneOffset.ofHours(8))); DeviceStatusProto.TrainMode.Builder trainMode = DeviceStatusConvertor.convert(DeviceStatus.TRAIN_MODE.class, this.mode); train.setMode(trainMode.build()); diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainRecordResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainRecordResponse.java index c4389ef..d799b51 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainRecordResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainRecordResponse.java @@ -18,52 +18,68 @@ import lombok.Getter; import java.time.LocalDateTime; import lombok.Setter; -/** 2.7.8列车报点消息 */ +/** + * 2.7.8列车报点消息 + */ @Getter @Setter public class TrainRecordResponse extends MessageResponse { - /** 线路号(2) */ + /** + * 线路号(2) + */ private Short lineId; - /** 表号(9) */ + /** + * 表号(9) + */ private String trainId; - /** 车次号(12) */ + /** + * 车次号(12) + */ private String globalId; - /** 局部序列号(4) */ + /** + * 局部序列号(4) + */ private Integer localSubId; - /** 车组号(9) */ + /** + * 车组号(9) + */ private String groupId; - /** 目的地(4) */ + /** + * 目的地(4) + */ private Integer destinationId; /** - * 列车类型(2) 0x01:计划车
- * 0x02:头码车
- * 0x03:M0车
- * 0x04:MM车
+ * 列车类型(2) 0x01:计划车
0x02:头码车
0x03:M0车
0x04:MM车
*/ private TrainTypeEnum trainType; /** - * 运行方向(1) 0x01:下行
- * 0x02:上行
- * 0x00:无方向
+ * 运行方向(1) 0x01:下行
0x02:上行
0x00:无方向
*/ private DirectionEnum direction; - /** 站号(2) */ + /** + * 站号(2) + */ private Short stationId; - /** 站台编号(2) */ + /** + * 站台编号(2) + */ private Short sideId; - /** 轨道名称(小区段名称)(20) */ + /** + * 轨道名称(小区段名称)(20) + */ private String trackName; /** - * 到发点类型(2)
- * 0x01H:到达
- * 0x02H:出发
- * true-到达,false-出发 + * 到发点类型(2)
0x01H:到达
0x02H:出发
true-到达,false-出发 */ private Boolean recordType; - /** 到发时间(7) */ + /** + * 到发时间(7) + */ private LocalDateTime recordTime; - /** 预留(4) */ + /** + * 预留(4) + */ private byte[] reserve = new byte[4]; @Override @@ -139,15 +155,13 @@ public class TrainRecordResponse extends MessageResponse { builder.setRecordType(this.getRecordType()); } if (this.getRecordTime() != null) { - builder.setRecordTime(this.getRecordTime().toEpochSecond(ZoneOffset.ofHours(8)) * 1000); + builder.setRecordTime(this.getRecordTime().toEpochSecond(ZoneOffset.ofHours(8))); } return Lists.newArrayList(builder); } /** - * 运行方向(1) 0x01:下行
- * 0x02:上行
- * 0x00:无方向
+ * 运行方向(1) 0x01:下行
0x02:上行
0x00:无方向
*/ @Getter public static enum DirectionEnum { @@ -172,10 +186,7 @@ public class TrainRecordResponse extends MessageResponse { } /** - * 列车类型(2) 0x01:计划车
- * 0x02:头码车
- * 0x03:M0车
- * 0x04:MM车
+ * 列车类型(2) 0x01:计划车
0x02:头码车
0x03:M0车
0x04:MM车
*/ public static enum TrainTypeEnum { PlannedTrain(0x01), diff --git a/src/main/java/club/joylink/xiannccda/configuration/JsonConfig.java b/src/main/java/club/joylink/xiannccda/configuration/JsonConfig.java index 1c41baa..0753b35 100644 --- a/src/main/java/club/joylink/xiannccda/configuration/JsonConfig.java +++ b/src/main/java/club/joylink/xiannccda/configuration/JsonConfig.java @@ -18,6 +18,7 @@ import org.springframework.context.annotation.Configuration; @Configuration public class JsonConfig implements ApplicationRunner { + public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @Bean @@ -50,4 +51,8 @@ public class JsonConfig implements ApplicationRunner { } }); } + + public static void main(String[] args) { + LocalDateTime.parse("2023-06-27 17:50:51.5856917", DATE_TIME_FORMATTER); + } } diff --git a/src/main/java/club/joylink/xiannccda/mock/message/MockAppContext.java b/src/main/java/club/joylink/xiannccda/mock/message/MockAppContext.java index 3c3d7ed..f68bbe9 100644 --- a/src/main/java/club/joylink/xiannccda/mock/message/MockAppContext.java +++ b/src/main/java/club/joylink/xiannccda/mock/message/MockAppContext.java @@ -1,6 +1,7 @@ package club.joylink.xiannccda.mock.message; import club.joylink.xiannccda.ats.message.MessageData; +import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.mock.message.event.MockMessageDataEvent; import com.alibaba.fastjson2.JSON; import java.io.BufferedOutputStream; @@ -20,7 +21,8 @@ public class MockAppContext implements ApplicationContextAware { private static ApplicationContext appContext; public static void publish(List datas) { - appContext.publishEvent(new MockMessageDataEvent(datas)); + List newList = datas.stream().filter(d -> d.getMsgId() != MessageId.MESSAGE_POLLING).toList(); + appContext.publishEvent(new MockMessageDataEvent(newList)); } /*private final static String path = ""; diff --git a/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java b/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java index 787401f..61733ec 100644 --- a/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java +++ b/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java @@ -1,8 +1,9 @@ package club.joylink.xiannccda.mock.message; -import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; +import club.joylink.xiannccda.ats.message.MessageResponse; +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository; +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum; import club.joylink.xiannccda.mock.message.NccMockData.ActionTypeEnum; import club.joylink.xiannccda.mock.message.NccMockData.MsgTypeEnum; import club.joylink.xiannccda.mock.message.NccMockDataService.DataType; @@ -26,7 +27,7 @@ public class MockLoadData implements ApplicationRunner { static final ScheduledExecutorService CIRCLE_QUERY_THREAD = Executors.newSingleThreadScheduledExecutor(); private final NccMockDataService nccMockDataService; - + @Override public void run(ApplicationArguments args) throws Exception { this.nccMockDataService.reset(1); @@ -44,11 +45,11 @@ public class MockLoadData implements ApplicationRunner { .eq(NccMockData::getActionType, ActionTypeEnum.ALL.name()) .eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name()) .eq(NccMockData::getMsgId, MessageId.DEVICE_STATUS_BITMAP.name()); - List dataList = this.nccMockDataService.loadALLData(wrapper); + List dataList = this.nccMockDataService.loadALLData(wrapper); try { - for (MessageData messageData : dataList) { + for (MessageResponse messageData : dataList) { List builders = messageData.generateProto(); - DeviceStatusDataRepository.addDeviceStatusDataList("3", builders); + DeviceDataRepository.add(messageData.getLineId().toString(), builders, DataTypeEnum.DEVICE); } } catch (Exception e) { e.printStackTrace(); @@ -61,12 +62,12 @@ public class MockLoadData implements ApplicationRunner { .eq(NccMockData::getActionType, ActionTypeEnum.ALL.name()) .eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name()) .eq(NccMockData::getMsgId, MessageId.TRAIN_INDICATION_INIT.name()); - List dataList = this.nccMockDataService.loadALLData(wrapper); + List dataList = this.nccMockDataService.loadALLData(wrapper); try { - for (MessageData messageData : dataList) { + for (MessageResponse messageData : dataList) { List builders = messageData.generateProto(); - DeviceStatusDataRepository.addTrain("3", builders); + DeviceDataRepository.add(messageData.getLineId().toString(), builders, DataTypeEnum.TRAIN); } } catch (Exception e) { e.printStackTrace(); @@ -75,13 +76,13 @@ public class MockLoadData implements ApplicationRunner { } private void loadTrain() { - List messageDataList = this.nccMockDataService.getMessageData(DataType.TRAIN); + List messageDataList = this.nccMockDataService.getMessageData(DataType.TRAIN); if (CollectionUtils.isEmpty(messageDataList)) { System.out.println("没有新的数据"); } - for (MessageData messageData : messageDataList) { + for (MessageResponse messageData : messageDataList) { try { - DeviceStatusDataRepository.addTrain("3", messageData.generateProto()); + DeviceDataRepository.add(messageData.getLineId().toString(), messageData.generateProto(), DataTypeEnum.TRAIN); } catch (Exception e) { e.printStackTrace(); } @@ -89,13 +90,13 @@ public class MockLoadData implements ApplicationRunner { } private void loadDevice() { - List messageDataList = this.nccMockDataService.getMessageData(DataType.TRAIN); + List messageDataList = this.nccMockDataService.getMessageData(DataType.DEVICE); if (CollectionUtils.isEmpty(messageDataList)) { System.out.println("没有新的数据"); } - for (MessageData messageData : messageDataList) { + for (MessageResponse messageData : messageDataList) { try { - DeviceStatusDataRepository.addDeviceStatusDataList("3", messageData.generateProto()); + DeviceDataRepository.add(messageData.getLineId().toString(), messageData.generateProto(), DataTypeEnum.DEVICE); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/club/joylink/xiannccda/mock/message/NccMockData.java b/src/main/java/club/joylink/xiannccda/mock/message/NccMockData.java index 1d1180b..cfc8758 100644 --- a/src/main/java/club/joylink/xiannccda/mock/message/NccMockData.java +++ b/src/main/java/club/joylink/xiannccda/mock/message/NccMockData.java @@ -36,6 +36,8 @@ public class NccMockData { private String msgId; + private Short lineId; + public static final String ID = "id"; public static final String MOCK_DATA = "mock_data"; @@ -47,6 +49,8 @@ public class NccMockData { public static final String MSG_ID = "msg_id"; + public static final String line_id = "line_id"; + public enum MsgTypeEnum { REAL_TIME, UNREAL_TIME diff --git a/src/main/java/club/joylink/xiannccda/mock/message/NccMockDataService.java b/src/main/java/club/joylink/xiannccda/mock/message/NccMockDataService.java index ceddfab..203901f 100644 --- a/src/main/java/club/joylink/xiannccda/mock/message/NccMockDataService.java +++ b/src/main/java/club/joylink/xiannccda/mock/message/NccMockDataService.java @@ -2,10 +2,13 @@ package club.joylink.xiannccda.mock.message; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.mock.message.NccMockData.ActionTypeEnum; import club.joylink.xiannccda.mock.message.NccMockData.MsgTypeEnum; import club.joylink.xiannccda.repository.impl.NccMockDataRepository; import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.JSONReader; +import com.alibaba.fastjson2.JSONReader.Feature; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -58,10 +61,10 @@ public class NccMockDataService { } } - public List loadALLData(Wrapper wrapp) { + public List loadALLData(Wrapper wrapp) { List nccMockData = this.nccMockDataRepository.list(wrapp); List list = this.parse(nccMockData); - return list; + return list.stream().map(d -> (MessageResponse) d).toList(); } public List loadAllTrainInitData() { @@ -92,7 +95,7 @@ public class NccMockDataService { return this.parse(updateMockData); } - public List getMessageData(DataType dataType) { + public List getMessageData(DataType dataType) { if (this.isLast()) { return Collections.emptyList(); } @@ -103,13 +106,13 @@ public class NccMockDataService { NccMockData mockData = list.get(list.size() - 1); LAST_ID = mockData.getId(); } - return this.parse(list); + return this.parse(list).stream().map(d -> (MessageResponse) d).toList(); } private List parse(List list) { List dataList = Lists.newArrayListWithCapacity(list.size()); for (NccMockData data : list) { - JSONObject jo = JSONObject.parse(data.getMockData()); + JSONObject jo = JSONObject.parse(data.getMockData(), Feature.Base64StringAsByteArray); this.parse(jo, dataList); } return dataList; @@ -118,7 +121,7 @@ public class NccMockDataService { private void parse(JSONObject jo, List dataList) { Integer msgId = jo.getInteger("msgId"); Class clazz = MessageId.of(msgId).create().getClass(); - MessageData md = jo.to(clazz); + MessageData md = jo.to(clazz, Feature.Base64StringAsByteArray); dataList.add(md); } @@ -137,7 +140,7 @@ public class NccMockDataService { } public enum DataType { - DEVICE(List.of("DEVICE_STATUS_CHANGE", "SIGNAL_ROUTE_STATUS", "DEVICE_STATUS_CHANGE")), + DEVICE(List.of("DEVICE_STATUS_CHANGE", "SIGNAL_ROUTE_STATUS")), TRAIN( List.of( "TRAIN_RECORD", @@ -146,7 +149,8 @@ public class NccMockDataService { "TRAIN_BLOCK_INFO")), ALL(List.of()); - @Getter List typeList; + @Getter + List typeList; DataType(List typeList) { this.typeList = typeList; diff --git a/src/main/java/club/joylink/xiannccda/mock/message/event/MockMessageDataHandle.java b/src/main/java/club/joylink/xiannccda/mock/message/event/MockMessageDataHandle.java index 0f16e58..cebb403 100644 --- a/src/main/java/club/joylink/xiannccda/mock/message/event/MockMessageDataHandle.java +++ b/src/main/java/club/joylink/xiannccda/mock/message/event/MockMessageDataHandle.java @@ -3,11 +3,14 @@ package club.joylink.xiannccda.mock.message.event; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.mock.message.NccMockData; import club.joylink.xiannccda.mock.message.NccMockData.ActionTypeEnum; import club.joylink.xiannccda.mock.message.NccMockData.MsgTypeEnum; import club.joylink.xiannccda.repository.INccMockDataRepository; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.JSONWriter.Feature; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; @@ -30,12 +33,17 @@ public class MockMessageDataHandle { if (obj instanceof List) { List datas = (List) obj; for (MessageData data : datas) { - NccMockData td = new NccMockData(); - td.setMockData(JSON.toJSONString(data)); - td.setMockReceiveTime(localDateTime); - td.setMsgId(data.getMsgId().name()); - this.setMsgType(td, data); - iNccMockDataRepository.save(td); + if (data instanceof MessageResponse response) { + NccMockData td = new NccMockData(); + td.setMockData(JSON.toJSONString(data, Feature.WriteByteArrayAsBase64)); + td.setMockReceiveTime(localDateTime); + td.setMsgId(data.getMsgId().name()); + + td.setLineId(response.getLineId()); + this.setMsgType(td, data); + iNccMockDataRepository.save(td); + } + } } } diff --git a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java index dfa488f..8441c49 100644 --- a/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java +++ b/src/main/java/club/joylink/xiannccda/service/LineDeviceStatusService.java @@ -3,12 +3,14 @@ package club.joylink.xiannccda.service; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertorManager; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; + +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository; 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.ats.message.collect.datasource.DeviceStatusData; import club.joylink.xiannccda.mock.message.NccMockDataService; import club.joylink.xiannccda.ws.IMessageServer; import club.joylink.xiannccda.ws.LineDeviceMessageServer; @@ -23,7 +25,9 @@ import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -/** 线路设备信息更新 */ +/** + * 线路设备信息更新 + */ @Slf4j @Service public class LineDeviceStatusService { diff --git a/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java index cf74516..d45b1a6 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineDeviceMessageServer.java @@ -1,8 +1,10 @@ package club.joylink.xiannccda.ws; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository; +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; +import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData; import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineMessage; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -38,11 +40,12 @@ public class LineDeviceMessageServer implements IMessageServer { public Object onSubscription(String destination, Map paramMap) { String lineId = paramMap.get("lineId"); this.lineIdSet.add(lineId); - DeviceStatusData statusData = DeviceStatusDataRepository.getDeviceStatusData(lineId); + DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE); + log.info("线路lineId={}订阅,发布全量数据", lineId); WsLineMessage.Builder builder = WsLineMessage.newBuilder(); fillBuilderFunction(fun -> { - Map builderMap = statusData.getAllDeviceMap().get(fun); + Map builderMap = deviceDataSource.getAllDeviceMap().get(fun); if (Objects.isNull(builderMap)) { return Map.of(); } @@ -69,8 +72,9 @@ public class LineDeviceMessageServer implements IMessageServer { List messages = Lists.newArrayList(); for (String lineId : this.lineIdSet) { WsLineMessage.Builder msg = WsLineMessage.newBuilder(); - DeviceStatusData statusData = DeviceStatusDataRepository.getDeviceStatusData(lineId); - fillBuilderFunction((field) -> statusData.getStatusVOMap().get(field), msg); + DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE); +// DeviceStatusData statusData = DeviceStatusDataRepository.getDeviceStatusData(lineId); + fillBuilderFunction((field) -> deviceDataSource.getStatusVOMap().get(field), msg); DeviceStatusDataOperate.clearStatusVOMap(DeviceStatusDataRepository.getDeviceStatusData(lineId)); String destination = this.createPlace("lineId", lineId); messages.add(new TopicMessage(destination, msg.build().toByteArray())); diff --git a/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java index a7e252d..8d5386b 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineNetMessageServer.java @@ -1,7 +1,8 @@ package club.joylink.xiannccda.ws; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusData; + import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; +import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData; import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage; import com.google.protobuf.Descriptors.FieldDescriptor.Type; import com.google.protobuf.Message; @@ -14,7 +15,9 @@ import java.util.function.Function; import lombok.extern.slf4j.Slf4j; import org.springframework.util.CollectionUtils; -/** 线网图websocket消息服务 */ +/** + * 线网图websocket消息服务 + */ @Slf4j public class LineNetMessageServer implements IMessageServer { diff --git a/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java index 2e19c04..116b5ee 100644 --- a/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/LineTrainMessageServer.java @@ -1,7 +1,8 @@ package club.joylink.xiannccda.ws; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; -import club.joylink.xiannccda.ats.message.collect.TrainInfoData; +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository; +import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum; +import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource; import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo; import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo.Builder; import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineTrainMessage; @@ -20,6 +21,7 @@ public class LineTrainMessageServer implements IMessageServer { private final static String SUBSCRIPTION_PATH = "/queue/line/{lineId}/train"; private final Set lineIdSet = Sets.newHashSet(); + @Override public String getDestinationPattern() { return SUBSCRIPTION_PATH; @@ -30,7 +32,9 @@ public class LineTrainMessageServer implements IMessageServer { String lineId = paramMap.get("lineId"); lineIdSet.add(lineId); log.info("线路lineId={}订阅车辆信息,发布全量数据", lineId); - Collection trains = DeviceStatusDataRepository.getAllTrainInfo(lineId).getAllTrain(); + TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN); + + Collection trains = trainDataSource.getAllTrain(); List trainMsg = trains.stream().map(TrainInfo.Builder::build).toList(); WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder(); trainMessage.addAllTrainInfo(trainMsg); @@ -50,7 +54,7 @@ public class LineTrainMessageServer implements IMessageServer { List messages = Lists.newArrayList(); for (String lineId : this.lineIdSet) { - TrainInfoData trainInfoData = DeviceStatusDataRepository.getAllTrainInfo(lineId); + TrainDataSource trainInfoData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN); WsLineTrainMessage.Builder trainMessage = WsLineTrainMessage.newBuilder(); for (TrainInfo.Builder trainInfo : trainInfoData.getAllTrain()) { diff --git a/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java b/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java index 5383258..47e267f 100644 --- a/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java +++ b/src/main/java/club/joylink/xiannccda/ws/WsMessageServerManager.java @@ -1,9 +1,7 @@ package club.joylink.xiannccda.ws; -import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -16,9 +14,7 @@ import org.springframework.messaging.simp.stomp.StompHeaderAccessor; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.stereotype.Component; import org.springframework.util.AntPathMatcher; -import org.springframework.web.socket.messaging.SessionDisconnectEvent; import org.springframework.web.socket.messaging.SessionSubscribeEvent; -import org.springframework.web.socket.messaging.SessionUnsubscribeEvent; @Component @Slf4j diff --git a/src/test/java/club/joylink/xiannccda/device/DeviceStatusTest.java b/src/test/java/club/joylink/xiannccda/device/DeviceStatusTest.java index 003e87a..fca78e0 100644 --- a/src/test/java/club/joylink/xiannccda/device/DeviceStatusTest.java +++ b/src/test/java/club/joylink/xiannccda/device/DeviceStatusTest.java @@ -2,6 +2,7 @@ package club.joylink.xiannccda.device; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; import club.joylink.xiannccda.ats.message.convertor.DeviceStatusConvertor; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus; @@ -127,8 +128,8 @@ public class DeviceStatusTest { .eq(NccMockData::getActionType, ActionTypeEnum.ALL.name()) .eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name()); - List messageData = this.dataService.loadALLData(wrapper); - for (MessageData messageDatum : messageData) { + List messageData = this.dataService.loadALLData(wrapper); + for (MessageResponse messageDatum : messageData) { List msgs = messageDatum.generateProto(); System.out.println(messageDatum); System.out.println(messageDatum.generateProto()); diff --git a/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java b/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java index 6aac0c6..5b3fec7 100644 --- a/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java +++ b/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java @@ -2,6 +2,7 @@ package club.joylink.xiannccda.device; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.ats.message.convertor.DeviceStatusConvertor; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.PLATFORM; @@ -199,8 +200,8 @@ public class TrainDataTest { .eq(NccMockData::getActionType, ActionTypeEnum.ALL.name()) .eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name()); - List messageData = this.dataService.loadALLData(wrapper); - for (MessageData messageDatum : messageData) { + List messageData = this.dataService.loadALLData(wrapper); + for (MessageResponse messageDatum : messageData) { List msgs = messageDatum.generateProto(); System.out.println(messageDatum); System.out.println(messageDatum.generateProto()); diff --git a/src/test/java/club/joylink/xiannccda/service/MockMsgTest.java b/src/test/java/club/joylink/xiannccda/service/MockMsgTest.java index 0c82414..433b43a 100644 --- a/src/test/java/club/joylink/xiannccda/service/MockMsgTest.java +++ b/src/test/java/club/joylink/xiannccda/service/MockMsgTest.java @@ -2,6 +2,7 @@ package club.joylink.xiannccda.service; import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.ats.message.line3.DateTimeUtil; import club.joylink.xiannccda.ats.message.line3.MessageCons; import club.joylink.xiannccda.ats.message.line3.rep.ActionReportResponse; @@ -100,7 +101,7 @@ public class MockMsgTest { @Test public void findMockData() { - List dataList = this.dataService.getMessageData(DataType.DEVICE); + List dataList = this.dataService.getMessageData(DataType.DEVICE); System.out.println(dataList); } @@ -108,7 +109,7 @@ public class MockMsgTest { public void findAll() { int i = 0; while (!this.dataService.finish()) { - List dataList = this.dataService.getMessageData(DataType.DEVICE); + List dataList = this.dataService.getMessageData(DataType.DEVICE); System.out.println((i++) + "----->" + dataList.size()); } } diff --git a/xian-ncc-da-message b/xian-ncc-da-message index a850c9b..3c2bb59 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit a850c9b8b6bb71db94daaf8a394aff290a76cfd0 +Subproject commit 3c2bb59efdec816062b4a3055fa527804f9c256a