【修改线网列车信息更新】
This commit is contained in:
parent
1cd2b8afb8
commit
77e2f2e104
@ -11,33 +11,27 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
/**
|
/** 线路设备操作方法 */
|
||||||
* 线路设备操作方法
|
|
||||||
*/
|
|
||||||
public abstract class DeviceStatusDataOperate {
|
public abstract class DeviceStatusDataOperate {
|
||||||
|
|
||||||
/**
|
/** 默认的主键名称 */
|
||||||
* 默认的主键名称
|
|
||||||
*/
|
|
||||||
private static final String DEFAULT_ID_NAME = "id";
|
private static final String DEFAULT_ID_NAME = "id";
|
||||||
|
|
||||||
/**
|
/** 设备主键名称映射 */
|
||||||
* 设备主键名称映射
|
public static final Map<String, List<String>> DEVICE_ID_NAME_MAP =
|
||||||
*/
|
|
||||||
private static final Map<String, String> DEVICE_ID_NAME_MAP =
|
|
||||||
Map.of(
|
Map.of(
|
||||||
"LineNetTrainOffsetDiagram",
|
"LineNetTrainOffsetDiagram",
|
||||||
"groupId",
|
List.of("groupId"),
|
||||||
"TrainInfo",
|
"TrainInfo",
|
||||||
"groupId",
|
List.of("groupId"),
|
||||||
"WsLineNetTrainOffsetMessage",
|
"WsLineNetTrainOffsetMessage",
|
||||||
"groupId");
|
List.of("lineId", "groupId"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量放入设备状态
|
* 批量放入设备状态
|
||||||
*
|
*
|
||||||
* @param builders 要添加的设备状态列表
|
* @param builders 要添加的设备状态列表
|
||||||
* @param data 存储内存
|
* @param data 存储内存
|
||||||
*/
|
*/
|
||||||
public static void addDevices(List<Builder> builders, DeviceStatusData data) {
|
public static void addDevices(List<Builder> builders, DeviceStatusData data) {
|
||||||
if (data == null || builders == null) {
|
if (data == null || builders == null) {
|
||||||
@ -95,8 +89,12 @@ public abstract class DeviceStatusDataOperate {
|
|||||||
* @param builder 设备状态信息
|
* @param builder 设备状态信息
|
||||||
* @return 状态类型
|
* @return 状态类型
|
||||||
*/
|
*/
|
||||||
private static String findType(Builder builder) {
|
public static String findType(Builder builder) {
|
||||||
return builder.getDefaultInstanceForType().getClass().getSimpleName();
|
return findType(builder.getDefaultInstanceForType().getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String findType(Class<?> cls) {
|
||||||
|
return cls.getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,11 +103,17 @@ public abstract class DeviceStatusDataOperate {
|
|||||||
* @param protoBuilder 数据信息
|
* @param protoBuilder 数据信息
|
||||||
* @return 主键
|
* @return 主键
|
||||||
*/
|
*/
|
||||||
private static String getIdVal(Builder protoBuilder) {
|
public static String getIdVal(Builder protoBuilder) {
|
||||||
String idName = DEVICE_ID_NAME_MAP.getOrDefault(findType(protoBuilder), DEFAULT_ID_NAME);
|
List<String> idKeyNames =
|
||||||
|
DEVICE_ID_NAME_MAP.getOrDefault(findType(protoBuilder), List.of(DEFAULT_ID_NAME));
|
||||||
try {
|
try {
|
||||||
return String.valueOf(
|
return idKeyNames.stream()
|
||||||
protoBuilder.getField(protoBuilder.getDescriptorForType().findFieldByName(idName)));
|
.map(
|
||||||
|
name ->
|
||||||
|
String.valueOf(
|
||||||
|
protoBuilder.getField(
|
||||||
|
protoBuilder.getDescriptorForType().findFieldByName(name))))
|
||||||
|
.collect(Collectors.joining("_"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(protoBuilder.getDescriptorForType().getName());
|
System.err.println(protoBuilder.getDescriptorForType().getName());
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package club.joylink.xiannccda.ats.message.collect.convertor;
|
||||||
|
|
||||||
|
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
||||||
|
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.ats.message.line3.device.DeviceType;
|
||||||
|
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/** 线网的列车数据,一些公共方法 */
|
||||||
|
@Slf4j
|
||||||
|
public abstract class LineNetTrainComMethod {
|
||||||
|
|
||||||
|
public static final String DATA_KEY = "lineNet";
|
||||||
|
|
||||||
|
static final String type =
|
||||||
|
DeviceStatusDataOperate.findType(WsMessageProto.WsLineNetTrainOffsetMessage.class);
|
||||||
|
|
||||||
|
// 设备状态数据集合
|
||||||
|
public static synchronized DeviceStatusData getDeviceStatusData() {
|
||||||
|
return DeviceStatusDataRepository.getDeviceStatusData(DATA_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取已存在的设备状态信息
|
||||||
|
*
|
||||||
|
* @param obj 提供Key信息
|
||||||
|
* @return 旧的设备状态
|
||||||
|
*/
|
||||||
|
public static void getDeviceStatusById(WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj) {
|
||||||
|
Map<String, Builder> builderMap =
|
||||||
|
getDeviceStatusData().getAllDeviceMap().getOrDefault(type, Map.of());
|
||||||
|
String key = DeviceStatusDataOperate.getIdVal(obj);
|
||||||
|
if (builderMap.containsKey(key)) {
|
||||||
|
obj.mergeFrom(builderMap.get(key).build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置公里标信息
|
||||||
|
*
|
||||||
|
* @param obj 要设置的对象
|
||||||
|
* @param type 所在设备类型
|
||||||
|
* @param deviceName 设备名称
|
||||||
|
*/
|
||||||
|
public static void setUpKilometerCode(
|
||||||
|
WsMessageProto.WsLineNetTrainOffsetMessage.Builder obj, DeviceType type, String deviceName) {
|
||||||
|
// 非区段、道岔直接返回
|
||||||
|
if (!DeviceType.DEVICE_TYPE_TRACK.equals(type) && !DeviceType.DEVICE_TYPE_SWITCH.equals(type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 获取到当前区段公里标
|
||||||
|
List<Long> kmList = LineGraphicDataRepository.getKilometerCodeList(obj.getLineId(), deviceName);
|
||||||
|
if (CollectionUtils.isNotEmpty(kmList)) {
|
||||||
|
long kilometer;
|
||||||
|
if (obj.getDir() == 1) { // 下行取大值
|
||||||
|
kilometer = kmList.stream().min(Long::compareTo).get();
|
||||||
|
} else if (obj.getDir() == 2) { // 上行取小值
|
||||||
|
kilometer = kmList.stream().max(Long::compareTo).get();
|
||||||
|
} else { // 无方向获取第一个
|
||||||
|
kilometer = kmList.get(0);
|
||||||
|
}
|
||||||
|
obj.setKilometerCode(kilometer);
|
||||||
|
} else {
|
||||||
|
log.warn(String.format("设备%s没有公里标信息", deviceName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,13 @@
|
|||||||
package club.joylink.xiannccda.ats.message.collect.convertor;
|
package club.joylink.xiannccda.ats.message.collect.convertor;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
|
||||||
import club.joylink.xiannccda.ats.message.MessageData;
|
import club.joylink.xiannccda.ats.message.MessageData;
|
||||||
import club.joylink.xiannccda.ats.message.MessageId;
|
import club.joylink.xiannccda.ats.message.MessageId;
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
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;
|
||||||
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationInitResponse.TrainCell;
|
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationInitResponse.TrainCell;
|
||||||
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -21,13 +17,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
/** 接收列车初始化消息,就收转换线网的列车数据 */
|
/** 接收列车初始化消息,就收转换线网的列车数据 */
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LineNetTrainInitConvertor extends DeviceStatusConvertor {
|
public class LineNetTrainInitConvertor extends DeviceStatusConvertor {
|
||||||
|
|
||||||
final DeviceStatusData dataSource;
|
|
||||||
|
|
||||||
public LineNetTrainInitConvertor(DeviceStatusData dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageId getMessageId() {
|
public MessageId getMessageId() {
|
||||||
return MessageId.TRAIN_INDICATION_INIT;
|
return MessageId.TRAIN_INDICATION_INIT;
|
||||||
@ -46,23 +35,15 @@ public class LineNetTrainInitConvertor extends DeviceStatusConvertor {
|
|||||||
offset.setLineId(response.getLineId()); // 线路id
|
offset.setLineId(response.getLineId()); // 线路id
|
||||||
offset.setTrainIndex(trainCell.getTrainIndex()); // 列车标示号,全线唯一
|
offset.setTrainIndex(trainCell.getTrainIndex()); // 列车标示号,全线唯一
|
||||||
offset.setGroupId(trainCell.getGroupId()); // 车组号
|
offset.setGroupId(trainCell.getGroupId()); // 车组号
|
||||||
offset.setShow(false); // 是否显示
|
|
||||||
offset.setDir(0); // 初始设置无运行方向
|
offset.setDir(0); // 初始设置无运行方向
|
||||||
// 获取到当前区段公里标
|
LineNetTrainComMethod.setUpKilometerCode(
|
||||||
if (DeviceType.DEVICE_TYPE_TRACK.equals(trainCell.getDevType())) {
|
offset, trainCell.getDevType(), trainCell.getDevName());
|
||||||
List<Long> kmCodeList =
|
offset.setShow(offset.getKilometerCode() != 0);
|
||||||
LineGraphicDataRepository.getKilometerCodeList(
|
|
||||||
response.getLineId(), trainCell.getDevName());
|
|
||||||
if (CollectionUtils.isNotEmpty(kmCodeList)) {
|
|
||||||
offset.setShow(true); // 是否显示
|
|
||||||
offset.setKilometerCode(kmCodeList.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buildList.add(offset);
|
buildList.add(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 增加设备信息
|
// 增加设备信息
|
||||||
DeviceStatusDataOperate.addDevices(buildList, dataSource);
|
DeviceStatusDataOperate.addDevices(buildList, LineNetTrainComMethod.getDeviceStatusData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package club.joylink.xiannccda.ats.message.collect.convertor;
|
package club.joylink.xiannccda.ats.message.collect.convertor;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
|
||||||
import club.joylink.xiannccda.ats.message.MessageData;
|
import club.joylink.xiannccda.ats.message.MessageData;
|
||||||
import club.joylink.xiannccda.ats.message.MessageId;
|
import club.joylink.xiannccda.ats.message.MessageId;
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
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.TrainRecordResponse;
|
import club.joylink.xiannccda.ats.message.line3.rep.TrainRecordResponse;
|
||||||
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,12 +17,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
|
public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
|
||||||
|
|
||||||
final DeviceStatusData dataSource;
|
|
||||||
|
|
||||||
public LineNetTrainRecordConvertor(DeviceStatusData dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageId getMessageId() {
|
public MessageId getMessageId() {
|
||||||
return MessageId.TRAIN_RECORD;
|
return MessageId.TRAIN_RECORD;
|
||||||
@ -34,6 +26,7 @@ public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
|
|||||||
public void run(List<MessageData> messageDataList) {
|
public void run(List<MessageData> messageDataList) {
|
||||||
try {
|
try {
|
||||||
List<Builder> buildList = Lists.newArrayList();
|
List<Builder> buildList = Lists.newArrayList();
|
||||||
|
// 已存在的设备信息
|
||||||
for (MessageData data : messageDataList) {
|
for (MessageData data : messageDataList) {
|
||||||
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
|
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
|
||||||
TrainRecordResponse response = (TrainRecordResponse) data;
|
TrainRecordResponse response = (TrainRecordResponse) data;
|
||||||
@ -41,31 +34,17 @@ public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
|
|||||||
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
|
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
|
||||||
offset.setLineId(response.getLineId()); // 线路id
|
offset.setLineId(response.getLineId()); // 线路id
|
||||||
offset.setGroupId(response.getGroupId()); // 车组号
|
offset.setGroupId(response.getGroupId()); // 车组号
|
||||||
|
LineNetTrainComMethod.getDeviceStatusById(offset); // 合并老旧数据
|
||||||
offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向
|
offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向
|
||||||
offset.setShow(false);
|
// 设置公里标信息
|
||||||
// 获取到当前区段公里标
|
LineNetTrainComMethod.setUpKilometerCode(
|
||||||
List<Long> kmCodeList =
|
offset, DeviceType.DEVICE_TYPE_TRACK, response.getTrackName());
|
||||||
LineGraphicDataRepository.getKilometerCodeList(
|
offset.setShow(offset.getKilometerCode() != 0);
|
||||||
response.getLineId(), response.getTrackName());
|
|
||||||
if (CollectionUtils.isNotEmpty(kmCodeList)) {
|
|
||||||
offset.setShow(true); // 如果公里标存在则
|
|
||||||
long kilometer;
|
|
||||||
if (offset.getDir() == 1) { // 下行取大值
|
|
||||||
kilometer = kmCodeList.stream().min(Long::compareTo).get();
|
|
||||||
} else if (offset.getDir() == 2) { // 上行取小值
|
|
||||||
kilometer = kmCodeList.stream().max(Long::compareTo).get();
|
|
||||||
} else { // 无方向获取第一个
|
|
||||||
kilometer = kmCodeList.get(0);
|
|
||||||
}
|
|
||||||
offset.setKilometerCode(kilometer);
|
|
||||||
} else {
|
|
||||||
log.warn(String.format("设备%s没有公里标信息", response.getTrackName()));
|
|
||||||
}
|
|
||||||
buildList.add(offset);
|
buildList.add(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 增加设备信息
|
// 增加设备信息
|
||||||
DeviceStatusDataOperate.addDevices(buildList, dataSource);
|
DeviceStatusDataOperate.addDevices(buildList, LineNetTrainComMethod.getDeviceStatusData());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("信息生成出错", e);
|
log.error("信息生成出错", e);
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class LineNetTrainRemoveConvertor extends DeviceStatusConvertor {
|
public class LineNetTrainRemoveConvertor extends DeviceStatusConvertor {
|
||||||
|
|
||||||
final DeviceStatusData dataSource;
|
|
||||||
|
|
||||||
public LineNetTrainRemoveConvertor(DeviceStatusData dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageId getMessageId() {
|
public MessageId getMessageId() {
|
||||||
return MessageId.TRAIN_INDICATION_REMOVE;
|
return MessageId.TRAIN_INDICATION_REMOVE;
|
||||||
@ -44,20 +38,14 @@ public class LineNetTrainRemoveConvertor extends DeviceStatusConvertor {
|
|||||||
offset.setLineId(response.getLineId());
|
offset.setLineId(response.getLineId());
|
||||||
offset.setGroupId(response.getGroupId());
|
offset.setGroupId(response.getGroupId());
|
||||||
offset.setTrainIndex(response.getTrainIndex());
|
offset.setTrainIndex(response.getTrainIndex());
|
||||||
|
LineNetTrainComMethod.getDeviceStatusById(offset); // 合并老旧数据
|
||||||
|
LineNetTrainComMethod.setUpKilometerCode(
|
||||||
|
offset, response.getDevType(), response.getDevName());
|
||||||
offset.setShow(false);
|
offset.setShow(false);
|
||||||
// 获取到当前区段公里标
|
|
||||||
if (DeviceType.DEVICE_TYPE_TRACK.equals(response.getDevType())) {
|
|
||||||
List<Long> kmCodeList =
|
|
||||||
LineGraphicDataRepository.getKilometerCodeList(
|
|
||||||
response.getLineId(), response.getDevName());
|
|
||||||
if (CollectionUtils.isNotEmpty(kmCodeList)) {
|
|
||||||
offset.setKilometerCode(kmCodeList.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buildList.add(offset);
|
buildList.add(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeviceStatusDataOperate.addDevices(buildList, dataSource);
|
DeviceStatusDataOperate.addDevices(buildList, LineNetTrainComMethod.getDeviceStatusData());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("移除列车信息", e);
|
log.error("移除列车信息", e);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
package club.joylink.xiannccda.ats.message.collect.convertor;
|
package club.joylink.xiannccda.ats.message.collect.convertor;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
|
||||||
import club.joylink.xiannccda.ats.message.MessageData;
|
import club.joylink.xiannccda.ats.message.MessageData;
|
||||||
import club.joylink.xiannccda.ats.message.MessageId;
|
import club.joylink.xiannccda.ats.message.MessageId;
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
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;
|
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse;
|
||||||
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -22,12 +17,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor {
|
public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor {
|
||||||
|
|
||||||
final DeviceStatusData dataSource;
|
|
||||||
|
|
||||||
public LineNetTrainUpdateConvertor(DeviceStatusData dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageId getMessageId() {
|
public MessageId getMessageId() {
|
||||||
return MessageId.TRAIN_INDICATION_UPDATE;
|
return MessageId.TRAIN_INDICATION_UPDATE;
|
||||||
@ -45,20 +34,14 @@ public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor {
|
|||||||
offset.setLineId(response.getLineId()); // 线路id
|
offset.setLineId(response.getLineId()); // 线路id
|
||||||
offset.setTrainIndex(response.getTrainIndex()); // 列车标示号,全线唯一
|
offset.setTrainIndex(response.getTrainIndex()); // 列车标示号,全线唯一
|
||||||
offset.setGroupId(response.getGroupId()); // 车组号
|
offset.setGroupId(response.getGroupId()); // 车组号
|
||||||
// 获取到当前区段公里标
|
LineNetTrainComMethod.getDeviceStatusById(offset); // 合并老旧数据
|
||||||
if (DeviceType.DEVICE_TYPE_TRACK.equals(response.getDevType())) {
|
LineNetTrainComMethod.setUpKilometerCode(
|
||||||
List<Long> kmCodeList =
|
offset, response.getDevType(), response.getDevName());
|
||||||
LineGraphicDataRepository.getKilometerCodeList(
|
offset.setShow(offset.getKilometerCode() != 0);
|
||||||
response.getLineId(), response.getDevName());
|
|
||||||
if (CollectionUtils.isNotEmpty(kmCodeList)) {
|
|
||||||
offset.setShow(true); // 是否显示
|
|
||||||
offset.setKilometerCode(kmCodeList.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buildList.add(offset);
|
buildList.add(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeviceStatusDataOperate.addDevices(buildList, dataSource);
|
DeviceStatusDataOperate.addDevices(buildList, LineNetTrainComMethod.getDeviceStatusData());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("移除列车信息", e);
|
log.error("移除列车信息", e);
|
||||||
}
|
}
|
||||||
|
@ -51,24 +51,17 @@ public class LineDeviceStatusService {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void deviceStatusRefresh() {
|
public void deviceStatusRefresh() {
|
||||||
this.createDataConvertor();
|
this.createDataConvertor();
|
||||||
// 设备状态数据集合
|
|
||||||
DeviceStatusData deviceStatusData = DeviceStatusDataRepository.getDeviceStatusData(DATA_KEY);
|
|
||||||
// 添加初始化转换方法
|
// 添加初始化转换方法
|
||||||
LineNetTrainInitConvertor initConvertor = new LineNetTrainInitConvertor(deviceStatusData);
|
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainInitConvertor());
|
||||||
DeviceStatusConvertorManager.addStatusConvertor(initConvertor);
|
|
||||||
// 列车报点信息转换方法
|
// 列车报点信息转换方法
|
||||||
LineNetTrainRecordConvertor recConvertor = new LineNetTrainRecordConvertor(deviceStatusData);
|
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainRecordConvertor());
|
||||||
DeviceStatusConvertorManager.addStatusConvertor(recConvertor);
|
|
||||||
// 列车更新转换方法
|
// 列车更新转换方法
|
||||||
LineNetTrainUpdateConvertor updateConvertor = new LineNetTrainUpdateConvertor(deviceStatusData);
|
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainUpdateConvertor());
|
||||||
DeviceStatusConvertorManager.addStatusConvertor(updateConvertor);
|
|
||||||
// 列车删除转换方法
|
// 列车删除转换方法
|
||||||
LineNetTrainRemoveConvertor removeConvertor = new LineNetTrainRemoveConvertor(deviceStatusData);
|
DeviceStatusConvertorManager.addStatusConvertor(new LineNetTrainRemoveConvertor());
|
||||||
DeviceStatusConvertorManager.addStatusConvertor(removeConvertor);
|
|
||||||
|
|
||||||
// websocket发送服务
|
// websocket发送服务
|
||||||
IMessageServer iMessageServer = new LineNetMessageServer(deviceStatusData);
|
wsMessageServerManager.registerMessageServer(new LineNetMessageServer());
|
||||||
wsMessageServerManager.registerMessageServer(iMessageServer);
|
|
||||||
wsMessageServerManager.registerMessageServer(new LineTrainMessageServer());
|
wsMessageServerManager.registerMessageServer(new LineTrainMessageServer());
|
||||||
wsMessageServerManager.registerMessageServer(new LineDeviceMessageServer());
|
wsMessageServerManager.registerMessageServer(new LineDeviceMessageServer());
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package club.joylink.xiannccda.ws;
|
package club.joylink.xiannccda.ws;
|
||||||
|
|
||||||
|
|
||||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
||||||
|
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainComMethod;
|
||||||
import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData;
|
import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData;
|
||||||
import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage;
|
import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage;
|
||||||
import com.google.protobuf.Descriptors.FieldDescriptor.Type;
|
import com.google.protobuf.Descriptors.FieldDescriptor.Type;
|
||||||
@ -15,16 +15,14 @@ import java.util.function.Function;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
/**
|
/** 线网图websocket消息服务 */
|
||||||
* 线网图websocket消息服务
|
|
||||||
*/
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LineNetMessageServer implements IMessageServer {
|
public class LineNetMessageServer implements IMessageServer {
|
||||||
|
|
||||||
final DeviceStatusData dataSource;
|
final DeviceStatusData dataSource;
|
||||||
|
|
||||||
public LineNetMessageServer(DeviceStatusData dataSource) {
|
public LineNetMessageServer() {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = LineNetTrainComMethod.getDeviceStatusData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit f86b35768560ddd4e2a3bef70c9b8dfe42510d8f
|
Subproject commit e8ac23070828a1eca3bd68b6f78e4e419123d139
|
Loading…
Reference in New Issue
Block a user