Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a7da2e5202
@ -20,9 +20,9 @@ public class DeviceStatusConvertorManager {
|
||||
* @param msgId 消息ID
|
||||
* @param convertor 转换对象
|
||||
*/
|
||||
public static void addStatusConvertor(MessageId msgId, DeviceStatusConvertor convertor) {
|
||||
public static void addStatusConvertor(DeviceStatusConvertor convertor) {
|
||||
Map<String, DeviceStatusConvertor> convertorMap =
|
||||
CONVERTOR_MAP.computeIfAbsent(msgId, k -> new ConcurrentHashMap<>());
|
||||
CONVERTOR_MAP.computeIfAbsent(convertor.getMessageId(), k -> new ConcurrentHashMap<>());
|
||||
convertorMap.put(convertor.getClass().getSimpleName(), convertor);
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
|
||||
offset.setGroupId(response.getGroupId()); // 车组号
|
||||
offset.setDestinationId(response.getDestinationId()); // 目的地ID
|
||||
offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向
|
||||
offset.setShow(true); // 显示
|
||||
// 获取到当前区段公里标
|
||||
List<String> kmCodeList =
|
||||
LineGraphicDataRepository.getSectionDefaultKmCodeList(
|
||||
|
@ -0,0 +1,64 @@
|
||||
package club.joylink.xiannccda.ats.message.collect.convertor;
|
||||
|
||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
||||
import club.joylink.xiannccda.ats.message.MessageData;
|
||||
import club.joylink.xiannccda.ats.message.MessageId;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusData;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationRemoveResponse;
|
||||
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** 列车信息移除时,线网信息处理 */
|
||||
@Slf4j
|
||||
public class LineNetTrainRemoveConvertor extends DeviceStatusConvertor {
|
||||
|
||||
final DeviceStatusData dataSource;
|
||||
|
||||
public LineNetTrainRemoveConvertor(DeviceStatusData dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageId getMessageId() {
|
||||
return MessageId.TRAIN_INDICATION_REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(List<MessageData> messageDataList) {
|
||||
try {
|
||||
List<Builder> buildList = Lists.newArrayList();
|
||||
for (MessageData data : messageDataList) {
|
||||
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
|
||||
TrainIndicationRemoveResponse response = (TrainIndicationRemoveResponse) data;
|
||||
WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset =
|
||||
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
|
||||
offset.setLineId(response.getLineId());
|
||||
offset.setGroupId(response.getGroupId());
|
||||
offset.setTrainIndex(response.getTrainIndex());
|
||||
offset.setShow(false);
|
||||
// 获取到当前区段公里标
|
||||
if (DeviceType.DEVICE_TYPE_TRACK.equals(response.getDevType())) {
|
||||
List<String> kmCodeList =
|
||||
LineGraphicDataRepository.getSectionDefaultKmCodeList(
|
||||
response.getLineId(), response.getDevName());
|
||||
if (CollectionUtils.isNotEmpty(kmCodeList)) {
|
||||
offset.setKilometerCode(kmCodeList.get(0));
|
||||
}
|
||||
}
|
||||
buildList.add(offset);
|
||||
}
|
||||
}
|
||||
DeviceStatusDataOperate.addDevices(buildList, dataSource);
|
||||
} catch (Exception e) {
|
||||
log.error("移除列车信息", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package club.joylink.xiannccda.ats.message.collect.convertor;
|
||||
|
||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
||||
import club.joylink.xiannccda.ats.message.MessageData;
|
||||
import club.joylink.xiannccda.ats.message.MessageId;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusData;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationRemoveResponse;
|
||||
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse;
|
||||
import club.joylink.xiannccda.dto.protos.WsMessageProto;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** 列车信息更新时,信息转换 */
|
||||
@Slf4j
|
||||
public class LineNetTrainUpdateConvertor extends DeviceStatusConvertor {
|
||||
|
||||
final DeviceStatusData dataSource;
|
||||
|
||||
public LineNetTrainUpdateConvertor(DeviceStatusData dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageId getMessageId() {
|
||||
return MessageId.TRAIN_INDICATION_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(List<MessageData> messageDataList) {
|
||||
try {
|
||||
List<Builder> buildList = Lists.newArrayList();
|
||||
for (MessageData data : messageDataList) {
|
||||
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
|
||||
TrainIndicationUpdateResponse response = (TrainIndicationUpdateResponse) data;
|
||||
WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset =
|
||||
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
|
||||
offset.setLineId(response.getLineId()); // 线路id
|
||||
offset.setTrainIndex(response.getTrainIndex()); // 列车标示号,全线唯一
|
||||
offset.setGroupId(response.getGroupId()); // 车组号
|
||||
offset.setDestinationId(response.getDestinationId()); // 目的地ID
|
||||
offset.setShow(true); // 是否显示
|
||||
offset.setDir(0); // 初始设置无运行方向
|
||||
// 获取到当前区段公里标
|
||||
if (DeviceType.DEVICE_TYPE_TRACK.equals(response.getDevType())) {
|
||||
List<String> kmCodeList =
|
||||
LineGraphicDataRepository.getSectionDefaultKmCodeList(
|
||||
response.getLineId(), response.getDevName());
|
||||
if (CollectionUtils.isNotEmpty(kmCodeList)) {
|
||||
offset.setKilometerCode(kmCodeList.get(0));
|
||||
}
|
||||
}
|
||||
buildList.add(offset);
|
||||
}
|
||||
}
|
||||
DeviceStatusDataOperate.addDevices(buildList, dataSource);
|
||||
} catch (Exception e) {
|
||||
log.error("移除列车信息", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ import club.joylink.xiannccda.ats.message.collect.DeviceStatusData;
|
||||
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository;
|
||||
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainInitConvertor;
|
||||
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRecordConvertor;
|
||||
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRemoveConvertor;
|
||||
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainUpdateConvertor;
|
||||
import club.joylink.xiannccda.mock.message.NccMockDataService;
|
||||
import club.joylink.xiannccda.ws.IMessageServer;
|
||||
import club.joylink.xiannccda.ws.LineDeviceMessageServer;
|
||||
@ -44,10 +46,16 @@ public class LineDeviceStatusService {
|
||||
DeviceStatusData deviceStatusData = DeviceStatusDataRepository.getDeviceStatusData(DATA_KEY);
|
||||
// 添加初始化转换方法
|
||||
LineNetTrainInitConvertor initConvertor = new LineNetTrainInitConvertor(deviceStatusData);
|
||||
DeviceStatusConvertorManager.addStatusConvertor(initConvertor.getMessageId(), initConvertor);
|
||||
DeviceStatusConvertorManager.addStatusConvertor(initConvertor);
|
||||
// 列车报点信息转换方法
|
||||
LineNetTrainRecordConvertor recConvertor = new LineNetTrainRecordConvertor(deviceStatusData);
|
||||
DeviceStatusConvertorManager.addStatusConvertor(recConvertor.getMessageId(), recConvertor);
|
||||
DeviceStatusConvertorManager.addStatusConvertor(recConvertor);
|
||||
// 列车更新转换方法
|
||||
LineNetTrainUpdateConvertor updateConvertor = new LineNetTrainUpdateConvertor(deviceStatusData);
|
||||
DeviceStatusConvertorManager.addStatusConvertor(updateConvertor);
|
||||
// 列车删除转换方法
|
||||
LineNetTrainRemoveConvertor removeConvertor = new LineNetTrainRemoveConvertor(deviceStatusData);
|
||||
DeviceStatusConvertorManager.addStatusConvertor(removeConvertor);
|
||||
// websocket发送服务
|
||||
IMessageServer iMessageServer = new LineNetMessageServer(deviceStatusData);
|
||||
wsMessageServerManager.registerMessageServer(iMessageServer);
|
||||
|
Loading…
Reference in New Issue
Block a user