数据存储调整
This commit is contained in:
parent
06699a176a
commit
e51f673364
@ -10,6 +10,8 @@ public abstract class MessageResponse extends MessageData {
|
||||
public void encode2(ByteBuf buf) {
|
||||
}
|
||||
|
||||
public abstract Short getLineId();
|
||||
|
||||
@Override
|
||||
public List<Builder> generateProto() throws Exception {
|
||||
return null;
|
||||
|
@ -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<String, AbstractData> 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<Builder> data, DataTypeEnum dataTypeEnum) {
|
||||
AbstractData ad = find(lineId, dataTypeEnum);
|
||||
ad.addDevice(data);
|
||||
}
|
||||
|
||||
public static <T extends AbstractData> T findDataSouce(String lineId, DataTypeEnum dataType) {
|
||||
AbstractData data = find(lineId, dataType);
|
||||
return (T) data;
|
||||
}
|
||||
|
||||
public enum DataTypeEnum {
|
||||
DEVICE(DeviceStatusData.class), TRAIN(TrainDataSource.class),
|
||||
;
|
||||
|
||||
Class<? extends AbstractData> clazz;
|
||||
|
||||
DataTypeEnum(Class<? extends AbstractData> clazz) {
|
||||
this.clazz = clazz;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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<String, Map<String, Builder>> allDeviceMap = new ConcurrentHashMap<>();
|
||||
|
||||
/** 增量的设备更新信息 */
|
||||
private Map<String, Map<String, Message>> statusVOMap = new ConcurrentHashMap<>();
|
||||
|
||||
/** 同步锁 */
|
||||
private Lock lock = new ReentrantLock();
|
||||
|
||||
public DeviceStatusData(String lineCode) {
|
||||
this.lineCode = lineCode;
|
||||
}
|
||||
}
|
@ -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<String, String> 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<Builder> builders, DeviceStatusData data) {
|
||||
if (data == null || builders == null) {
|
||||
|
@ -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<String, DeviceStatusData> lineStatusDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, TrainInfoData> trainDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public static void addTrain(String lineCode, List<Builder> builders) {
|
||||
TrainInfoData data = getAllTrainInfo(lineCode);
|
||||
for (Builder builder : builders) {
|
||||
data.addTrain(builder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static TrainInfoData getAllTrainInfo(String lineId) {
|
||||
return trainDataMap.computeIfAbsent(lineId, TrainInfoData::new);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量增加
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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<GeneratedMessageV3.Builder> dataList);
|
||||
|
||||
public abstract void clear();
|
||||
|
||||
}
|
@ -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<String, Map<String, Builder>> allDeviceMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 增量的设备更新信息
|
||||
*/
|
||||
private Map<String, Map<String, Message>> statusVOMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 同步锁
|
||||
*/
|
||||
private Lock lock = new ReentrantLock();
|
||||
|
||||
|
||||
public DeviceStatusData(String lineId) {
|
||||
super(lineId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(List<GeneratedMessageV3.Builder> dataList) {
|
||||
|
||||
DeviceStatusDataOperate.addDevices(dataList, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.allDeviceMap.clear();
|
||||
this.statusVOMap.clear();
|
||||
}
|
||||
}
|
@ -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<String, TrainInfo.Builder> allTrainInfoMaper = Maps.newConcurrentMap();
|
||||
private Map<String, Builder> 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<GeneratedMessageV3.Builder> 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<TrainInfo.Builder> getAllTrain() {
|
||||
public Collection<Builder> getAllTrain() {
|
||||
return this.allTrainInfoMaper.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.allTrainInfoMaper.clear();
|
||||
this.trainUpdate.clear();
|
||||
}
|
||||
}
|
@ -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 extends GeneratedMessageV3.Builder> T convert(final Class<?> deviceStatusEnum, final int statusBitMap) throws Exception {
|
||||
public static <T extends GeneratedMessageV3.Builder> T convert(final Class<? extends DeviceStatus.Status> deviceStatusEnum, final int statusBitMap) throws Exception {
|
||||
final GeneratedMessageV3.Builder to = findBy(deviceStatusEnum);
|
||||
convert(deviceStatusEnum, statusBitMap, to);
|
||||
return (T) to;
|
||||
}
|
||||
|
||||
public static <T extends GeneratedMessageV3.Builder> T convert(DeviceType deviceType, final int statusBitMap) throws Exception {
|
||||
Class<?> deviceStatusEnum = findByEnum(deviceType);
|
||||
Class<? extends DeviceStatus.Status> 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<Method> 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<? extends DeviceStatus.Status> 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<? extends DeviceStatus.Status> findByEnum(DeviceType deviceType) {
|
||||
switch (deviceType) {
|
||||
case DEVICE_TYPE_SWITCH:
|
||||
return DeviceStatus.SWITCH.class;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package club.joylink.xiannccda.ats.message.line3.rep;
|
||||
package club.joylink.xiannccda.ats.message.line3.device;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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:计划车<br>
|
||||
* 0x02:头码车<br>
|
||||
* 0x03:M0车<br>
|
||||
* 0x04:MM车<br>
|
||||
* 列车类型(2) 0x01:计划车<br> 0x02:头码车<br> 0x03:M0车<br> 0x04:MM车<br>
|
||||
*/
|
||||
private TrainTypeEnum trainType;
|
||||
/**
|
||||
* 运行方向(1) 0x01:下行 <br>
|
||||
* 0x02:上行<br>
|
||||
* 0x00:无方向<br>
|
||||
* 运行方向(1) 0x01:下行 <br> 0x02:上行<br> 0x00:无方向<br>
|
||||
*/
|
||||
private DirectionEnum direction;
|
||||
/** 站号(2) */
|
||||
/**
|
||||
* 站号(2)
|
||||
*/
|
||||
private Short stationId;
|
||||
/** 站台编号(2) */
|
||||
/**
|
||||
* 站台编号(2)
|
||||
*/
|
||||
private Short sideId;
|
||||
/** 轨道名称(小区段名称)(20) */
|
||||
/**
|
||||
* 轨道名称(小区段名称)(20)
|
||||
*/
|
||||
private String trackName;
|
||||
/**
|
||||
* 到发点类型(2)<br>
|
||||
* 0x01H:到达<br>
|
||||
* 0x02H:出发<br>
|
||||
* true-到达,false-出发
|
||||
* 到发点类型(2)<br> 0x01H:到达<br> 0x02H:出发<br> 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:下行 <br>
|
||||
* 0x02:上行<br>
|
||||
* 0x00:无方向<br>
|
||||
* 运行方向(1) 0x01:下行 <br> 0x02:上行<br> 0x00:无方向<br>
|
||||
*/
|
||||
@Getter
|
||||
public static enum DirectionEnum {
|
||||
@ -172,10 +186,7 @@ public class TrainRecordResponse extends MessageResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* 列车类型(2) 0x01:计划车<br>
|
||||
* 0x02:头码车<br>
|
||||
* 0x03:M0车<br>
|
||||
* 0x04:MM车<br>
|
||||
* 列车类型(2) 0x01:计划车<br> 0x02:头码车<br> 0x03:M0车<br> 0x04:MM车<br>
|
||||
*/
|
||||
public static enum TrainTypeEnum {
|
||||
PlannedTrain(0x01),
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<MessageData> datas) {
|
||||
appContext.publishEvent(new MockMessageDataEvent(datas));
|
||||
List<MessageData> newList = datas.stream().filter(d -> d.getMsgId() != MessageId.MESSAGE_POLLING).toList();
|
||||
appContext.publishEvent(new MockMessageDataEvent(newList));
|
||||
}
|
||||
|
||||
/*private final static String path = "";
|
||||
|
@ -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<MessageData> dataList = this.nccMockDataService.loadALLData(wrapper);
|
||||
List<MessageResponse> dataList = this.nccMockDataService.loadALLData(wrapper);
|
||||
try {
|
||||
for (MessageData messageData : dataList) {
|
||||
for (MessageResponse messageData : dataList) {
|
||||
List<GeneratedMessageV3.Builder> 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<MessageData> dataList = this.nccMockDataService.loadALLData(wrapper);
|
||||
List<MessageResponse> dataList = this.nccMockDataService.loadALLData(wrapper);
|
||||
try {
|
||||
|
||||
for (MessageData messageData : dataList) {
|
||||
for (MessageResponse messageData : dataList) {
|
||||
List<Builder> 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<MessageData> messageDataList = this.nccMockDataService.getMessageData(DataType.TRAIN);
|
||||
List<MessageResponse> 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<MessageData> messageDataList = this.nccMockDataService.getMessageData(DataType.TRAIN);
|
||||
List<MessageResponse> 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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<MessageData> loadALLData(Wrapper<NccMockData> wrapp) {
|
||||
public List<MessageResponse> loadALLData(Wrapper<NccMockData> wrapp) {
|
||||
List<NccMockData> nccMockData = this.nccMockDataRepository.list(wrapp);
|
||||
List<MessageData> list = this.parse(nccMockData);
|
||||
return list;
|
||||
return list.stream().map(d -> (MessageResponse) d).toList();
|
||||
}
|
||||
|
||||
public List<MessageData> loadAllTrainInitData() {
|
||||
@ -92,7 +95,7 @@ public class NccMockDataService {
|
||||
return this.parse(updateMockData);
|
||||
}
|
||||
|
||||
public List<MessageData> getMessageData(DataType dataType) {
|
||||
public List<MessageResponse> 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<MessageData> parse(List<NccMockData> list) {
|
||||
List<MessageData> 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<MessageData> dataList) {
|
||||
Integer msgId = jo.getInteger("msgId");
|
||||
Class<? extends MessageData> 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<String> typeList;
|
||||
@Getter
|
||||
List<String> typeList;
|
||||
|
||||
DataType(List<String> typeList) {
|
||||
this.typeList = typeList;
|
||||
|
@ -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<MessageData> datas = (List<MessageData>) 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<String, String> 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<String, Builder> builderMap = statusData.getAllDeviceMap().get(fun);
|
||||
Map<String, Builder> builderMap = deviceDataSource.getAllDeviceMap().get(fun);
|
||||
if (Objects.isNull(builderMap)) {
|
||||
return Map.of();
|
||||
}
|
||||
@ -69,8 +72,9 @@ public class LineDeviceMessageServer implements IMessageServer {
|
||||
List<TopicMessage> 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()));
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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<String> 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<Builder> trains = DeviceStatusDataRepository.getAllTrainInfo(lineId).getAllTrain();
|
||||
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN);
|
||||
|
||||
Collection<Builder> trains = trainDataSource.getAllTrain();
|
||||
List<TrainInfo> 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<TopicMessage> 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()) {
|
||||
|
@ -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
|
||||
|
@ -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> messageData = this.dataService.loadALLData(wrapper);
|
||||
for (MessageData messageDatum : messageData) {
|
||||
List<MessageResponse> messageData = this.dataService.loadALLData(wrapper);
|
||||
for (MessageResponse messageDatum : messageData) {
|
||||
List<? extends GeneratedMessageV3.Builder> msgs = messageDatum.generateProto();
|
||||
System.out.println(messageDatum);
|
||||
System.out.println(messageDatum.generateProto());
|
||||
|
@ -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> messageData = this.dataService.loadALLData(wrapper);
|
||||
for (MessageData messageDatum : messageData) {
|
||||
List<MessageResponse> messageData = this.dataService.loadALLData(wrapper);
|
||||
for (MessageResponse messageDatum : messageData) {
|
||||
List<? extends GeneratedMessageV3.Builder> msgs = messageDatum.generateProto();
|
||||
System.out.println(messageDatum);
|
||||
System.out.println(messageDatum.generateProto());
|
||||
|
@ -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<MessageData> dataList = this.dataService.getMessageData(DataType.DEVICE);
|
||||
List<MessageResponse> 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<MessageData> dataList = this.dataService.getMessageData(DataType.DEVICE);
|
||||
List<MessageResponse> dataList = this.dataService.getMessageData(DataType.DEVICE);
|
||||
System.out.println((i++) + "----->" + dataList.size());
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit a850c9b8b6bb71db94daaf8a394aff290a76cfd0
|
||||
Subproject commit 3c2bb59efdec816062b4a3055fa527804f9c256a
|
Loading…
Reference in New Issue
Block a user