【测试列车报点数据】

This commit is contained in:
weizhihong 2023-06-28 14:30:39 +08:00
parent 6e7a720425
commit 35c9c6bd91
10 changed files with 1816 additions and 1783 deletions

View File

@ -150,22 +150,22 @@ public class LineGraphicDataRepository {
private static void setUpKilometerCode(
Map<String, Map<String, ? extends Builder>> dataMap,
LayoutGraphicsProto.RtssGraphicStorage storage) {
Map<String, ? extends Builder> sectionMap = dataMap.get(DeviceType.Section.name());
if (sectionMap != null) {
return;
}
Map<String, ? extends Builder> sectionMap =
dataMap.getOrDefault(DeviceType.Section.name(), Map.of());
storage
.getAxleCountingsList()
.forEach(
ac -> {
ac.getSectionIdList().stream()
.filter(sid -> sectionMap.containsKey(sid))
.forEach(
sid -> {
DeviceInfoProto.Section.Builder sectionBuilder =
(DeviceInfoProto.Section.Builder) sectionMap.get(sid);
sectionBuilder.addKilometerCode(ac.getKilometerCode());
});
});
ac ->
ac.getAxleCountingRefList().stream()
.filter(
ref ->
DeviceType.Section.equals(ref.getDeviceType())
&& sectionMap.containsKey(ref.getId()))
.forEach(
ref -> {
DeviceInfoProto.Section.Builder sectionBuilder =
(DeviceInfoProto.Section.Builder) sectionMap.get(ref.getId());
sectionBuilder.addKilometerCode(ac.getKilometerCode());
}));
}
}

View File

@ -18,7 +18,13 @@ public abstract class DeviceStatusDataOperate {
/** 设备主键名称映射 */
private static final Map<String, String> DEVICE_ID_NAME_MAP =
Map.of("LineNetTrainOffsetDiagram", "groupId", "TrainInfo", "groupId");
Map.of(
"LineNetTrainOffsetDiagram",
"groupId",
"TrainInfo",
"groupId",
"WsLineNetTrainOffsetMessage",
"groupId");
/**
* 批量放入设备状态

View File

@ -6,7 +6,6 @@ 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.TrainRecordResponse;
import club.joylink.xiannccda.dto.protos.WsMessageProto;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@ -14,7 +13,9 @@ 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 LineNetTrainRecordConvertor extends DeviceStatusConvertor {
final DeviceStatusData dataSource;
@ -30,27 +31,31 @@ public class LineNetTrainRecordConvertor extends DeviceStatusConvertor {
@Override
public void run(List<MessageData> messageDataList) {
List<Builder> buildList = Lists.newArrayList();
for (MessageData data : messageDataList) {
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
TrainRecordResponse response = (TrainRecordResponse) data;
WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset =
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
offset.setLineId(response.getLineId()); // 线路id
offset.setGroupId(response.getGroupId()); // 车组号
offset.setDestinationId(response.getDestinationId()); // 目的地ID
offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向
// 获取到当前区段公里标
List<String> kmCodeList =
LineGraphicDataRepository.getSectionDefaultKmCodeList(
response.getLineId(), response.getTrackName());
if (CollectionUtils.isNotEmpty(kmCodeList)) {
offset.setKilometerCode(kmCodeList.get(0));
try {
List<Builder> buildList = Lists.newArrayList();
for (MessageData data : messageDataList) {
if (Objects.equals(getMessageId(), data.getMsgId())) { // 消息类型一致
TrainRecordResponse response = (TrainRecordResponse) data;
WsMessageProto.WsLineNetTrainOffsetMessage.Builder offset =
WsMessageProto.WsLineNetTrainOffsetMessage.newBuilder();
offset.setLineId(response.getLineId()); // 线路id
offset.setGroupId(response.getGroupId()); // 车组号
offset.setDestinationId(response.getDestinationId()); // 目的地ID
offset.setDir(response.getDirection().getValue()); // 初始设置无运行方向
// 获取到当前区段公里标
List<String> kmCodeList =
LineGraphicDataRepository.getSectionDefaultKmCodeList(
response.getLineId(), response.getTrackName());
if (CollectionUtils.isNotEmpty(kmCodeList)) {
offset.setKilometerCode(kmCodeList.get(0));
}
buildList.add(offset);
}
buildList.add(offset);
}
// 增加设备信息
DeviceStatusDataOperate.addDevices(buildList, dataSource);
} catch (Exception e) {
log.error("信息生成出错", e);
}
// 增加设备信息
DeviceStatusDataOperate.addDevices(buildList, dataSource);
}
}

View File

@ -13,10 +13,6 @@ import lombok.Setter;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author walker-sheng
* @since 2023-06-13
*/
@ -38,6 +34,8 @@ public class NccMockData {
private String actionType;
private String msgId;
public static final String ID = "id";
public static final String MOCK_DATA = "mock_data";
@ -47,12 +45,16 @@ public class NccMockData {
public static final String MSG_TYPE = "msg_type";
public static final String ACTION_TYPE = "action_type";
public static final String MSG_ID = "msg_id";
public enum MsgTypeEnum {
REAL_TIME, UNREAL_TIME
REAL_TIME,
UNREAL_TIME
}
public enum ActionTypeEnum {
ALL, UPDATES
ALL,
UPDATES
}
@TableField(exist = false)

View File

@ -10,12 +10,15 @@ import club.joylink.xiannccda.mock.message.NccMockData.MsgTypeEnum;
import club.joylink.xiannccda.repository.impl.NccMockDataRepository;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -59,13 +62,43 @@ public class NccMockDataService {
}
public List<MessageData> loadALLData() {
List<NccMockData> nccMockData = this.nccMockDataRepository.list(Wrappers.<NccMockData>lambdaQuery()
.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name()));
List<NccMockData> nccMockData =
this.nccMockDataRepository.list(
Wrappers.<NccMockData>lambdaQuery()
.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name()));
List<MessageData> list = this.parse(nccMockData);
return list;
}
public List<MessageData> loadAllTrainInitData() {
// 请求全部信息
LambdaQueryWrapper<NccMockData> allQuery = Wrappers.lambdaQuery();
allQuery
.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name())
.eq(NccMockData::getMsgId, MessageId.TRAIN_INDICATION_INIT.name());
List<NccMockData> allMockData = this.nccMockDataRepository.list(allQuery);
return this.parse(allMockData);
}
public List<MessageData> loadUpdateData(AtomicLong id, String msgName, int count) {
// 请求全部信息
LambdaQueryWrapper<NccMockData> query = Wrappers.lambdaQuery();
query
.eq(NccMockData::getActionType, ActionTypeEnum.UPDATES.name())
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name())
.eq(NccMockData::getMsgId, msgName)
.gt(NccMockData::getId, id == null ? 0 : id.get())
.last(String.format(" limit %s", count))
.orderByAsc(NccMockData::getId);
List<NccMockData> updateMockData = this.nccMockDataRepository.list(query);
if (id != null && !CollectionUtils.isEmpty(updateMockData)) {
id.set(updateMockData.get(updateMockData.size() - 1).getId());
}
return this.parse(updateMockData);
}
public List<MessageData> getMessageData() {
if (this.isLast()) {
return Collections.emptyList();

View File

@ -1,14 +1,21 @@
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.DeviceStatusDataRepository;
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainInitConvertor;
import club.joylink.xiannccda.ats.message.collect.convertor.LineNetTrainRecordConvertor;
import club.joylink.xiannccda.mock.message.NccMockDataService;
import club.joylink.xiannccda.ws.IMessageServer;
import club.joylink.xiannccda.ws.LineNetMessageServer;
import club.joylink.xiannccda.ws.WsMessageServerManager;
import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -21,8 +28,12 @@ public class LineDeviceStatusService {
private final WsMessageServerManager wsMessageServerManager;
public LineDeviceStatusService(WsMessageServerManager wsMessageServerManager) {
private final NccMockDataService nccMockDataService;
public LineDeviceStatusService(
WsMessageServerManager wsMessageServerManager, NccMockDataService nccMockDataService) {
this.wsMessageServerManager = wsMessageServerManager;
this.nccMockDataService = nccMockDataService;
}
@PostConstruct
@ -38,5 +49,25 @@ public class LineDeviceStatusService {
// websocket发送服务
IMessageServer iMessageServer = new LineNetMessageServer(deviceStatusData);
wsMessageServerManager.registerMessageServer(iMessageServer);
// 加载数据
refreshTestData();
}
public void refreshTestData() {
List<MessageData> allMockData = nccMockDataService.loadAllTrainInitData();
DeviceStatusConvertorManager.doConvertor(allMockData);
AtomicLong id = new AtomicLong(0);
Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay(
() -> {
int count = (int) (Math.random() * 12);
List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count);
DeviceStatusConvertorManager.doConvertor(updateMockData);
},
1500,
1500,
TimeUnit.MILLISECONDS);
}
}

@ -1 +1 @@
Subproject commit 39c150153d2bfa730d4ef6843f7bf87e5002b530
Subproject commit 6c684988299ebe2019da7687dd5b3104ef770a79