调整
All checks were successful
local-test分支构建docker并发布运行 / Docker-Build (push) Successful in 1m54s

This commit is contained in:
tiger_zhou 2024-11-26 18:17:41 +08:00
parent 953294ea31
commit 4408103aaa
74 changed files with 2633 additions and 744 deletions

View File

@ -133,7 +133,7 @@ public class NccAlertInfo implements AlertInfo, Cloneable {
case BLUE_DISPLAY, PLATFORM_DOOR_CANNOT_CLOSE, PLATFORM_DOOR_CANNOT_OPEN,
PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, TRAIN_DELAY_10, SWITCH_LOST, SWITCH_FW_LOST, SWITCH_All_LOST, SWITCH_DW_LOST,
SWITCH_LOST_MOST, SWITCH_LOST_INTERLOCK_AREA, AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, TRAIN_EB_ATP,
ALL_LINE_BLUE_DISPLAY, AXLE_LED_RED_INTERLOCK_AREA, AXLE_LED_ORANGE_INTERLOCK_AREA, SWITCH_JAMMED -> {
ALL_LINE_BLUE_DISPLAY, AXLE_LED_RED_INTERLOCK_AREA, AXLE_LED_ORANGE_INTERLOCK_AREA, SWITCH_JAMMED, PLATFORM_WAIT_TRAIN_MAX_RECORD, HOLD_PLATFORM_STAY_TRAIN_MORE -> {
return "I";
}
case PLATFORM_EMERG_STOP -> {

View File

@ -24,7 +24,10 @@ public enum AlertDeviceType {
/**
* 列车设备
*/
DEVICE_TYPE_TRAIN
DEVICE_TYPE_TRAIN,
/**
* 站台扣车对应的区段
*/
LOGIC_DEVICE_TRACK_AREA_FOR_PLATFORM_HOLDER;
}

View File

@ -22,6 +22,7 @@ import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RelatedRef.DeviceTy
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RtssGraphicStorage;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.entity.PublishedGi;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@ -33,11 +34,14 @@ import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageOrBuilder;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import lombok.Getter;
@ -83,7 +87,9 @@ public class LineGraphicDataRepository {
private static final Table<Integer, String, String> TURNOUT_TO_TURNOUT_TRACK = HashBasedTable.create();
private static final Table<Integer, String, String> LOGIC_SECTION_TO_AXLE_TABLE = HashBasedTable.create();
private static final Table<Integer, String, String> turnout_to_switch = HashBasedTable.create();
public static final Map<Integer, List<Integer>> STATION_SORTS = new HashMap<>();
/**
* 缓存线路数据信息
@ -92,6 +98,7 @@ public class LineGraphicDataRepository {
*/
public static void putLineGraph(PublishedGi publishGi) {
try {
if (publishGi.getLineId() != null) {
LayoutGraphicsProto.RtssGraphicStorage storage =
LayoutGraphicsProto.RtssGraphicStorage.parseFrom(publishGi.getProto());
@ -113,18 +120,15 @@ public class LineGraphicDataRepository {
// 填充line_code_table
fillLineCodeTable(publishGi.getLineId(), storage);
Map<String, Map<Integer, Builder>> tmpMaper = lineGraphMap.get(publishGi.getLineId());
if (CollectionUtils.isEmpty(tmpMaper)) {
return;
}
Map<Integer, Builder> turnoutMap = tmpMaper.get(DeviceType.Turnout.name());
Map<Integer, Builder> builderMap = tmpMaper.get(DeviceType.Section.name());
for (Section section : storage.getSectionList()) {
if (section.getSectionType() == SectionType.TurnoutPhysical) {
for (Integer childId : section.getChildrenList()) {
Builder b = turnoutMap.get(childId);
if (b instanceof DeviceInfoProto.Turnout.Builder logicSection) {
@ -142,13 +146,22 @@ public class LineGraphicDataRepository {
}
}
}
STATION_SORTS.computeIfAbsent(publishGi.getLineId(), lineId -> {
List<Station> allStation = LineGraphicDataRepository.getDevices(publishGi.getLineId(), LayoutGraphicsProto.Station.class)
.filter(d -> com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(d.getCode())).toList();
List<Integer> stationCodeList = allStation.stream().map(d -> Integer.valueOf(d.getCode())).distinct().sorted().toList();
return stationCodeList;
});
}
} catch (InvalidProtocolBufferException e) {
log.error("反序列化信息失败", e);
}
}
public static void initDeviceStationCenter(Integer lineId) {
log.info("开始初始化地图中设备集中站的归属。。。");
@ -194,6 +207,9 @@ public class LineGraphicDataRepository {
}
}
public static List<Integer> allStation(Integer lineId) {
return STATION_SORTS.get(lineId);
}
private static List<GeneratedMessageV3.Builder> createMsg(Integer lineId, club.joylink.xiannccda.ats.message.line3.device.DeviceType dt, String devName, short rtuId) {
DeviceStatusChangeResponse statusChange = new DeviceStatusChangeResponse();
@ -238,6 +254,12 @@ public class LineGraphicDataRepository {
}
public static Collection<Integer> getAllLines() {
return lineGraphMap.keySet();
}
/**
* 获取线路上区段名为sectionName的公里标
*
@ -276,21 +298,42 @@ public class LineGraphicDataRepository {
public static MessageOrBuilder getDeviceByCodeNotException(int lineId, String code) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
return mob;
}
public static MessageOrBuilder getDeviceByCode2(int lineId, String code, String t) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(mob,
String.format("线路[%s]code[%s] deviceid[%s]", lineId, code, t));
return mob;
}
public static MessageOrBuilder getDeviceByCode(int lineId, String code) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(mob,
String.format("线路[%s]code[%s]", lineId, code));
return mob;
}
/**
* 根据道岔code 查找对应的道岔区段
*
* @param lineId
* @param code
* @return
*/
public static String findTurnoutSectionFromTurnoutCode(int lineId, String code) {
return TURNOUT_TO_TURNOUT_TRACK.get(lineId, code);
}
public static <T> T getDeviceByCodeNotException(int lineId, String code, Class<T> cls) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
return (T) mob;
}
public static <T> Optional<T> getDeviceOptByCode(int lineId, String code, Class<T> cls) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
if (Objects.isNull(mob)) {

View File

@ -23,7 +23,7 @@ public class FrameSchema {
* (Multi-flag)为帧标识位占1字节值为0或者1分别表示下面的意思 1表示在这帧数据中一个完整的消息没有发送结束有后续帧 0表示在这帧数据中消息完整发送没有后续帧同样几个消息可合并成一帧数据发送
*/
short multiFlag;
static final short Flag_Multi = 1;
public static final short Flag_Multi = 1;
/**
* 消息内容最长为1024字节它可由一个或多个消息组成也可以是一个消息的一部分每个消息由消息标识和消息数据组成
*/

View File

@ -27,7 +27,7 @@ public class OccMessageDecoder extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
connection.lastReceiveMessageTime = System.currentTimeMillis();
connection.receiveMessageLatest = System.currentTimeMillis();
// connection.receiveMessageLatest = System.currentTimeMillis();
Long id = IdUtil.getSnowflake().nextId();
DecodeResult dr = FrameSchemaParse.decode(in, this.connection.port);
if (Objects.nonNull(dr) && CollectionUtils.isNotEmpty(dr.getData())) {

View File

@ -61,10 +61,10 @@ public class OccMessageHandler extends SimpleChannelInboundHandler<List<DecodeMe
@Override
protected void channelRead0(ChannelHandlerContext ctx, List<DecodeMessageData> msg) throws Exception {
DecodeMessageData messageData = msg.get(0);
if (messageData.getMessages().stream().anyMatch(d -> d.getMsgId() == MessageId.MESSAGE_POLLING)) {
/* if (messageData.getMessages().stream().anyMatch(d -> d.getMsgId() == MessageId.MESSAGE_POLLING)) {
MessageData md = MessageId.MESSAGE_POLLING.create();
this.connection.write(md);
}
}*/
if (this.collectorData) {
MockAppContext.publishCollectorAtsData(messageData);

View File

@ -48,7 +48,12 @@ public class OccTcpClientConnection {
/**
* 最后一次接受到消息的时间
*/
long receiveMessageLatest;
// long receiveMessageLatest;
/**
* 最近一次连接occ 服务时间
*/
long connectionOccTimeLatest;
final ReconnectState reconnectState;
@ -112,7 +117,8 @@ public class OccTcpClientConnection {
this.lastReceiveMessageTime = System.currentTimeMillis();
this.channel = channelFuture.channel();
this.connected = true;
// this.client.requestBaseData();
this.client.requestBaseData();
this.connectionOccTimeLatest = System.currentTimeMillis();
SystemContext.publishEvent(new SystemWarnConnStateEvent(this.client.getLineId(), this));
}
});

View File

@ -2,7 +2,10 @@ package club.joylink.xiannccda.ats.message;
import club.joylink.xiannccda.ats.message.line3.req.LoadDeviceStatusRequest;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
import club.joylink.xiannccda.configuration.protos.OccServerProto.OccClientMessage;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.Objects;
import java.util.concurrent.Executors;
@ -41,7 +44,8 @@ public class XianOccMessagingClient {
private final Long requestBaseTime;
private final ConnectionTimeOutHandler timeOutHandler = new ConnectionTimeOutHandler();
private final ConnectionTimeOutHandler timeOutHandler;
public void send(MessageData md, boolean isRealTime) {
OccTcpClientConnection conn = isRealTime ? rtConnection : nrtConnection;
@ -54,17 +58,6 @@ public class XianOccMessagingClient {
}
/* public XianOccMessagingClient(int lineId, Integer realPort, Integer unRealPort, String host, boolean collectorData, Integer receiveMsgTimeout) {
this.host = host;
this.lineId = lineId;
this.requestBaseTime = TimeUnit.HOURS.toMillis(receiveMsgTimeout);
// 创建实时和非实时消息连接
this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData, true);
this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false, false);
this.timeOutHandler.addConnection(this.rtConnection);
this.timeOutHandler.addConnection(this.nrtConnection);
}*/
public XianOccMessagingClient(Integer lineId, OccClientMessage clientMessage) {
this.host = clientMessage.getServerHost();
this.lineId = lineId;
@ -72,6 +65,8 @@ public class XianOccMessagingClient {
// 创建实时和非实时消息连接
this.rtConnection = new OccTcpClientConnection(this, host, clientMessage.getRealPort(), clientMessage.getCollectorData(), true, clientMessage.getNameChanger());
this.nrtConnection = new OccTcpClientConnection(this, host, clientMessage.getUnRealPort(), false, false, clientMessage.getNameChanger());
this.timeOutHandler = new ConnectionTimeOutHandler(this.requestBaseTime);
this.timeOutHandler.addConnection(this.rtConnection);
this.timeOutHandler.addConnection(this.nrtConnection);
@ -83,7 +78,7 @@ public class XianOccMessagingClient {
*/
public void resetRequestBaseDataFlag() {
//实时数据客户端断开并且最新的获取时间 + 2小时小于当前时间
if (Objects.equals(false, this.rtConnection.connected) && (this.rtConnection.receiveMessageLatest + this.requestBaseTime) < System.currentTimeMillis()) {
if (Objects.equals(false, this.rtConnection.connected) /*&& (this.rtConnection.receiveMessageLatest + this.requestBaseTime) < System.currentTimeMillis()*/) {
this.requestBaseDataFlag.set(false);
}
}
@ -92,7 +87,8 @@ public class XianOccMessagingClient {
public void requestBaseData() {
if (this.rtConnection.connected && this.nrtConnection.connected && this.requestBaseDataFlag.compareAndSet(false, true)) {
log.info("发送计划运行图请求 lineId[{}] host[{}] 实时接口[{}]", this.lineId, this.host, false);
// LoadHistoryTGDataRequest dataRequest = new LoadHistoryTGDataRequest((short) this.lineId, LocalDateTime.now(), ApplyTypeEnum.PLAN_GRAPH);
// LoadHistoryTGDataRequest planData = new LoadHistoryTGDataRequest((short) this.lineId, LocalDateTime.now(), ApplyTypeEnum.PLAN_GRAPH);
// this.send(planData, false);
LoadDeviceStatusRequest dataRequest = new LoadDeviceStatusRequest((short) this.lineId);
this.send(dataRequest, true);
}
@ -145,7 +141,11 @@ public class XianOccMessagingClient {
Executor.shutdownNow();
}
public ConnectionTimeOutHandler() {
//重新请求基础数据间隔
private Long requestBaseTime;
public ConnectionTimeOutHandler(Long requestBaseTime) {
this.requestBaseTime = requestBaseTime;
this.systemInfo = new SystemInfo();
if (Executor.isShutdown()) {
Executor = Executors.newSingleThreadScheduledExecutor();
@ -185,9 +185,13 @@ public class XianOccMessagingClient {
for (OccTcpClientConnection cc : this.clientConnections) {
if (cc.connected) {
long ctm = System.currentTimeMillis();
if (cc.lastReceiveMessageTime + HeartBeatTimeout < ctm) {
/*if (cc.lastReceiveMessageTime + HeartBeatTimeout < ctm) {
log.info("超时未收到OCC消息尝试断开重连 port :{} 最后一次获取数据时间:{}", cc.port, cc.lastReceiveMessageTime);
cc.reconnect();
}*/
if (cc.isRealPort && (cc.connectionOccTimeLatest + requestBaseTime) < ctm) {
}
} else {
cc.reconnect();

View File

@ -1,25 +0,0 @@
package club.joylink.xiannccda.ats.message.changer.line4;
public class Line4NameUtil {
public static String convertLine4Name(String line4Name) {
try {
StringBuilder sb = new StringBuilder();
byte[] bb = line4Name.getBytes("ISO-8859-1");
for (int i = 0; i < bb.length; i++) {
byte b = bb[i];
if (i + 1 < bb.length) {
if (b == 0 && bb[i + 1] == 63) {
break;
}
}
sb.append((char) b);
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return line4Name;
}
}
}

View File

@ -1,30 +0,0 @@
package club.joylink.xiannccda.ats.message.changer.line4;
import club.joylink.xiannccda.ats.message.changer.NameChanger;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.changer.NameChangerFilter;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
public class SignalChanger {
/**
* X10301 /XR
*/
@NameChanger(value = {NameChangerEnum.LINE_4})
public static class Signal1Changer implements NameChangerFilter {
@Override
public DeviceType deviceType() {
return DeviceType.DEVICE_TYPE_SIGNAL;
}
@Override
public String changeDeviceName(String sourceName) {
return Line4NameUtil.convertLine4Name(sourceName);
}
}
}

View File

@ -1,35 +0,0 @@
package club.joylink.xiannccda.ats.message.changer.line4;
import club.joylink.xiannccda.ats.message.changer.NameChanger;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.changer.NameChangerFilter;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* P09301
*/
public class SwitchChanger {
/**
* 道岔物理区段转换
*/
@NameChanger(value = {NameChangerEnum.LINE_4})
public static class SwitchDGChanger implements NameChangerFilter {
@Override
public DeviceType deviceType() {
return DeviceType.DEVICE_TYPE_SWITCH;
}
@Override
public String changeDeviceName(String sourceName) {
return Line4NameUtil.convertLine4Name(sourceName);
}
}
}

View File

@ -4,8 +4,10 @@ import club.joylink.xiannccda.ats.message.changer.NameChanger;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.changer.NameChangerFilter;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import cn.hutool.core.util.ReUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
public class TrackChanger {
@ -23,7 +25,14 @@ public class TrackChanger {
@Override
public String changeDeviceName(String sourceName) {
return Line4NameUtil.convertLine4Name(sourceName);
if (StringUtils.startsWith(sourceName, "DG")) {
int flag = StringUtils.indexOf(sourceName, "-");
if (flag > 0) {
return sourceName.substring(0, flag);
}
return sourceName;
}
return sourceName;
}
}

View File

@ -14,6 +14,7 @@ import java.util.stream.Collectors;
*/
public class DeviceStatusConvertorManager {
/**
* 消息类型与转换列表
*/

View File

@ -77,7 +77,7 @@ public abstract class DeviceStatusDataOperate {
}));
// 对比结果
Map<String, Message> compareMap = compare(deviceStatusMap, newDeviceMap);
if (!CollectionUtils.isEmpty(compareMap) && (!(data instanceof DeviceStatusData))) {
if (!CollectionUtils.isEmpty(compareMap)/* && ((data instanceof DeviceStatusData))*/) {
statusVOMap.put(k, compareMap);
}
});

View File

@ -1,5 +1,6 @@
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.MessageResponse;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
@ -22,6 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.Collection;
import org.apache.commons.lang3.StringUtils;
public abstract class DefaultConvertor extends DeviceStatusConvertor {
@ -46,6 +48,27 @@ public abstract class DefaultConvertor extends DeviceStatusConvertor {
return responseList.stream().collect(Collectors.groupingBy(MessageResponse::getLineId));
}
private void tmpChangeLine4Name(Integer lineId, GeneratedMessageV3.Builder msg) {
if (lineId == 4 && msg instanceof TrainInfo.Builder ti) {
String deviceName = ti.getDevName();
if (StringUtils.startsWith(deviceName, "P")) {
String occName = LineGraphicDataRepository.findTurnoutSectionFromTurnoutCode(lineId, deviceName);
if (StringUtils.isNotEmpty(occName)) {
ti.setDevName(occName);
}
} else if (StringUtils.startsWith(deviceName, "DG")) {
int flag = StringUtils.indexOf(deviceName, "-");
if (flag > 0) {
String newName = deviceName.substring(0, flag);
ti.setDevName(newName);
}
}
} else if (lineId == 4 && msg instanceof TrainRemove.Builder re) {
System.out.println(re.getDevName());
}
}
@Override
public void run(NameChangerEnum nameChanger, List<MessageData> messageDataList) {
Map<Short, List<MessageResponse>> lineMapper = this.groupByLineId(messageDataList);
@ -54,7 +77,8 @@ public abstract class DefaultConvertor extends DeviceStatusConvertor {
.flatMap(Collection::stream).filter(d -> {
Integer lineId = DeviceStatusDataOperate.findFieldVal(d, "lineId", Integer.class);
Integer rtuId = DeviceStatusDataOperate.findFieldVal(d, "rtuId", Integer.class);
if (d instanceof TrainInfo.Builder || d instanceof TrainRemove.Builder) {
if (d instanceof TrainInfo.Builder ti || d instanceof TrainRemove.Builder) {
tmpChangeLine4Name(lineId, d);
return true;
}
return SystemContext.notMatchRtu(lineId, rtuId);

View File

@ -7,7 +7,10 @@ import club.joylink.xiannccda.constants.SystemContext;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.CommonInfo;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.service.config.DeviceAreaConfigService;
import club.joylink.xiannccda.vo.AreaConfigVO;
@ -31,8 +34,10 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@Slf4j
public class InterLockData extends AbstractData {
/**
@ -92,11 +97,19 @@ public class InterLockData extends AbstractData {
Integer max = Integer.parseInt(sortStationList.get(sortStationList.size() - 1).getCode());
if (rtuId >= min && rtuId <= max) {
if (builder instanceof Track.Builder track) {
String axleCode = LineGraphicDataRepository.findAxleCodeFromLogicCode(lineId, track.getId());
MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, track.getId());
if (section instanceof LayoutGraphicsProto.Section ss) {
if (ss.getSectionType() == SectionType.TurnoutPhysical) {
this.put(section, alertType, AlertDeviceType.DEVICE_TYPE_TRACK, interlockArea, min, max, rtuId);
}
} else {
if (section instanceof LayoutGraphicsProto.LogicSection) {
String axleCode = LineGraphicDataRepository.findAxleCodeFromLogicCode(lineId, track.getId());
MessageOrBuilder sec = LineGraphicDataRepository.getDeviceByCode2(lineId, axleCode, track.getId());
this.put(sec, alertType, AlertDeviceType.DEVICE_TYPE_TRACK, interlockArea, min, max, rtuId);
}
}
// MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, track.getId());
MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, axleCode);
this.put(section, alertType, AlertDeviceType.DEVICE_TYPE_TRACK, interlockArea, min, max, rtuId);
} else if (builder instanceof Switch.Builder switchs) {
// MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, switchs.getId());
// this.put(section, alertType, AlertDeviceType.DEVICE_TYPE_SWITCH, interlockArea, min, max, rtuId);
@ -151,7 +164,11 @@ public class InterLockData extends AbstractData {
@Override
public void addDevice(List<Builder> dataList) {
for (Builder builder : dataList) {
this.insert(builder);
try {
this.insert(builder);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}

View File

@ -76,6 +76,7 @@ public class TrainDataSource extends AbstractData {
if (Objects.nonNull(dbTime) && Objects.nonNull(collTime)) {
if (collTime >= dbTime) {
DeviceStatusDataOperate.merge(trainBuild, message);
// this.putTrainDeviceMapper(trainBuild);
}
}
@ -84,6 +85,10 @@ public class TrainDataSource extends AbstractData {
trainInfo.clearBlock();
trainInfo.clearRemove();
trainInfo.clearRecord();
if (builder instanceof TrainInfo.Builder oldTrain) {
trainInfo.setHasNextStation(oldTrain.getHasNextStation());
trainInfo.setTrainDelay(oldTrain.getTrainDelay());
}
allTrainInfoMaper.put(idVal.toString(), trainInfo);
if (SystemContext.notMatchRtu(trainInfo.getLineId(), trainInfo.getRtuId())) {
this.putTrainDeviceMapper(trainInfo);

View File

@ -57,7 +57,7 @@ public class ActionReportResponse extends MessageResponse {
this.totalMessage = buf.readShort();
this.messageSequence = buf.readShort();
this.count = buf.readShort();
this.entityList = EntityParseUtil.collect(this.count, buf, ActionReportEntity.class);
this.entityList = EntityParseUtil.collect(this.lineId, this.count, buf, ActionReportEntity.class);
}
@ -117,7 +117,7 @@ public class ActionReportResponse extends MessageResponse {
private String actionContent;
@Override
public ActionReportEntity read(ByteBuf buf) {
public ActionReportEntity read(Integer lineId, ByteBuf buf) {
ActionReportEntity entity = new ActionReportEntity();
entity.actionSite = ActionReportSiteEnum.of(buf.readByte());

View File

@ -55,7 +55,7 @@ public class AlarmReportResponse extends MessageResponse {
this.totalMessage = buf.readShort();
this.messageSequence = buf.readShort();
this.count = buf.readShort();
this.entityList = EntityParseUtil.collect(this.count, buf, AlarmReportEntity.class);
this.entityList = EntityParseUtil.collect(this.lineId, this.count, buf, AlarmReportEntity.class);
}
@ -128,18 +128,18 @@ public class AlarmReportResponse extends MessageResponse {
@Override
public AlarmReportEntity read(ByteBuf buf) {
public AlarmReportEntity read(Integer lineId, ByteBuf buf) {
AlarmReportEntity entity = new AlarmReportEntity();
entity.alamrSite = AlarmReportSiteEnum.of(buf.readByte());
entity.alarmSiteid = buf.readShort();
entity.alarmNname = EntityParseUtil.convertStr(buf, 20);
entity.alarmNname = EntityParseUtil.convertStr(lineId, buf, 20);
entity.alarmTime = DateTimeUtil.convert(buf);
entity.alarmType = AlarmTypeControlEnum.of(buf.readShort());
entity.alarmSubType = buf.readShort();
entity.alarmLen = buf.readShort();
entity.alarmContent = EntityParseUtil.convertStr(buf, entity.alarmLen);
entity.alarmContent = EntityParseUtil.convertStr(lineId, buf, entity.alarmLen);
entity.alarmAckSiteid = buf.readShort();
entity.alarmAckSite = EntityParseUtil.convertStr(buf, 32);

View File

@ -58,7 +58,7 @@ public class DepotPlanResponse extends MessageResponse {
this.lineId = buf.readShort();
this.date = DateTimeUtil.convert(buf);
this.depotCount = buf.readShort();
this.entityList = EntityParseUtil.collect(this.depotCount, buf, DepotPlanEntity.class);
this.entityList = EntityParseUtil.collect(this.lineId, this.depotCount, buf, DepotPlanEntity.class);
}
@ -230,11 +230,11 @@ public class DepotPlanResponse extends MessageResponse {
private Integer inLocalSubid;
@Override
public DepotPlanEntity read(ByteBuf buf) {
public DepotPlanEntity read(Integer lineId, ByteBuf buf) {
DepotPlanEntity entity = new DepotPlanEntity();
entity.depotStation = buf.readShort();
entity.groupId = EntityParseUtil.convertStr(buf, 9);
entity.driverId = EntityParseUtil.convertStr(buf, 13);
entity.groupId = EntityParseUtil.convertStr(lineId, buf, 9);
entity.driverId = EntityParseUtil.convertStr(lineId, buf, 13);
entity.outFlag = buf.readShort() == 1;
entity.outSchedule = buf.readByte() == 1;
entity.outTime = DateTimeUtil.convert(buf);

View File

@ -66,7 +66,7 @@ public class DeviceStatusBitmapResponse extends MessageResponse {
this.lineId = buf.readShort();
this.rtuId = buf.readShort();
this.typeCnt = buf.readShort();
this.entityList = EntityParseUtil.collect(this.typeCnt, buf, DeviceTypeEntity.class);
this.entityList = EntityParseUtil.collect(this.lineId, this.typeCnt, buf, DeviceTypeEntity.class);
}
@Override
@ -88,7 +88,7 @@ public class DeviceStatusBitmapResponse extends MessageResponse {
DeviceStatusConvertor.convertForTrack(deviceEntity.getStatus(), builder);
DeviceStatusConvertor.convertForPlatform(deviceEntity.getStatus(), (Objects.isNull(deviceEntity.getSpare()) ? 0 : deviceEntity.getSpare()), builder);
DeviceStatusConvertor.convertForSwitch(Objects.isNull(deviceEntity.getSpare()) ? 0 : deviceEntity.getSpare(), builder);
log.info("接受全量状态设备类型:[{}] 对应状态[{}]", dt.name(), builder);
// log.info("接受全量状态设备类型:[{}] 对应状态[{}]", dt.name(), builder);
msgBuildList.add(builder);
}
}
@ -122,12 +122,12 @@ public class DeviceStatusBitmapResponse extends MessageResponse {
private List<DeviceEntity> deviceList;
@Override
public DeviceTypeEntity read(ByteBuf buf) {
public DeviceTypeEntity read(Integer lineId, ByteBuf buf) {
DeviceTypeEntity entity = new DeviceTypeEntity();
entity.type = DeviceType.of(buf.readShort());
entity.objCount = buf.readShort();
entity.deviceList = EntityParseUtil.collect(entity.objCount, buf, DeviceEntity.class);
entity.deviceList = EntityParseUtil.collect(lineId, entity.objCount, buf, DeviceEntity.class);
/* for (DeviceEntity de : entity.deviceList) {
de.devName = DeviceNameChangerManage.findMatch(entity.type, de.devName);
}*/
@ -163,9 +163,9 @@ public class DeviceStatusBitmapResponse extends MessageResponse {
}
@Override
public DeviceEntity read(ByteBuf buf) {
public DeviceEntity read(Integer lineId, ByteBuf buf) {
DeviceEntity entity = new DeviceEntity();
entity.devName = EntityParseUtil.convertStr(buf, 24);
entity.devName = EntityParseUtil.convertStr(lineId, buf, 24);
entity.status = buf.readInt();
entity.spare = buf.readInt();
return entity;

View File

@ -17,6 +17,7 @@ import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
/**
* 2.7.5 设备状态变化消息
@ -79,9 +80,11 @@ public class DeviceStatusChangeResponse extends MessageResponse {
this.lineId = buf.readShort();
this.rtuId = buf.readShort();
this.type = DeviceType.of(buf.readShort());
this.devName = EntityParseUtil.convertStr(buf, 24);
this.devName = EntityParseUtil.convertStr(Integer.valueOf(this.lineId), buf, 24);
this.deviceStatus = buf.readInt();
this.spare = buf.readInt();
// this.devName = DeviceNameChangerManage.findMatch(this.type, this.devName);
}
@ -92,6 +95,7 @@ public class DeviceStatusChangeResponse extends MessageResponse {
log.error("设备变更状态类型为空:{}", JSON.toJSONString(this));
return Collections.emptyList();
}
String occName = DeviceNameChangerManage.findMatch(nameChanger, this.type, this.devName);
// if (this.type == DeviceType.DEVICE_TYPE_SWITCH && StringUtils.startsWith(occName, "DG")) {
// this.type = DeviceType.DEVICE_TYPE_TRACK;

View File

@ -7,20 +7,22 @@ import com.google.common.collect.Lists;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.GeneratedMessageV3;
import io.netty.buffer.ByteBuf;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class EntityParseUtil {
public static <T> List<T> collect(int count, ByteBuf buf, Class<T> tClass) {
public static <T> List<T> collect(int lineId, int count, ByteBuf buf, Class<T> tClass) {
List<T> list = Lists.newArrayListWithCapacity(count);
for (var i = 0; i < count; i++) {
try {
Object obj = tClass.getDeclaredConstructor().newInstance();
if (obj instanceof ReadData rd) {
list.add((T) rd.read(buf));
list.add((T) rd.read(lineId, buf));
}
} catch (Exception e) {
throw new RuntimeException(e);
@ -37,9 +39,32 @@ public class EntityParseUtil {
return name;
}
public static String convertStr(Integer lineId, ByteBuf buf, int len) {
byte[] data = new byte[len];
buf.readBytes(data);
if (lineId == 3) {
return new String(data, MessageCons.STRING_CHARSET).trim();
} else {
int findIndex = 0;
for (; findIndex < data.length; findIndex++) {
byte dn = data[findIndex];
if (dn == 0) {
// findIndex = findIndex;
break;
}
}
byte[] nameByte = new byte[findIndex];
System.arraycopy(data, 0, nameByte, 0, findIndex);
return new String(nameByte, Charset.forName("GBK"));
}
}
public interface ReadData<T> {
T read(ByteBuf buf);
T read(Integer lineId, ByteBuf buf);
}
/* public static void fill(GeneratedMessageV3.Builder builder, String name, Object val) {

View File

@ -66,7 +66,7 @@ public class HistoryScheduleResponse extends MessageResponse {
if (this.subId == ScheduleSubIdType.HISTORY_RUN) {
this.groupId = EntityParseUtil.convertStr(buf, 9);
this.recCnt = buf.readShort();
this.entityList = EntityParseUtil.collect(this.recCnt, buf, HistoryScheduleEntity.class);
this.entityList = EntityParseUtil.collect(this.lineId, this.recCnt, buf, HistoryScheduleEntity.class);
}
}
@ -126,7 +126,7 @@ public class HistoryScheduleResponse extends MessageResponse {
@Override
public HistoryScheduleEntity read(ByteBuf buf) {
public HistoryScheduleEntity read(Integer lineId, ByteBuf buf) {
HistoryScheduleEntity entity = new HistoryScheduleEntity();
entity.stationId = buf.readShort();
@ -134,8 +134,8 @@ public class HistoryScheduleResponse extends MessageResponse {
entity.aTime = DateTimeUtil.convert(buf);
entity.dTime = DateTimeUtil.convert(buf);
entity.flag = buf.readShort();
entity.serviceId = EntityParseUtil.convertStr(buf, 9);
entity.globalId = EntityParseUtil.convertStr(buf, 12);
entity.serviceId = EntityParseUtil.convertStr(lineId, buf, 9);
entity.globalId = EntityParseUtil.convertStr(lineId, buf, 12);
entity.destinationId = EntityParseUtil.convertStr(buf, 4);
entity.planType = buf.readShort() == 1;

View File

@ -75,11 +75,17 @@ public class InusedScheduleResponse extends MessageResponse {
this.lineId = buf.readShort();
this.date = DateTimeUtil.convert(buf);
this.subId = ScheduleSubIdType.of(buf.readShort());
/* if (this.subId == ScheduleSubIdType.HISTORY_BEGIN) {
System.out.println("aaaaaaaaaa");
}
if (this.subId == ScheduleSubIdType.HISTORY_STOP) {
System.out.println("bbbbbbbbbbbb");
}*/
if (this.subId == ScheduleSubIdType.HISTORY_RUN) {
this.trainId = EntityParseUtil.convertStr(buf, 9);
this.tripCnt = buf.readShort();
this.entityList = EntityParseUtil.collect(this.tripCnt, buf, InusedScheduleEntity.class);
this.entityList = EntityParseUtil.collect(this.lineId, this.tripCnt, buf, InusedScheduleEntity.class);
}
}
@ -151,14 +157,14 @@ public class InusedScheduleResponse extends MessageResponse {
@Override
public InusedScheduleEntity read(ByteBuf buf) {
public InusedScheduleEntity read(Integer lineId, ByteBuf buf) {
InusedScheduleEntity entity = new InusedScheduleEntity();
entity.globalId = EntityParseUtil.convertStr(buf, 12);
entity.groupId = EntityParseUtil.convertStr(buf, 9);
entity.destinationId = EntityParseUtil.convertStr(buf, 4);
entity.recCnt = buf.readShort();
entity.recordList = EntityParseUtil.collect(entity.recCnt, buf, EntityRecord.class);
entity.recordList = EntityParseUtil.collect(lineId, entity.recCnt, buf, EntityRecord.class);
return entity;
}
}
@ -204,7 +210,7 @@ public class InusedScheduleResponse extends MessageResponse {
@Override
public EntityRecord read(ByteBuf buf) {
public EntityRecord read(Integer lineId, ByteBuf buf) {
EntityRecord record = new EntityRecord();
record.stationId = buf.readShort();

View File

@ -52,7 +52,7 @@ public class SignalRouteStatusResponse extends MessageResponse {
this.lineId = buf.readShort();
this.rtuId = buf.readShort();
this.singalCount = buf.readShort();
this.signals = EntityParseUtil.collect(this.singalCount, buf, SignalStatusEntity.class);
this.signals = EntityParseUtil.collect(this.lineId, this.singalCount, buf, SignalStatusEntity.class);
}
@ -90,12 +90,12 @@ public class SignalRouteStatusResponse extends MessageResponse {
private List<RouteStatusEntity> routes;
@Override
public SignalStatusEntity read(ByteBuf buf) {
public SignalStatusEntity read(Integer lineId, ByteBuf buf) {
SignalStatusEntity entity = new SignalStatusEntity();
entity.signalName = EntityParseUtil.convertStr(buf, 20);
entity.routeCount = buf.readByte();
entity.routes = EntityParseUtil.collect(entity.routeCount, buf, RouteStatusEntity.class);
entity.routes = EntityParseUtil.collect(lineId, entity.routeCount, buf, RouteStatusEntity.class);
return entity;
}
}
@ -121,9 +121,9 @@ public class SignalRouteStatusResponse extends MessageResponse {
@Override
public RouteStatusEntity read(ByteBuf buf) {
public RouteStatusEntity read(Integer lineId, ByteBuf buf) {
RouteStatusEntity entity = new RouteStatusEntity();
entity.routeName = EntityParseUtil.convertStr(buf, 64);
entity.routeName = EntityParseUtil.convertStr(lineId, buf, 64);
entity.routeStatus = RouteStatusEnum.of(buf.readByte());
return entity;

View File

@ -16,6 +16,8 @@ import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import lombok.Setter;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
/**
@ -23,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
*/
@Getter
@Setter
@Slf4j
public class TrainBlockInfoResponse extends MessageResponse {
/**
@ -41,8 +44,12 @@ public class TrainBlockInfoResponse extends MessageResponse {
@Override
public void decode2(ByteBuf buf) throws Exception {
this.lineId = buf.readShort();
this.trainCnt = buf.readShort();
this.trains = new ArrayList<>(this.trainCnt);
/*if (this.lineId == 4) {
log.warn("lineId:{} 阻塞数据量:{}", this.lineId, this.trainCnt);
}*/
for (int cnt = 0; cnt < this.trainCnt; cnt++) {
this.trains.add(new TrainCell().decode(buf));
}

View File

@ -1,5 +1,6 @@
package club.joylink.xiannccda.ats.message.line3.rep;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.convertor.DeviceStatusConvertor;
@ -81,6 +82,12 @@ public class TrainIndicationInitResponse extends MessageResponse {
if (trainCell.devType == DeviceType.DEVICE_TYPE_SWITCH) {
//车辆在道岔时转换对应的设备类型
builder.setDevType(DeviceStatusProto.DeviceType.SWITCH_TRACK);
/* if (lineId == 4) {
if (StringUtils.startsWith(trainCell.getDevName(), "P")) {
occName = LineGraphicDataRepository.findTurnoutSectionFromTurnoutCode(this.lineId, trainCell.getDevName());
builder.setDevName(occName);
}
}*/
}
builder.setTrainIndex(StringUtils.defaultString(trainCell.getTrainIndex(), ""));
builder.setGroupId(StringUtils.defaultString(trainCell.getGroupId(), ""));

View File

@ -1,5 +1,6 @@
package club.joylink.xiannccda.ats.message.line3.rep;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.convertor.DeviceStatusConvertor;
@ -9,6 +10,7 @@ import club.joylink.xiannccda.ats.message.changer.DeviceNameChangerManage;
import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.TrainProto;
import club.joylink.xiannccda.dto.protos.TrainProto.NccWindow;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
@ -146,13 +148,18 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
if (Objects.nonNull(this.devType)) {
train.setDevType(DeviceStatusProto.DeviceType.forNumber(this.devType.getVal()));
}
// train.setDevName(StringUtils.defaultString(this.devName, ""));
String occName = DeviceNameChangerManage.findMatch(nameChanger, this.devType, this.devName);
train.setDevName(occName);
if (this.devType == DeviceType.DEVICE_TYPE_SWITCH) {
//车辆在道岔时转换对应的设备类型
train.setDevType(DeviceStatusProto.DeviceType.SWITCH_TRACK);
/* if (lineId == 4) {
if (StringUtils.startsWith(this.devName, "P")) {
occName = LineGraphicDataRepository.findTurnoutSectionFromTurnoutCode(this.lineId, this.devName);
train.setDevName(occName);
}
}*/
}
train.setTrainIndex(StringUtils.defaultString(this.trainIndex, ""));
train.setRollingStock(this.getRollingStock());

View File

@ -28,6 +28,7 @@ import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.protobuf.MessageOrBuilder;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -70,6 +71,7 @@ public class AxleLedInterlockTask implements AlertMonitoringTask {
for (Entry<String, InterLockDetail> interLockDetail : detailMap.entrySet()) {
String rtuIdJoinStr = interLockDetail.getKey();
InterLockDetail detail = interLockDetail.getValue();
Optional<AxleInterLockSource> redOpt = this.handle(lineId, detail, AlertType.AXLE_LED_RED, AlertType.AXLE_LED_RED_INTERLOCK_AREA, rtuIdJoinStr);
Optional<AxleInterLockSource> orangeOpt = this.handle(lineId, detail, AlertType.AXLE_LED_ORANGE, AlertType.AXLE_LED_ORANGE_INTERLOCK_AREA, rtuIdJoinStr);
redOpt.ifPresent(axleInterLockSource -> this.alertManager.emit(new LedMostEvent(axleInterLockSource)));
@ -82,6 +84,7 @@ public class AxleLedInterlockTask implements AlertMonitoringTask {
private Optional<AxleInterLockSource> handle(String lineId, InterLockDetail detail, AlertType findWarnAlertType, AlertType warnAlertType, String rtuIdJoinStr) {
int deviceCount = detail.getDevices().size();
Integer lineIdInt = Integer.parseInt(lineId);
//收集联锁下的所有所有区段设备
List<TrackOccupiedStatus> resultList = this.collectorLedWarDevices(findWarnAlertType, lineId, detail.getDevices());
List<String> occupidedDeviceList = resultList.stream().filter(d -> d.occupied).map(d -> d.deviceCode).toList();
@ -110,6 +113,10 @@ public class AxleLedInterlockTask implements AlertMonitoringTask {
}
private List<TrackOccupiedStatus> collectorLedWarDevices(AlertType alertType, String lineId, List<Integer> deviceLayoutIds) {
if (CollectionUtils.isEmpty(deviceLayoutIds)) {
log.error("{}", lineId);
return Collections.emptyList();
}
Integer lineIdInt = Integer.parseInt(lineId);
DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE);
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.TRAIN);
@ -148,17 +155,21 @@ public class AxleLedInterlockTask implements AlertMonitoringTask {
if (deviceStatus instanceof Track.Builder track) {
if (alertType == AlertType.AXLE_LED_RED) {
boolean red = track.getCiOccupied() && !track.getCbtcOccupied();
sectionStatusList.add(red);
sectionStatusList.add(this.isLight(red, track.getReceiveTime()));
} else {
boolean orange = track.getAtcInvalid();
sectionStatusList.add(orange);
sectionStatusList.add(this.isLight(orange, track.getReceiveTime()));
}
}
}
return sectionStatusList.stream().allMatch(d -> d);
}
private boolean isLight(boolean ledLight, long deviceReceiveTime) {
return ledLight && (System.currentTimeMillis() - deviceReceiveTime) / 1000 > 3;
}
private boolean checkTurnoutStatus(Integer lineId, Section section, AlertType alertType, DeviceStatusData deviceStatusData, TrainDataSource trainDataSource) {
List<Boolean> turnoutOccLList = Lists.newArrayListWithCapacity(section.getChildrenList().size());
for (Integer refTuronoutId : section.getChildrenList()) {
@ -173,9 +184,9 @@ public class AxleLedInterlockTask implements AlertMonitoringTask {
boolean ledRed = switchBuild.getIpSingleSwitchStusCiOccupied() && !switchBuild.getIpSingleSwitchStusCbtcOccupied();
boolean orange = switchBuild.getIpSingleSwitchStusAtcInvalid();
if (alertType == AlertType.AXLE_LED_RED) {
turnoutOccLList.add(ledRed);
turnoutOccLList.add(this.isLight(ledRed, switchBuild.getReceiveTime()));
} else {
turnoutOccLList.add(orange);
turnoutOccLList.add(this.isLight(orange, switchBuild.getReceiveTime()));
}
}
}

View File

@ -91,14 +91,15 @@ public class SwitchLostAndJammedTask implements AlertMonitoringTask {
private final static String JAMMED_NAME = "JAMMED";
private void checkJammed(Switch.Builder switchBuild, String layoutId) {
if (switchBuild.getIpSingleSwitchStusJammed()) {
boolean ledRed = switchBuild.getIpSingleSwitchStusCiOccupied();//&& !switchBuild.getIpSingleSwitchStusCbtcOccupied();
boolean orange = switchBuild.getIpSingleSwitchStusAtcInvalid();
if (switchBuild.getIpSingleSwitchStusJammed() && (ledRed || orange)) {
if (alertDataSource.putAlterDevice(switchBuild.getLineId(), JAMMED_NAME, switchBuild.getId())) {
String alertMsg = String.format("设备[%s]挤岔", switchBuild.getId());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_JAMMED, switchBuild, alertMsg, layoutId,
AlertDeviceType.DEVICE_TYPE_SWITCH, false);
alertManager.emit(alertInfo);
}
} else {
alertDataSource.removeAlterDevice(switchBuild.getLineId(), JAMMED_NAME, switchBuild.getId());
}

View File

@ -10,24 +10,31 @@ 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.DeviceStatusData;
import club.joylink.xiannccda.ats.message.collect.datasource.InUsedScheduleData;
import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource;
import club.joylink.xiannccda.ats.message.line3.rep.TrainRecordResponse.DirectionEnum;
import club.joylink.xiannccda.dto.protos.AlertConstProto;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainDelayInfo;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainRecord;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainRecord.Builder;
import club.joylink.xiannccda.dto.protos.TrainShedule.Plan;
import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.base.Strings;
import com.google.protobuf.GeneratedMessageV3;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -57,6 +64,60 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
this.trainRecordMap.put(trainRecord.getTrainId(), trainRecord);
}
void findNexPlatform(TrainRecord.Builder tr) {
alertDataSource.removeAlterDevice(tr.getLineId(), AlertType.TRAIN_DELAY_MIN_5.name(), tr.getGroupId());
alertDataSource.removeAlterDevice(tr.getLineId(), AlertType.TRAIN_DELAY_MIN_15.name(), tr.getGroupId());
alertDataSource.removeAlterDevice(tr.getLineId(), AlertType.TRAIN_DELAY_MIN_25.name(), tr.getGroupId());
alertDataSource.removeAlterDevice(tr.getLineId(), AlertType.TRAIN_DELAY_MIN_55.name(), tr.getGroupId());
boolean upWay = PlatformAlertMonitoringTask.isUpWay(tr);
TrainDataSource trainInfoData = DeviceDataRepository.findDataSouce(String.valueOf(tr.getLineId()), DataTypeEnum.TRAIN);
TrainInfo.Builder ti = trainInfoData.getTrainInfo(tr.getGroupId());
if (Objects.isNull(ti)) {
return;
}
Platform.Builder pf = PlatformAlertMonitoringTask.parsePlatform(tr, upWay);
if (Objects.isNull(pf)) {
ti.setHasNextStation(false);
return;
}
LayoutGraphicsProto.Platform giPF = LineGraphicDataRepository.getDeviceByCode(pf.getLineId(), pf.getId(), LayoutGraphicsProto.Platform.class);
LayoutGraphicsProto.Station station = LineGraphicDataRepository.getDeviceByCodeNotException(pf.getLineId(), String.valueOf(giPF.getRefStation()), LayoutGraphicsProto.Station.class);
if (Objects.isNull(station)) {
ti.setHasNextStation(false);
return;
}
List<Integer> sortStations = LineGraphicDataRepository.allStation(pf.getLineId());
if (tr.getStationId() + 1 <= sortStations.get(sortStations.size() - 1) || tr.getStationId() - 1 >= sortStations.get(0)) {
Integer nextStationInt = tr.getStationId() + 1;
if (upWay == false) {
nextStationInt = tr.getStationId() - 1;
}
InUsedScheduleData scheduleData = DeviceDataRepository.findDataSouce(String.valueOf(tr.getLineId()), DataTypeEnum.TRAIN_PLAN);
Optional<Plan.Builder> planBuildOpt = scheduleData.findPlan(ti.getTrainId(), ti.getGlobalId(), nextStationInt, upWay, tr.getSideId());
if (planBuildOpt.isEmpty()) {
ti.setHasNextStation(false);
return;
}
String nextStationCode = Strings.padStart(String.valueOf(nextStationInt), 2, '0');
LayoutGraphicsProto.Station nextStation = LineGraphicDataRepository.getDevices(tr.getLineId(), LayoutGraphicsProto.Station.class).filter(d -> StringUtils.equals(d.getCode(), nextStationCode))
.findFirst().orElse(null);
if (nextStation == null) {
ti.setHasNextStation(false);
return;
}
ti.setHasNextStation(true);
TrainDelayInfo.Builder tdbuild = TrainDelayInfo.newBuilder();
tdbuild.setNextStationName(nextStation.getName());
tdbuild.setNextStationName(nextStationCode);
tdbuild.setCurrentPlatfomrLayoutId(giPF.getCommon().getId());
tdbuild.setNextStationArriveTime(System.currentTimeMillis());
ti.setTrainDelay(tdbuild);
} else {
ti.setHasNextStation(false);
}
}
public void trainLeavePlatform(TrainRecord.Builder trainRecord) {
boolean isUpWay = trainRecord.getDir() == DirectionEnum.Up.getValue();
Platform.Builder platformBuild = this.parsePlatform(trainRecord, isUpWay);
@ -92,7 +153,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
}
private Platform.Builder parsePlatform(TrainRecord.Builder record, boolean isUpWay) {
static Platform.Builder parsePlatform(TrainRecord.Builder record, boolean isUpWay) {
// String newTrackName = DeviceNameChangerManage.findMatch(DeviceType.DEVICE_TYPE_TRACK, record.getTrackName());
Optional<LayoutGraphicsProto.Platform> layoutPlatformOpt = LineGraphicDataRepository.findLayoutPlatformFromSection(record.getLineId(), record.getTrackName());
String platformCode = layoutPlatformOpt.map(LayoutGraphicsProto.Platform::getCode).orElse(null);
@ -106,7 +167,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
if (Objects.nonNull(builder)) {
Platform.Builder platformBuild = (Platform.Builder) builder;
if (log.isDebugEnabled()) {
log.debug("车站报对应的屏蔽门信息,线路[{}] 列车表号[{}] 列车车次号[{}] 车站id[{}] 站台门id[{}] 上下行[{}] 屏蔽门是否开启[{}] 是否车辆停靠[{}]"
log.debug("未找到对应的站台信息,线路[{}] 列车表号[{}] 列车车次号[{}] 车站id[{}] 站台门id[{}] 上下行[{}] 屏蔽门是否开启[{}] 是否车辆停靠[{}]"
, record.getLineId(), record.getTrainId(), record.getGlobalId(), record.getStationId(), record.getSideId(), isUpWay, platformBuild.getPsdOpen(), platformBuild.getTrainberth());
}
return platformBuild;
@ -176,13 +237,39 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
return false;
}
return true;
}
public void trainDelayCheck(TrainInfo.Builder ti) {
if (ti.getHasNextStation() == false) {
return;
}
TrainDelayInfo.Builder td = ti.getTrainDelayBuilder();
this.trainDelayAlert(ti, 5, AlertType.TRAIN_DELAY_MIN_5);
this.trainDelayAlert(ti, 15, AlertType.TRAIN_DELAY_MIN_15);
this.trainDelayAlert(ti, 25, AlertType.TRAIN_DELAY_MIN_25);
this.trainDelayAlert(ti, 55, AlertType.TRAIN_DELAY_MIN_55);
}
private void trainDelayAlert(TrainInfo.Builder ti, Integer min, AlertType at) {
TrainDelayInfo.Builder td = ti.getTrainDelayBuilder();
long delayTime = (System.currentTimeMillis() - td.getNextStationArriveTime()) / 1000;
if (delayTime >= TimeUnit.MINUTES.toSeconds(min) && alertDataSource.putAlterDevice(ti.getLineId(), at.name(), ti.getGroupId())) {
String msg = String.format("列车[%s] 已晚点超时%d", ti.getGroupId(), min);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), at, ti, msg, String.valueOf(td.getCurrentPlatfomrLayoutId()),
AlertDeviceType.DEVICE_TYPE_PLATFORM, false);
alertManager.emit(alertInfo);
}
}
static boolean isUpWay(TrainRecord.Builder tr) {
return tr.getDir() == DirectionEnum.Up.getValue();
}
@Override
public void run() {
for (Builder record : this.trainRecordMap.values()) {
boolean isUpWay = record.getDir() == DirectionEnum.Up.getValue();
boolean isUpWay = isUpWay(record);
Platform.Builder platformBuild = this.parsePlatform(record, isUpWay);
if (Objects.isNull(platformBuild)) {
this.removeTrainRecord(record);

View File

@ -8,67 +8,234 @@ import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
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.datasource.DeviceStatusData;
import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource;
import club.joylink.xiannccda.configuration.protos.OccServerProto;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RelatedRef.DeviceType;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.entity.DeviceAreaConfig;
import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceAreaConfigService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
import club.joylink.xiannccda.vo.AreaConfigVO;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Lists;
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.MessageOrBuilder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
@Slf4j
@Order(30)
public class PlatformEmergStopTask implements AlertMonitoringTask {
@Autowired
private AlertInfoService alertInfoService;
@Autowired
private DeviceAreaConfigService deviceAreaConfigService;
@Autowired
private DeviceGuardConfigService guardConfigService;
private final AlertDeviceStatusRepository alertDataSource = AlertDeviceStatusRepository.getInstance();
private final AlertManager alertManager = AlertManager.getDefault();
@Override
public String getName() {
return "PLATFORM_EMERG_STOP_ALTER";
}
private void emergStop(Platform.Builder platformBuild, LayoutGraphicsProto.Platform giPlatform) {
Integer lineId = platformBuild.getLineId();
if (platformBuild.getEmergstop()) {
if (alertDataSource.putAlterDevice(lineId, this.getName(), platformBuild.getId())) {
Integer layOutId = giPlatform.getCommon().getId();
Station station = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), giPlatform.getRefStation() + "", Station.class);
String upWay = giPlatform.getUp() ? "上行" : "下行";
String msg = String.format("%s-%s站台 应急触发", station.getName(), upWay);
// Optional<AreaConfigVO> optional = alertInfoService.findAreaDevice(AlertType.PLATFORM_EMERG_STOP, AlertDeviceType.DEVICE_TYPE_PLATFORM, layOutId, lineIdInt);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.PLATFORM_EMERG_STOP, platformBuild, msg, layOutId.toString(),
AlertDeviceType.DEVICE_TYPE_PLATFORM, false);
alertManager.emit(alertInfo);
}
} else {
alertDataSource.removeAlterDevice(lineId, this.getName(), platformBuild.getId());
}
}
private final static String PLATFORM_HOLD_ALERT_NAME = "platform_hold_alert";
private void stationPlatformHoldCheck(Platform.Builder platformBuild, LayoutGraphicsProto.Platform giPlatform, List<Integer> stationCodeList) {
boolean upHold = platformBuild.getUpHold() || platformBuild.getUpOccHold();
boolean downHold = platformBuild.getDownHold() || platformBuild.getDownOccHold();
if (!upHold && !downHold) {
alertDataSource.removeAlterDevice(platformBuild.getLineId(), PLATFORM_HOLD_ALERT_NAME, platformBuild.getId());
return;
}
LayoutGraphicsProto.Station station = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), String.valueOf(giPlatform.getRefStation()), LayoutGraphicsProto.Station.class);
Integer currentStationCodeInt = Integer.valueOf(station.getCode());
Integer startStationCodeInt = stationCodeList.get(0);
if (giPlatform.getUp() == false) {
startStationCodeInt = stationCodeList.get(stationCodeList.size() - 1);
}
if (!currentStationCodeInt.equals(startStationCodeInt)) {
LayoutGraphicsProto.Section startSection = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), giPlatform.getRefSectionId() + "", LayoutGraphicsProto.Section.class);
LayoutGraphicsProto.RelatedRef sectionRef = startSection.getPaRef();
if (giPlatform.getUp() == false) {
sectionRef = startSection.getPbRef();
}
Map<Integer, GeneratedMessageV3> deviceMap = new HashMap<>();
deviceMap.put(startSection.getCommon().getId(), startSection);
findPlatformTrack(platformBuild, giPlatform.getUp(), sectionRef, deviceMap);
deviceMap.remove(startSection.getCommon().getId());//移除站台轨
List<LayoutGraphicsProto.Section> trackAreas = deviceMap.values().stream().filter(d -> d instanceof LayoutGraphicsProto.Section).map(d -> (LayoutGraphicsProto.Section) d).toList();
List<String> areaTrainGroups = this.findAreaTrain(trackAreas, platformBuild.getLineId());
if (areaTrainGroups.size() >= 2 && alertDataSource.putAlterDevice(platformBuild.getLineId(), PLATFORM_HOLD_ALERT_NAME, platformBuild.getId())) {
String pf = giPlatform.getUp() ? "上行站台" : "下行站台";
String msg = String.format("%s%s扣车此区间已驶入%d辆列车", station.getName(), pf, areaTrainGroups.size());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.HOLD_PLATFORM_STAY_TRAIN_MORE, platformBuild, msg, String.valueOf(giPlatform.getCommon().getId()),
AlertDeviceType.DEVICE_TYPE_PLATFORM, false);
alertManager.emit(alertInfo);
}
}
}
private List<String> findAreaTrain(List<LayoutGraphicsProto.Section> findTrackArea, Integer lineId) {
List<String> findAreaTrains = Lists.newArrayList();
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.TRAIN);
for (Section section : findTrackArea) {
if (section.getSectionType() == SectionType.Physical) {
for (Integer childSecionId : section.getChildrenList()) {
MessageOrBuilder childMB = LineGraphicDataRepository.getDeviceByCode(lineId, childSecionId.toString());
String deviceCode = DeviceStatusDataOperate.findFieldVal(childMB, "code", String.class);
String trainGroupId = trainDataSource.findTrainForDeviceName(deviceCode);
if (StringUtils.isNotEmpty(trainGroupId)) {
findAreaTrains.add(trainGroupId);
}
}
} else if (section.getSectionType() == SectionType.TurnoutPhysical) {
String trainGroupId = trainDataSource.findTrainForDeviceName(section.getCode());
if (StringUtils.isNotEmpty(trainGroupId)) {
findAreaTrains.add(trainGroupId);
}
}
}
return findAreaTrains;
}
/**
* 获取站台所属的道轨
*
* @param platformBuild
* @param upway
* @param startRef
* @param deviceMap
*/
public void findPlatformTrack(Platform.Builder platformBuild, boolean upway, LayoutGraphicsProto.RelatedRef startRef, Map<Integer, GeneratedMessageV3> deviceMap) {
if (startRef.getDeviceType() == DeviceType.Turnout) {
LayoutGraphicsProto.Turnout turnout = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), startRef.getId() + "", LayoutGraphicsProto.Turnout.class);
String sectionCode = LineGraphicDataRepository.findTurnoutSectionFromTurnoutCode(platformBuild.getLineId(), turnout.getCode());
LayoutGraphicsProto.Section turnoutSec = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), sectionCode + "", LayoutGraphicsProto.Section.class);
deviceMap.put(turnoutSec.getCommon().getId(), turnoutSec);
deviceMap.put(turnout.getCommon().getId(), turnout);
if (deviceMap.containsKey(turnout.getPaRef().getId())) {
this.findPlatformTrack(platformBuild, upway, turnout.getPbRef(), deviceMap);
} else {
this.findPlatformTrack(platformBuild, upway, turnout.getPaRef(), deviceMap);
}
} else if (startRef.getDeviceType() == DeviceType.Section) {
LayoutGraphicsProto.Section nextSection = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), startRef.getId() + "", LayoutGraphicsProto.Section.class);
Optional<LayoutGraphicsProto.Platform> layoutPlatformOpt = LineGraphicDataRepository.findLayoutPlatformFromSection(platformBuild.getLineId(), nextSection.getCode());
String platformCode = layoutPlatformOpt.map(LayoutGraphicsProto.Platform::getCode).orElse(null);
if (StringUtils.isNotEmpty(platformCode)) {
return;
}
deviceMap.put(nextSection.getCommon().getId(), nextSection);
LayoutGraphicsProto.RelatedRef sectionRef = nextSection.getPaRef();
if (upway == false) {
sectionRef = nextSection.getPbRef();
}
this.findPlatformTrack(platformBuild, upway, sectionRef, deviceMap);
}
}
private final static String PLATFORM_WAIT_MAX_TIME_ALERT_NAME = "platform_wait_max_time_alert";
/**
* 检查站台列车候车时间阈值
*
* @param platformBuild
*/
private void checkPlatformWithTimeOut(Platform.Builder platformBuild, LayoutGraphicsProto.Platform giPlatform) {
if (platformBuild.getBizWaitTimerGoing() == false && platformBuild.getBizWaitStartTimeSec() > 0) {
long waitTimes = (System.currentTimeMillis() / 1000 - (platformBuild.getBizWaitStartTimeSec()));
GuardConfig config = this.guardConfigService.getGuardConfig(platformBuild.getLineId());
if (waitTimes > config.getPlatformWaitTimes()) {
if (alertDataSource.putAlterDevice(platformBuild.getLineId(), PLATFORM_WAIT_MAX_TIME_ALERT_NAME, platformBuild.getId())) {
LayoutGraphicsProto.Station station = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), giPlatform.getRefStation() + "", LayoutGraphicsProto.Station.class);
String pf = giPlatform.getUp() ? "上行站台" : "下行站台";
String msg = String.format("%s%s乘客等待列车时间超过%d秒", station.getName(), pf, config.getPlatformWaitTimes());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.PLATFORM_WAIT_TRAIN_MAX_RECORD, platformBuild, msg, String.valueOf(giPlatform.getCommon().getId()),
AlertDeviceType.DEVICE_TYPE_PLATFORM, false);
alertManager.emit(alertInfo);
}
}
} else {
alertDataSource.removeAlterDevice(platformBuild.getLineId(), PLATFORM_WAIT_MAX_TIME_ALERT_NAME, platformBuild.getId());
}
}
@Override
public void run() {
Set<String> allLineSet = DeviceDataRepository.getAllLines();
for (String lineIdStr : allLineSet) {
Integer lineIdInt = Integer.parseInt(lineIdStr);
List<Integer> stationCodeList = LineGraphicDataRepository.allStation(lineIdInt);
DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineIdStr, DataTypeEnum.DEVICE);
List<LayoutGraphicsProto.Platform> giPlatformList = LineGraphicDataRepository.getDevices(lineIdInt, LayoutGraphicsProto.Platform.class).toList();
List<LayoutGraphicsProto.Platform> giPlatformList = LineGraphicDataRepository.getDevices(lineIdInt, LayoutGraphicsProto.Platform.class).distinct().toList();
for (LayoutGraphicsProto.Platform giPlatform : giPlatformList) {
Map<String, Builder> builderMap = deviceStatusData.getAllDeviceMap().get(DeviceStatusProto.Platform.getDescriptor().getName());
if (CollectionUtils.isNotEmpty(builderMap) && Objects.nonNull(builderMap.get(giPlatform.getCode()))) {
Platform.Builder platformBuild = (Platform.Builder) builderMap.get(giPlatform.getCode());
if (platformBuild.getEmergstop()) {
if (alertDataSource.putAlterDevice(lineIdInt, this.getName(), platformBuild.getId())) {
Integer layOutId = giPlatform.getCommon().getId();
Station station = LineGraphicDataRepository.getDeviceByCode(lineIdInt, giPlatform.getRefStation() + "", Station.class);
String upWay = giPlatform.getUp() ? "上行" : "下行";
String msg = String.format("%s-%s站台 应急触发", station.getName(), upWay);
// Optional<AreaConfigVO> optional = alertInfoService.findAreaDevice(AlertType.PLATFORM_EMERG_STOP, AlertDeviceType.DEVICE_TYPE_PLATFORM, layOutId, lineIdInt);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.PLATFORM_EMERG_STOP, platformBuild, msg, layOutId.toString(),
AlertDeviceType.DEVICE_TYPE_PLATFORM, false);
alertManager.emit(alertInfo);
}
} else {
alertDataSource.removeAlterDevice(lineIdInt, this.getName(), platformBuild.getId());
}
this.emergStop(platformBuild, giPlatform);
this.stationPlatformHoldCheck(platformBuild, giPlatform, stationCodeList);
this.checkPlatformWithTimeOut(platformBuild, giPlatform);
}
}
}
}
}

View File

@ -1,13 +1,29 @@
package club.joylink.xiannccda.ats.warn.platform;
import club.joylink.xiannccda.alert.core.AlertDeviceStatusRepository;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
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.InUsedScheduleData;
import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource;
import club.joylink.xiannccda.ats.message.line3.rep.TrainRecordResponse.DirectionEnum;
import club.joylink.xiannccda.ats.warn.DeviceAlertEvent;
import club.joylink.xiannccda.ats.warn.platform.TrainReacrdAlertListener.TrainRecordAlertEvent;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainDelayInfo;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainRecord;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainRecord.Builder;
import club.joylink.xiannccda.dto.protos.TrainShedule.Plan;
import com.google.common.base.Strings;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -23,14 +39,15 @@ public class TrainReacrdAlertListener implements AlertSourceEventListener<TrainR
this.platformAlertMonitoringTask = platformAlertMonitoringTask;
}
@Override
public void accept(TrainRecordAlertEvent event) {
TrainRecord.Builder trainRecord = event.getSource();
if (trainRecord.getRecordType()) {
log.info("列车报点,线路[{}] 列车表号[{}] 列车车次号[{}] 车站[{}] 上行[{}] 列车类型[{}] 是否进站[{}]",
trainRecord.getLineId(), trainRecord.getTrainId(), trainRecord.getGlobalId(), trainRecord.getStationId(), (trainRecord.getDir() == DirectionEnum.Up.getValue()), trainRecord.getTrainType(),
trainRecord.getRecordType());
this.platformAlertMonitoringTask.findNexPlatform(trainRecord);
this.platformAlertMonitoringTask.putTrainRecord(trainRecord);
} else {
log.info("列车报点驶离,线路[{}] 列车表号[{}] 列车车次号[{}] 车站[{}] 上行[{}] 列车类型[{}] 是否进站[{}]",

View File

@ -66,6 +66,11 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
private final static String TRAIN_INTEGRITY_NAME = "TRAIN_INTEGRITY";
/**
* 列车不完整直接报警
*
* @param trainInfo
*/
public void trainIntegrityAlarm(TrainInfo.Builder trainInfo) {
if (trainInfo.getMode().getIpModeTrainIntegrityAlarm()) {
if (alertDataSource.putAlterDevice(trainInfo.getLineId(), TRAIN_INTEGRITY_NAME, trainInfo.getGroupId())) {
@ -93,6 +98,7 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
}
}
/**
* 判断紧致后发生atp切除并恢复
* <p>
@ -127,13 +133,12 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
return "TRAIN_EB_WITH_ATP_CUT_ALTER";
}
protected void trainAlert(TrainInfo.Builder trainInfo) {
private Integer findTrainLocation(TrainInfo.Builder trainInfo) {
MessageOrBuilder mb = LineGraphicDataRepository.getDeviceByCodeNotException(trainInfo.getLineId(), trainInfo.getDevName());
if (!(mb instanceof LogicSection) && !(mb instanceof Turnout) && !(mb instanceof Section)) {
log.error("线路[{}]列车[{}]所在未知设备[{}]", trainInfo.getLineId(), trainInfo.getGroupId(), trainInfo.getDevName());
this.trainInfoMap.remove(trainInfo.getGroupId());
return;
return null;
}
CommonInfo commonInfo = DeviceStatusDataOperate.findFieldVal(mb, "common", CommonInfo.class);
Integer layoutDeviceId = commonInfo.getId();
@ -141,13 +146,19 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
String axleCode = LineGraphicDataRepository.findAxleCodeFromLogicCode(trainInfo.getLineId(), trainInfo.getDevName());
Section section = LineGraphicDataRepository.getDeviceByCode(trainInfo.getLineId(), axleCode, Section.class);
layoutDeviceId = section.getCommon().getId();
}
if (mb instanceof Turnout) {
} else if (mb instanceof Turnout) {
String turnoutCode = LineGraphicDataRepository.findTurnoutSectionFromTurnoutCode(trainInfo.getLineId(), trainInfo.getDevName());
Section section = LineGraphicDataRepository.getDeviceByCode(trainInfo.getLineId(), turnoutCode, Section.class);
layoutDeviceId = section.getCommon().getId();
}
return layoutDeviceId;
}
protected void trainAlert(TrainInfo.Builder trainInfo) {
Integer layoutDeviceId = this.findTrainLocation(trainInfo);
if (Objects.isNull(layoutDeviceId)) {
return;
}
if (alertDataSource.putAlterDevice(trainInfo.getLineId(), this.getName(), trainInfo.getGroupId())) {
log.info("列车紧制ATP检测告警 线路[{}] 列车车组号[{}] 所在设备[{}]", trainInfo.getLineId(), trainInfo.getGroupId(), trainInfo.getDevName());
String alertMsg = String.format("列车[%s] 紧制导致ATP切除所在区段[%s]", trainInfo.getGroupId(), trainInfo.getDevName());
@ -158,6 +169,21 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
this.trainInfoMap.remove(trainInfo.getGroupId());
}
private final static String TRAIN_LOST_LOCATION_ALERT_NAME = "train_lost_location_alert";
private void trainLostLocation(TrainInfo.Builder trainInfo) {
Integer layoutDeviceId = this.findTrainLocation(trainInfo);
if (Objects.isNull(layoutDeviceId)) {
return;
}
if (alertDataSource.putAlterDevice(trainInfo.getLineId(), TRAIN_LOST_LOCATION_ALERT_NAME, trainInfo.getGroupId())) {
String alertMsg = String.format("列车[%s] 定位丢失所在区段[%s]", trainInfo.getGroupId(), trainInfo.getDevName());
NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.TRAIN_LOST_LOCATION, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, trainInfo, alertMsg,
AlertDeviceType.DEVICE_TYPE_TRAIN, false);
alertManager.emit(alertInfo);
}
}
@Override
public void run() {
for (Builder trainInfo : this.trainInfoMap.values()) {
@ -172,6 +198,12 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
} else if (timeOver) {
this.trainInfoMap.remove(groupId);
}
if (trainInfo.getMode().getIpModeTrainDriveModeRmf()) {
//列车紧致导致rm模式
this.trainLostLocation(trainInfo);
} else if (trainInfo.getMode().getIpModeTrainDriveModeRmf() == false) {
alertDataSource.removeAlterDevice(trainInfo.getLineId(), TRAIN_LOST_LOCATION_ALERT_NAME, trainInfo.getGroupId());
}
}
}

View File

@ -2,6 +2,7 @@ package club.joylink.xiannccda.ats.warn.train;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.ats.warn.DeviceAlertEvent;
import club.joylink.xiannccda.ats.warn.platform.PlatformAlertMonitoringTask;
import club.joylink.xiannccda.ats.warn.train.TrainModeAlertListener.TrainAlertEvent;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
@ -18,9 +19,11 @@ import org.springframework.stereotype.Component;
public class TrainModeAlertListener implements AlertSourceEventListener<TrainAlertEvent> {
private final TrainAtpCutAlertMonitoringTask atpCutAlertMonitoringTask;
private final PlatformAlertMonitoringTask platformAlertMonitoringTask;
public TrainModeAlertListener(TrainAtpCutAlertMonitoringTask atpCutAlertMonitoringTask) {
public TrainModeAlertListener(TrainAtpCutAlertMonitoringTask atpCutAlertMonitoringTask, PlatformAlertMonitoringTask platformAlertMonitoringTask) {
this.atpCutAlertMonitoringTask = atpCutAlertMonitoringTask;
this.platformAlertMonitoringTask = platformAlertMonitoringTask;
}
@Override
@ -30,6 +33,8 @@ public class TrainModeAlertListener implements AlertSourceEventListener<TrainAle
TrainMode trainMode = trainInfo.getMode();
//列车不完整直接报警
this.atpCutAlertMonitoringTask.trainIntegrityAlarm(trainInfo);
//列车晚点超时
this.platformAlertMonitoringTask.trainDelayCheck(trainInfo);
if (trainMode.getIpModeTrainEbAlarm()) {
//列车紧急制动
log.info("列车紧制ATP检测 线路[{}] 列车车组号[{}] 所在设备[{}] 是否ATP切除[{}] 是否紧制[{}]", trainInfo.getLineId(), trainInfo.getGroupId(), trainInfo.getDevName(),
@ -38,15 +43,16 @@ public class TrainModeAlertListener implements AlertSourceEventListener<TrainAle
this.atpCutAlertMonitoringTask.putTrainInfoMonitor(trainInfo);
} else if (Objects.equals(false, trainMode.getIpModeTrainAtpCut())) {
this.atpCutAlertMonitoringTask.recoverAtpCut(trainInfo);
//TODo
} else {
this.atpCutAlertMonitoringTask.updateTrainInfo(trainInfo);
}
} else if (trainMsgBuild instanceof TrainRemove.Builder trainRemove) {
this.atpCutAlertMonitoringTask.trainRemoveAllInfo(trainRemove);
}
}
public static class TrainAlertEvent extends DeviceAlertEvent<Builder> {
public TrainAlertEvent(GeneratedMessageV3.Builder source) {

View File

@ -0,0 +1,25 @@
package club.joylink.xiannccda.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/mock/ats")
@Tag(name = "线路信息管理接口")
@RequiredArgsConstructor
public class MockLoadAtsDataController {
@PostMapping("")
public void startLoad() {
}
@DeleteMapping()
public void delete() {
}
}

View File

@ -0,0 +1,16 @@
package club.joylink.xiannccda.dto.mock;
import java.time.LocalDateTime;
import lombok.Data;
@Data
public class MockRequestDTO {
private LineType lineType;
private LocalDateTime beginDate;
private LocalDateTime endDate;
public enum LineType {
ALL, LINE3, LINE4;
}
}

View File

@ -19,8 +19,10 @@ public abstract class NewAlertMockDTO {
public MessageId parseMessageId() {
if (alertType == AlertType.TRAIN_EB_ATP) {
return MessageId.TRAIN_INDICATION_UPDATE;
} else if (alertType == AlertType.TRAIN_RECORD) {
} else if (alertType == AlertType.PLATFORM_WAIT_TRAIN_MAX_RECORD) {
return MessageId.TRAIN_RECORD;
} else if (alertType == AlertType.HOLD_PLATFORM_STAY_TRAIN_MORE) {
return MessageId.TRAIN_INDICATION_UPDATE;
}
return MessageId.DEVICE_STATUS_CHANGE;

View File

@ -12,7 +12,7 @@ public class SwitchJammedMockDTO extends NewAlertMockDTO {
return 40;
}
case ALERT -> {
return 261;
return 67350;
}
}
return 0;

View File

@ -0,0 +1,20 @@
package club.joylink.xiannccda.dto.mock.show;
import lombok.Data;
@Data
public class TrainUpdateMockDTO extends NewAlertMockDTO {
@Override
public Integer deviceStatus(AlertMockStatus status) {
/* switch (status) {
case NORMAL -> {
return 0x01;
}
case BEGIN -> {
return 0x02;
}
}*/
return 0;
}
}

View File

@ -432,9 +432,41 @@ public final class AlertConstProto {
*/
INTERLOCKED_ATS_STUCK(30),
/**
* <code>TRAIN_RECORD = 31;</code>
* <pre>
*列车驶入驶离站台
* </pre>
*
* <code>PLATFORM_WAIT_TRAIN_MAX_RECORD = 31;</code>
*/
TRAIN_RECORD(31),
PLATFORM_WAIT_TRAIN_MAX_RECORD(31),
/**
* <pre>
*车站扣车
* </pre>
*
* <code>HOLD_PLATFORM_STAY_TRAIN_MORE = 32;</code>
*/
HOLD_PLATFORM_STAY_TRAIN_MORE(32),
/**
* <pre>
*列车晚点
* </pre>
*
* <code>TRAIN_DELAY_MIN_5 = 33;</code>
*/
TRAIN_DELAY_MIN_5(33),
/**
* <code>TRAIN_DELAY_MIN_15 = 34;</code>
*/
TRAIN_DELAY_MIN_15(34),
/**
* <code>TRAIN_DELAY_MIN_25 = 35;</code>
*/
TRAIN_DELAY_MIN_25(35),
/**
* <code>TRAIN_DELAY_MIN_55 = 36;</code>
*/
TRAIN_DELAY_MIN_55(36),
UNRECOGNIZED(-1),
;
@ -667,9 +699,41 @@ public final class AlertConstProto {
*/
public static final int INTERLOCKED_ATS_STUCK_VALUE = 30;
/**
* <code>TRAIN_RECORD = 31;</code>
* <pre>
*列车驶入驶离站台
* </pre>
*
* <code>PLATFORM_WAIT_TRAIN_MAX_RECORD = 31;</code>
*/
public static final int TRAIN_RECORD_VALUE = 31;
public static final int PLATFORM_WAIT_TRAIN_MAX_RECORD_VALUE = 31;
/**
* <pre>
*车站扣车
* </pre>
*
* <code>HOLD_PLATFORM_STAY_TRAIN_MORE = 32;</code>
*/
public static final int HOLD_PLATFORM_STAY_TRAIN_MORE_VALUE = 32;
/**
* <pre>
*列车晚点
* </pre>
*
* <code>TRAIN_DELAY_MIN_5 = 33;</code>
*/
public static final int TRAIN_DELAY_MIN_5_VALUE = 33;
/**
* <code>TRAIN_DELAY_MIN_15 = 34;</code>
*/
public static final int TRAIN_DELAY_MIN_15_VALUE = 34;
/**
* <code>TRAIN_DELAY_MIN_25 = 35;</code>
*/
public static final int TRAIN_DELAY_MIN_25_VALUE = 35;
/**
* <code>TRAIN_DELAY_MIN_55 = 36;</code>
*/
public static final int TRAIN_DELAY_MIN_55_VALUE = 36;
public final int getNumber() {
@ -725,7 +789,12 @@ public final class AlertConstProto {
case 28: return TRAIN_INTEGRITY_ALARM;
case 29: return TRAIN_FAULT_HELP;
case 30: return INTERLOCKED_ATS_STUCK;
case 31: return TRAIN_RECORD;
case 31: return PLATFORM_WAIT_TRAIN_MAX_RECORD;
case 32: return HOLD_PLATFORM_STAY_TRAIN_MORE;
case 33: return TRAIN_DELAY_MIN_5;
case 34: return TRAIN_DELAY_MIN_15;
case 35: return TRAIN_DELAY_MIN_25;
case 36: return TRAIN_DELAY_MIN_55;
default: return null;
}
}
@ -969,7 +1038,7 @@ public final class AlertConstProto {
"\n\020alertConst.proto\022\005alert*g\n\rAlertLocati" +
"on\022\032\n\026ALERT_LOCATION_UNKNOWN\020\000\022\006\n\002QX\020\001\022\013" +
"\n\007YHZ_LSQ\020\002\022\013\n\007HJM_LSQ\020\003\022\013\n\007BCT_LSQ\020\004\022\013\n" +
"\007BSQ_LSQ\020\005*\350\005\n\tAlertType\022\026\n\022ALERT_TYPE_U" +
"\007BSQ_LSQ\020\005*\374\006\n\tAlertType\022\026\n\022ALERT_TYPE_U" +
"NKNOWN\020\000\022\020\n\014BLUE_DISPLAY\020\001\022\021\n\rTRAIN_DELA" +
"Y_2\020\002\022\022\n\016TRAIN_DELAY_10\020\003\022\'\n#PLATFORM_DO" +
"OR_WITHOUT_LOCKED_SIGNAL\020\004\022\035\n\031PLATFORM_D" +
@ -987,12 +1056,16 @@ public final class AlertConstProto {
"TCH_JAMMED\020\031\022\030\n\024INTERLOCKED_ZC_FAULT\020\032\022\027" +
"\n\023TRAIN_LOST_LOCATION\020\033\022\031\n\025TRAIN_INTEGRI" +
"TY_ALARM\020\034\022\024\n\020TRAIN_FAULT_HELP\020\035\022\031\n\025INTE" +
"RLOCKED_ATS_STUCK\020\036\022\020\n\014TRAIN_RECORD\020\037*x\n" +
"\rTipTimeConfig\022\026\n\022HOLIDAYS_MORN_PEAK\020\000\022\031" +
"\n\025HOLIDAYS_EVENING_PEAK\020\001\022\r\n\tMORN_PEAK\020\002" +
"\022\021\n\rEVENING_PEARK\020\003\022\022\n\016NORMAL_UNPEARK\020\004B" +
"4\n!club.joylink.xiannccda.dto.protosB\017Al" +
"ertConstProtob\006proto3"
"RLOCKED_ATS_STUCK\020\036\022\"\n\036PLATFORM_WAIT_TRA" +
"IN_MAX_RECORD\020\037\022!\n\035HOLD_PLATFORM_STAY_TR" +
"AIN_MORE\020 \022\025\n\021TRAIN_DELAY_MIN_5\020!\022\026\n\022TRA" +
"IN_DELAY_MIN_15\020\"\022\026\n\022TRAIN_DELAY_MIN_25\020" +
"#\022\026\n\022TRAIN_DELAY_MIN_55\020$*x\n\rTipTimeConf" +
"ig\022\026\n\022HOLIDAYS_MORN_PEAK\020\000\022\031\n\025HOLIDAYS_E" +
"VENING_PEAK\020\001\022\r\n\tMORN_PEAK\020\002\022\021\n\rEVENING_" +
"PEARK\020\003\022\022\n\016NORMAL_UNPEARK\020\004B4\n!club.joyl" +
"ink.xiannccda.dto.protosB\017AlertConstProt" +
"ob\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,

View File

@ -13650,24 +13650,40 @@ public final class DeviceStatusProto {
boolean getClose();
/**
* <pre>
*上行方向车站扣车
* </pre>
*
* <code>bool upHold = 4;</code>
* @return The upHold.
*/
boolean getUpHold();
/**
* <pre>
*下行方向车站扣车
* </pre>
*
* <code>bool downHold = 5;</code>
* @return The downHold.
*/
boolean getDownHold();
/**
* <pre>
*上行方向中心扣车
* </pre>
*
* <code>bool upOccHold = 6;</code>
* @return The upOccHold.
*/
boolean getUpOccHold();
/**
* <pre>
*下行方向中心扣车
* </pre>
*
* <code>bool downOccHold = 7;</code>
* @return The downOccHold.
*/
@ -13897,6 +13913,10 @@ public final class DeviceStatusProto {
public static final int UPHOLD_FIELD_NUMBER = 4;
private boolean upHold_ = false;
/**
* <pre>
*上行方向车站扣车
* </pre>
*
* <code>bool upHold = 4;</code>
* @return The upHold.
*/
@ -13908,6 +13928,10 @@ public final class DeviceStatusProto {
public static final int DOWNHOLD_FIELD_NUMBER = 5;
private boolean downHold_ = false;
/**
* <pre>
*下行方向车站扣车
* </pre>
*
* <code>bool downHold = 5;</code>
* @return The downHold.
*/
@ -13919,6 +13943,10 @@ public final class DeviceStatusProto {
public static final int UPOCCHOLD_FIELD_NUMBER = 6;
private boolean upOccHold_ = false;
/**
* <pre>
*上行方向中心扣车
* </pre>
*
* <code>bool upOccHold = 6;</code>
* @return The upOccHold.
*/
@ -13930,6 +13958,10 @@ public final class DeviceStatusProto {
public static final int DOWNOCCHOLD_FIELD_NUMBER = 7;
private boolean downOccHold_ = false;
/**
* <pre>
*下行方向中心扣车
* </pre>
*
* <code>bool downOccHold = 7;</code>
* @return The downOccHold.
*/
@ -15136,6 +15168,10 @@ public final class DeviceStatusProto {
private boolean upHold_ ;
/**
* <pre>
*上行方向车站扣车
* </pre>
*
* <code>bool upHold = 4;</code>
* @return The upHold.
*/
@ -15144,6 +15180,10 @@ public final class DeviceStatusProto {
return upHold_;
}
/**
* <pre>
*上行方向车站扣车
* </pre>
*
* <code>bool upHold = 4;</code>
* @param value The upHold to set.
* @return This builder for chaining.
@ -15156,6 +15196,10 @@ public final class DeviceStatusProto {
return this;
}
/**
* <pre>
*上行方向车站扣车
* </pre>
*
* <code>bool upHold = 4;</code>
* @return This builder for chaining.
*/
@ -15168,6 +15212,10 @@ public final class DeviceStatusProto {
private boolean downHold_ ;
/**
* <pre>
*下行方向车站扣车
* </pre>
*
* <code>bool downHold = 5;</code>
* @return The downHold.
*/
@ -15176,6 +15224,10 @@ public final class DeviceStatusProto {
return downHold_;
}
/**
* <pre>
*下行方向车站扣车
* </pre>
*
* <code>bool downHold = 5;</code>
* @param value The downHold to set.
* @return This builder for chaining.
@ -15188,6 +15240,10 @@ public final class DeviceStatusProto {
return this;
}
/**
* <pre>
*下行方向车站扣车
* </pre>
*
* <code>bool downHold = 5;</code>
* @return This builder for chaining.
*/
@ -15200,6 +15256,10 @@ public final class DeviceStatusProto {
private boolean upOccHold_ ;
/**
* <pre>
*上行方向中心扣车
* </pre>
*
* <code>bool upOccHold = 6;</code>
* @return The upOccHold.
*/
@ -15208,6 +15268,10 @@ public final class DeviceStatusProto {
return upOccHold_;
}
/**
* <pre>
*上行方向中心扣车
* </pre>
*
* <code>bool upOccHold = 6;</code>
* @param value The upOccHold to set.
* @return This builder for chaining.
@ -15220,6 +15284,10 @@ public final class DeviceStatusProto {
return this;
}
/**
* <pre>
*上行方向中心扣车
* </pre>
*
* <code>bool upOccHold = 6;</code>
* @return This builder for chaining.
*/
@ -15232,6 +15300,10 @@ public final class DeviceStatusProto {
private boolean downOccHold_ ;
/**
* <pre>
*下行方向中心扣车
* </pre>
*
* <code>bool downOccHold = 7;</code>
* @return The downOccHold.
*/
@ -15240,6 +15312,10 @@ public final class DeviceStatusProto {
return downOccHold_;
}
/**
* <pre>
*下行方向中心扣车
* </pre>
*
* <code>bool downOccHold = 7;</code>
* @param value The downOccHold to set.
* @return This builder for chaining.
@ -15252,6 +15328,10 @@ public final class DeviceStatusProto {
return this;
}
/**
* <pre>
*下行方向中心扣车
* </pre>
*
* <code>bool downOccHold = 7;</code>
* @return This builder for chaining.
*/

View File

@ -87,6 +87,16 @@ public final class GuardConfigProto {
* @return The trainAtpCutTimes.
*/
int getTrainAtpCutTimes();
/**
* <pre>
*乘客等待时间
* </pre>
*
* <code>int32 platformWaitTimes = 8;</code>
* @return The platformWaitTimes.
*/
int getPlatformWaitTimes();
}
/**
* Protobuf type {@code alert.GuardConfig}
@ -228,6 +238,21 @@ public final class GuardConfigProto {
return trainAtpCutTimes_;
}
public static final int PLATFORMWAITTIMES_FIELD_NUMBER = 8;
private int platformWaitTimes_ = 0;
/**
* <pre>
*乘客等待时间
* </pre>
*
* <code>int32 platformWaitTimes = 8;</code>
* @return The platformWaitTimes.
*/
@java.lang.Override
public int getPlatformWaitTimes() {
return platformWaitTimes_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
@ -263,6 +288,9 @@ public final class GuardConfigProto {
if (trainAtpCutTimes_ != 0) {
output.writeInt32(7, trainAtpCutTimes_);
}
if (platformWaitTimes_ != 0) {
output.writeInt32(8, platformWaitTimes_);
}
getUnknownFields().writeTo(output);
}
@ -300,6 +328,10 @@ public final class GuardConfigProto {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(7, trainAtpCutTimes_);
}
if (platformWaitTimes_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(8, platformWaitTimes_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
return size;
@ -329,6 +361,8 @@ public final class GuardConfigProto {
!= other.getCanNotCloseTimes()) return false;
if (getTrainAtpCutTimes()
!= other.getTrainAtpCutTimes()) return false;
if (getPlatformWaitTimes()
!= other.getPlatformWaitTimes()) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@ -354,6 +388,8 @@ public final class GuardConfigProto {
hash = (53 * hash) + getCanNotCloseTimes();
hash = (37 * hash) + TRAINATPCUTTIMES_FIELD_NUMBER;
hash = (53 * hash) + getTrainAtpCutTimes();
hash = (37 * hash) + PLATFORMWAITTIMES_FIELD_NUMBER;
hash = (53 * hash) + getPlatformWaitTimes();
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@ -492,6 +528,7 @@ public final class GuardConfigProto {
canNotOpenTimes_ = 0;
canNotCloseTimes_ = 0;
trainAtpCutTimes_ = 0;
platformWaitTimes_ = 0;
return this;
}
@ -546,6 +583,9 @@ public final class GuardConfigProto {
if (((from_bitField0_ & 0x00000040) != 0)) {
result.trainAtpCutTimes_ = trainAtpCutTimes_;
}
if (((from_bitField0_ & 0x00000080) != 0)) {
result.platformWaitTimes_ = platformWaitTimes_;
}
}
@java.lang.Override
@ -581,6 +621,9 @@ public final class GuardConfigProto {
if (other.getTrainAtpCutTimes() != 0) {
setTrainAtpCutTimes(other.getTrainAtpCutTimes());
}
if (other.getPlatformWaitTimes() != 0) {
setPlatformWaitTimes(other.getPlatformWaitTimes());
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
return this;
@ -642,6 +685,11 @@ public final class GuardConfigProto {
bitField0_ |= 0x00000040;
break;
} // case 56
case 64: {
platformWaitTimes_ = input.readInt32();
bitField0_ |= 0x00000080;
break;
} // case 64
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
@ -966,6 +1014,50 @@ public final class GuardConfigProto {
onChanged();
return this;
}
private int platformWaitTimes_ ;
/**
* <pre>
*乘客等待时间
* </pre>
*
* <code>int32 platformWaitTimes = 8;</code>
* @return The platformWaitTimes.
*/
@java.lang.Override
public int getPlatformWaitTimes() {
return platformWaitTimes_;
}
/**
* <pre>
*乘客等待时间
* </pre>
*
* <code>int32 platformWaitTimes = 8;</code>
* @param value The platformWaitTimes to set.
* @return This builder for chaining.
*/
public Builder setPlatformWaitTimes(int value) {
platformWaitTimes_ = value;
bitField0_ |= 0x00000080;
onChanged();
return this;
}
/**
* <pre>
*乘客等待时间
* </pre>
*
* <code>int32 platformWaitTimes = 8;</code>
* @return This builder for chaining.
*/
public Builder clearPlatformWaitTimes() {
bitField0_ = (bitField0_ & ~0x00000080);
platformWaitTimes_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
@ -1044,14 +1136,14 @@ public final class GuardConfigProto {
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\021guardConfig.proto\022\005alert\"\302\001\n\013GuardConf" +
"\n\021guardConfig.proto\022\005alert\"\335\001\n\013GuardConf" +
"ig\022\027\n\017switchLostTimes\030\001 \001(\005\022\032\n\022switchLos" +
"tMostNums\030\002 \001(\005\022\026\n\016redLedMostNums\030\003 \001(\005\022" +
"\031\n\021orangeLedMostNums\030\004 \001(\005\022\027\n\017canNotOpen" +
"Times\030\005 \001(\005\022\030\n\020canNotCloseTimes\030\006 \001(\005\022\030\n" +
"\020trainAtpCutTimes\030\007 \001(\005B5\n!club.joylink." +
"xiannccda.dto.protosB\020GuardConfigProtob\006" +
"proto3"
"\020trainAtpCutTimes\030\007 \001(\005\022\031\n\021platformWaitT" +
"imes\030\010 \001(\005B5\n!club.joylink.xiannccda.dto" +
".protosB\020GuardConfigProtob\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
@ -1062,7 +1154,7 @@ public final class GuardConfigProto {
internal_static_alert_GuardConfig_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_alert_GuardConfig_descriptor,
new java.lang.String[] { "SwitchLostTimes", "SwitchLostMostNums", "RedLedMostNums", "OrangeLedMostNums", "CanNotOpenTimes", "CanNotCloseTimes", "TrainAtpCutTimes", });
new java.lang.String[] { "SwitchLostTimes", "SwitchLostMostNums", "RedLedMostNums", "OrangeLedMostNums", "CanNotOpenTimes", "CanNotCloseTimes", "TrainAtpCutTimes", "PlatformWaitTimes", });
}
// @@protoc_insertion_point(outer_class_scope)

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,16 @@
package club.joylink.xiannccda.mapper;
import club.joylink.xiannccda.entity.MockAtsCollectorData;
import club.joylink.xiannccda.entity.PublishedGi;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>
* Mapper 接口
* Mapper 接口
* </p>
*
* @author walker-sheng
@ -15,4 +19,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MockAtsCollectorDataMapper extends BaseMapper<MockAtsCollectorData> {
List<MockAtsCollectorData> selectAll(@Param("ew") QueryWrapper<MockAtsCollectorData> qw);
}

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.xiannccda.mapper.MockAtsCollectorDataMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.MockAtsCollectorData">
<id column="id" property="id" />
<result column="line_id" property="lineId" />
<result column="source_date" property="sourceDate" />
<result column="create_time" property="createTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, line_id, source_date, create_time
</sql>
</mapper>

View File

@ -15,10 +15,16 @@ import java.util.Objects;
public class MockAppContext {
public static void publishCollectorAtsData(DecodeMessageData nessageData) {
MessageData findMsg = nessageData.getMessages().stream().filter(d -> !(d instanceof HeartBeatMsg)).findFirst().orElseGet(null);
if (Objects.nonNull(findMsg) && findMsg instanceof MessageResponse mr) {
SystemContext.publishEvent(new MockCollectorMessageDataEvent(nessageData.getSourceData(), mr.getLineId().intValue(), nessageData.getId()));
try {
MessageData findMsg = nessageData.getMessages().stream().filter(d -> !(d instanceof HeartBeatMsg)).findFirst().orElse(null);
if (Objects.nonNull(findMsg) && findMsg instanceof MessageResponse mr) {
SystemContext.publishEvent(new MockCollectorMessageDataEvent(nessageData.getSourceData(), mr.getLineId().intValue(), nessageData.getId()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void publish(List<MessageData> datas) {

View File

@ -183,7 +183,7 @@ public class MockDeviceController {
, @RequestParam(value = "fromId", defaultValue = "0") Long fromId
) {
this.mockDataService.reset(pageSize, fromId);
// this.mockDataService.reset(pageSize, fromId);
DeviceDataRepository.clearAll(lineId);
DeviceStatusDataRepository.clearAll(lineId);
}

View File

@ -1,12 +1,28 @@
package club.joylink.xiannccda.mock.message;
import static club.joylink.xiannccda.ats.message.FrameSchema.Flag_Multi;
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.MessageResponse;
import club.joylink.xiannccda.ats.message.changer.DeviceNameChangerManage;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertorManager;
import club.joylink.xiannccda.dto.mock.MockRequestDTO;
import club.joylink.xiannccda.entity.MockAtsCollectorData;
import club.joylink.xiannccda.exception.BusinessException;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.repository.impl.MockAtsCollectorDataRepository;
import club.joylink.xiannccda.service.AlertMockService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import jakarta.xml.bind.SchemaOutputResolver;
import java.io.BufferedReader;
import java.io.FileReader;
@ -14,62 +30,156 @@ import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@ConditionalOnProperty(name = "load-mock-history-data", havingValue = "true")
//@ConditionalOnProperty(name = "load-mock-history-data", havingValue = "true")
@Component
@Order(1)
@RequiredArgsConstructor
@Order(50)
@Slf4j
public class MockLoadData implements ApplicationRunner {
static final ScheduledExecutorService CIRCLE_QUERY_THREAD = Executors.newSingleThreadScheduledExecutor();
private final NccMockDataService nccMockDataService;
@Value("${load-mock-history-data:false}")
private boolean loadHistoryData;
public void close() {
CIRCLE_QUERY_THREAD.shutdownNow();
static final ScheduledExecutorService CIRCLE_QUERY_THREAD = Executors.newSingleThreadScheduledExecutor();
private final MockAtsCollectorDataRepository atsCollectorDataRep;
private final AlertMockService alertMockService;
private final static RunState RUN_STATE = new RunState();
private final static short page_size = 15;
public MockLoadData(MockAtsCollectorDataRepository atsCollectorDataRep, AlertMockService alertMockService) {
this.atsCollectorDataRep = atsCollectorDataRep;
this.alertMockService = alertMockService;
}
@Override
public void run(ApplicationArguments args) throws Exception {
this.nccMockDataService.reset(10);
AtomicInteger ai = new AtomicInteger(0);
CIRCLE_QUERY_THREAD.scheduleWithFixedDelay(() -> {
// this.nccMockDataService.skip(170L, 1100L, 1180L);
// if (ai.incrementAndGet() > 1) {
// return;
// }
loadData();
}, 500, 500, TimeUnit.MILLISECONDS);
if (loadHistoryData) {
CIRCLE_QUERY_THREAD.scheduleWithFixedDelay(() -> {
this.createQueryWrapper();
loadData();
}, 300, 300, TimeUnit.MILLISECONDS);
}
}
private void loadData(MockRequestDTO dto) {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(this.loadHistoryData, "已经启动了加载历史,不能再手动启动");
}
private void createQueryWrapper() {
QueryWrapper<MockAtsCollectorData> qw = Wrappers.query();
qw.lambda().orderByAsc(MockAtsCollectorData::getId);
RUN_STATE.setCurrentQuery(qw);
}
private void loadData() {
try {
Wrapper<NccMockData> wrapper = Wrappers.<NccMockData>lambdaQuery()
// .eq(NccMockData::getMsgId, MessageId.INUSED_SCHEDULE.name())
// .eq(NccMockData::getId, 1658)
// .in(NccMockData::getMsgId, List.of("DEVICE_STATUS_BITMAP", "TRAIN_INDICATION_INIT", "TRAIN_INDICATION_UPDATE", "TRAIN_INDICATION_REMOVE"))
// .eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP")
// .gt(NccMockData::getMockReceiveTime, "2023-08-06 23:20:20")
// .gt(NccMockData::getId, 2598023)
// .gt(NccMockData::getId, 2933958)
// .ne(NccMockData::getIsDelete, 1)
.orderBy(true, true, NccMockData::getId);
List<MessageResponse> dataList = this.nccMockDataService.loadALLData(wrapper);
DeviceStatusConvertorManager.doConvertor(NameChangerEnum.UNIVERSAL, dataList.stream().map(d -> (MessageData) d).collect(Collectors.toList()));
RUN_STATE.getCurrentQuery().gt("id", RUN_STATE.getLatestId());
RUN_STATE.getCurrentQuery().last(String.format(" limit %d", page_size));
List<MockAtsCollectorData> dataList = this.atsCollectorDataRep.getBaseMapper().selectAll(RUN_STATE.getCurrentQuery());
if (CollectionUtils.isNotEmpty(dataList)) {
RUN_STATE.setLatestId(dataList.get(dataList.size() - 1).getId());
} else {
RUN_STATE.setLatestId(0L);
for (Integer lineId : LineGraphicDataRepository.getAllLines()) {
alertMockService.reset(lineId);
}
}
for (MockAtsCollectorData cd : dataList) {
List<MessageData> messages = Lists.newArrayList();
ByteBuf in = Unpooled.wrappedBuffer(cd.getSourceDate());
ByteBuf out = Unpooled.buffer();
if (schemaParse(in, out)) {
messageDecode(out, messages);
for (MessageData message : messages) {
if (message instanceof MessageResponse res) {
Integer lineId = res.getLineId().intValue();
NameChangerEnum nc = DeviceNameChangerManage.findNameChanger(lineId);
DeviceStatusConvertorManager.doConvertor(nc, messages);
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
private static void messageDecode(ByteBuf buf, List<MessageData> messages) throws Exception {
int len = buf.getUnsignedShort(0);
byte[] msgData = new byte[len + 2];
buf.readBytes(msgData);
ByteBuf msgBuf = Unpooled.wrappedBuffer(msgData);
int msgId = msgBuf.getUnsignedShort(8);
MessageId messageId = MessageId.of(msgId);
if (messageId.equals(MessageId.UNKNOWN)) {
throw new Exception("未知的消息id");
}
if (messageId.omc == null || messageId.omc.create() == null) {
throw new Exception(
String.format("id=%s的消息没有消息对象创建接口omc或接口返回null", messageId));
}
MessageData message = messageId.omc.create();
message.setMsgId(messageId);
message.decode(msgBuf);
messages.add(message);
if (buf.readableBytes() > 0) {
messageDecode(buf, messages);
}
}
private static boolean schemaParse(ByteBuf inByteBuf, ByteBuf packageData) {
inByteBuf.markReaderIndex();
int totalReadables = inByteBuf.readableBytes();
if (totalReadables < 4) {
// inByteBuf.resetReaderIndex();
return false;
}
short sysId = inByteBuf.readUnsignedByte();
int totalLength = inByteBuf.readUnsignedShort();
short flag = inByteBuf.readUnsignedByte();
int contentLen = totalLength - 1;
int readables = inByteBuf.readableBytes();
if (readables < contentLen) {
inByteBuf.resetReaderIndex();
return false;
}
byte[] bb = new byte[contentLen];
inByteBuf.readBytes(bb);
packageData.writeBytes(bb);
if (flag == Flag_Multi) {
schemaParse(inByteBuf, packageData);
}
return true;
}
@Data
private static class RunState {
AtomicBoolean RUNNING = new AtomicBoolean(false);
QueryWrapper<MockAtsCollectorData> currentQuery;
long latestId;
}
}

View File

@ -5,6 +5,7 @@ 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.MockAtsCollectorDataRepository;
import club.joylink.xiannccda.repository.impl.NccMockDataRepository;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader.Feature;
@ -20,16 +21,18 @@ import java.util.concurrent.atomic.AtomicLong;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@Component
//@Component
@RequiredArgsConstructor
@Slf4j
public class NccMockDataService {
private final NccMockDataRepository nccMockDataRepository;
@Autowired
private final MockAtsCollectorDataRepository atsCollectorDataRep;
private static Long LAST_ID;
@ -37,148 +40,5 @@ public class NccMockDataService {
private static int PAGE_SIZE = 200;
public void reset() {
LAST_ID = 0L;
FINISH = false;
}
public void reset(int pageSize) {
this.reset();
PAGE_SIZE = pageSize;
}
public void skip(Long gtStart, Long ltEnd, Long to) {
if (LAST_ID > gtStart && LAST_ID < ltEnd) {
LAST_ID = to;
}
}
public void reset(int pageSize, Long fromId) {
this.reset(pageSize);
LAST_ID = fromId;
}
public boolean finish() {
return FINISH;
}
private boolean isLast() {
if (Objects.isNull(LAST_ID) || LAST_ID <= 0L) {
LAST_ID = 0L;
FINISH = false;
return false;
} else {
return FINISH;
}
}
public List<MessageResponse> loadALLData(Wrapper<NccMockData> wrapp) {
if (wrapp instanceof LambdaQueryWrapper<NccMockData> lam) {
lam.last(String.format(" limit %s", PAGE_SIZE));
lam.gt(NccMockData::getId, LAST_ID);
}
List<NccMockData> nccMockData = this.nccMockDataRepository.list(wrapp);
List<MessageData> list = this.parse(nccMockData);
if (CollectionUtils.isEmpty(nccMockData)) {
FINISH = true;
log.info("已经没有mock的相关数据。。。。。。。。。。。");
return Collections.emptyList();
} else {
LAST_ID = nccMockData.get(nccMockData.size() - 1).getId();
return list.stream().map(d -> (MessageResponse) d).toList();
}
}
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<MessageResponse> getMessageData(DataType dataType) {
if (this.isLast()) {
return Collections.emptyList();
}
List<NccMockData> list = this.findData(dataType);
if (CollectionUtils.isEmpty(list)) {
FINISH = true;
} else {
NccMockData mockData = list.get(list.size() - 1);
LAST_ID = mockData.getId();
}
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(), Feature.Base64StringAsByteArray);
// System.out.println(data.getId());
this.parse(jo, dataList);
}
return dataList;
}
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, Feature.Base64StringAsByteArray);
dataList.add(md);
}
private List<NccMockData> findData(DataType dataType) {
QueryWrapper<NccMockData> queryWrapper = Wrappers.query();
queryWrapper.gt(NccMockData.ID, LAST_ID);
queryWrapper.eq(NccMockData.MSG_TYPE, MsgTypeEnum.REAL_TIME.name());
queryWrapper.eq(NccMockData.ACTION_TYPE, ActionTypeEnum.UPDATES.name());
if (!CollectionUtils.isEmpty(dataType.getTypeList())) {
queryWrapper.in(NccMockData.MSG_ID, dataType.getTypeList());
}
queryWrapper.last(String.format(" limit %s", PAGE_SIZE));
queryWrapper.orderByAsc(NccMockData.ID);
List<NccMockData> list = this.nccMockDataRepository.list(queryWrapper);
return list;
}
public enum DataType {
DEVICE(List.of("DEVICE_STATUS_CHANGE", "SIGNAL_ROUTE_STATUS")),
TRAIN(
List.of(
// "TRAIN_RECORD",
"TRAIN_INDICATION_UPDATE",
"TRAIN_INDICATION_REMOVE",
"TRAIN_BLOCK_INFO")),
ALL(List.of());
@Getter
List<String> typeList;
DataType(List<String> typeList) {
this.typeList = typeList;
}
}
}

View File

@ -179,7 +179,7 @@ public class MockOccServer {
}
private Integer findDeviceRtuId(Integer lineId, DeviceType dt, String deviceName, AlertType alertType) {
if (alertType == AlertType.AXLE_LED_RED || alertType == AlertType.AXLE_LED_ORANGE || alertType == AlertType.TRAIN_EB_ATP) {
if (alertType == AlertType.AXLE_LED_RED || alertType == AlertType.AXLE_LED_ORANGE || alertType == AlertType.TRAIN_EB_ATP || alertType == AlertType.HOLD_PLATFORM_STAY_TRAIN_MORE) {
MessageOrBuilder t = LineGraphicDataRepository.getDeviceByCodeNotException(lineId, deviceName);
if (t instanceof Turnout) {
@ -191,7 +191,7 @@ public class MockOccServer {
Integer stationId = DeviceStatusDataOperate.findFieldVal(section, "centralizedStationId", Integer.class);
return this.findRtuStation(lineId, stationId);
}
} else if (alertType == AlertType.TRAIN_RECORD) {
} else if (alertType == AlertType.PLATFORM_WAIT_TRAIN_MAX_RECORD) {
MessageOrBuilder mb = LineGraphicDataRepository.getDeviceByCode(lineId, deviceName);
System.out.println(mb);
Integer stationId = DeviceStatusDataOperate.findFieldVal(mb, "centralizedStationId", Integer.class);

View File

@ -19,6 +19,7 @@ import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO.DeviceNameInfo;
import club.joylink.xiannccda.dto.mock.show.PlatformEBDTO;
import club.joylink.xiannccda.dto.mock.show.SwitchJammedMockDTO;
import club.joylink.xiannccda.dto.mock.show.TrainRecordMockDTO;
import club.joylink.xiannccda.dto.mock.show.TrainUpdateMockDTO;
import club.joylink.xiannccda.dto.mock.test.AlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.OrangeAlertMockDTO;
@ -121,10 +122,22 @@ public class AlertMockService {
for (DeviceNameInfo deviceInfo : mockDTO.getDeviceInfos()) {
deviceInfo.setDeviceType(DeviceType.DEVICE_TYPE_PLATFORM);
}
} else if (alertType == AlertType.TRAIN_RECORD) {
} else if (alertType == AlertType.PLATFORM_WAIT_TRAIN_MAX_RECORD) {
for (DeviceNameInfo deviceInfo : mockDTO.getDeviceInfos()) {
deviceInfo.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
}
} else if (alertType == AlertType.HOLD_PLATFORM_STAY_TRAIN_MORE) {
for (DeviceNameInfo deviceInfo : mockDTO.getDeviceInfos()) {
deviceInfo.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
}
Map<String, List<DeviceNameInfo>> groupDatas = mockDTO.getDeviceInfos().stream().collect(Collectors.groupingBy(DeviceNameInfo::getGroupId));
StringBuilder sb = new StringBuilder();
for (Entry<String, List<DeviceNameInfo>> listEntry : groupDatas.entrySet()) {
if (listEntry.getValue().size() > 1) {
sb.append(String.format("%s有重复的车组", groupDatas.keySet()));
}
}
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(!sb.isEmpty(), sb.toString());
}
mockDTO.setAlertType(alertType);
@ -157,9 +170,12 @@ public class AlertMockService {
case SWITCH_JAMMED -> {
return SwitchJammedMockDTO.class;
}
case TRAIN_RECORD -> {
case PLATFORM_WAIT_TRAIN_MAX_RECORD -> {
return TrainRecordMockDTO.class;
}
case HOLD_PLATFORM_STAY_TRAIN_MORE -> {
return TrainUpdateMockDTO.class;
}
default -> throw new IllegalStateException("Unexpected value: " + alertType);
}
}

View File

@ -175,9 +175,7 @@ public class LineDeviceMessageServer implements IMessageServer {
Platform pf = (Platform) value;
Platform.Builder pfb = pf.toBuilder();
if (this.showTimeCounter(timeHour)) {
if (StringUtils.equals(pf.getId(), "PF02301")) {
System.out.println(pf.getId() + " -" + pfb.getBizWaitTimerGoing() + " " + pf.getBizWaitTimerGoing());
}
if (pf.getBizWaitTimerGoing()) {
pfb.setBizWaitTimeSec(System.currentTimeMillis() / 1000 - pf.getBizWaitStartTimeSec());
}

View File

@ -15,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 {
@ -56,7 +58,25 @@ public class LineNetMessageServer implements IMessageServer {
@Override
public List<TopicMessage> onTick() {
log.info("【线网订阅】发布全量数据");
List<TopicMessage> topicMessages = new ArrayList<>();
WsLineNetMessage message =
commonCollectFunction(
(fieldType) -> {
Map<String, Builder> deviceMap = dataSource.getAllDeviceMap().get(fieldType);
if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态则全部放入
Map<String, Message> messageMap = new HashMap<>(deviceMap.size());
deviceMap.forEach((k, v) -> messageMap.put(k, v.build()));
return messageMap;
}
return Map.of();
});
byte[] bytes = message.toByteArray();
log.info("【线网订阅】全量数据量:" + bytes.length);
topicMessages.add(new TopicMessage(this.getDestinationPattern(), bytes));
return topicMessages;
/* List<TopicMessage> topicMessages = new ArrayList<>();
if (!dataSource.getStatusVOMap().isEmpty()) {
WsLineNetMessage message =
commonCollectFunction(
@ -67,7 +87,7 @@ public class LineNetMessageServer implements IMessageServer {
log.info("【线网订阅】数据状态变化量:" + bytes.length);
topicMessages.add(new TopicMessage(this.getDestinationPattern(), bytes));
}
return topicMessages;
return topicMessages;*/
}
/**

View File

@ -46,11 +46,11 @@ public class SystemInfoStateMessageServer implements IMessageServer {
int nowHour = LocalDateTime.now().getHour();
for (Builder msg : msgs) {
//先手动设置后续更改
if (showTimeCounter(nowHour)) {
/* if (showTimeCounter(nowHour)) {
msg.setAtsWarnShowCounter(true);
} else {
msg.setAtsWarnShowCounter(false);
}
}*/
lineMsg.addMsgs(msg.build());
}

View File

@ -18,26 +18,27 @@ logging:
occ-client:
clientInfoMap:
3:
server-host: 127.0.0.1
real-port: 2603
nameChanger: UNIVERSAL
server-host: 10.255.11.15
real-port: 5603
un-real-port: 5703
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
connectionOcc: false
filterRtuIds:
- 81
- 82
nameChanger: UNIVERSAL
lineTypes:
- OCC
- NCC
4:
nameChanger: LINE_4
server-host: 127.0.0.1
real-port: 2603
server-host: 10.254.12.45
real-port: 3604
un-real-port: 3704
collector-data: false
collector-data: true
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
@ -47,7 +48,6 @@ occ-client:
lineTypes:
- OCC
- NCC
#故障测试
mock-alert-test: false
#加载历史模拟数据

View File

@ -19,7 +19,6 @@ occ-client:
server-host: 127.0.0.1
real-port: 2603
un-real-port: 5703
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
@ -32,8 +31,8 @@ occ-client:
- NCC
4:
nameChanger: NONE
server-host: 10.254.12.45
real-port: 3604
server-host: 127.0.0.1
real-port: 2603
un-real-port: 3704
collector-data: true
monitor-handware-change: false
@ -47,7 +46,6 @@ occ-client:
- NCC
#故障测试
mock-alert-test: true
#加载历史模拟数据
load-mock-history-data: false
load-mock-history-data: true
#延时加载告警处理
loadAlertTaskDelayMin: 0

View File

@ -9,7 +9,7 @@ logging:
level:
root: info
club.joylink.xiannccda.ats: info
club.joylink.xiannccda.mapper: debug
club.joylink.xiannccda.mapper: info
com.zaxxer.hikari: info
file:
path: /usr/xianncc
@ -21,7 +21,7 @@ occ-client:
server-host: 127.0.0.1
real-port: 2603
un-real-port: 5703
collector-data: true
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
@ -32,12 +32,16 @@ occ-client:
lineTypes:
- OCC
- NCC
4:
nameChanger: LINE_4
server-host: 10.254.12.45
real-port: 3604
server-host: 127.0.0.1
real-port: 2603
# server-host: 10.254.12.45
# real-port: 3604
un-real-port: 3704
collector-data: true
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
@ -47,8 +51,6 @@ occ-client:
lineTypes:
- OCC
- NCC
mock-alert-test: true
load-mock-history-data: false
#延时加载告警处理
mock-alert-test: true
loadAlertTaskDelayMin: 0

View File

@ -0,0 +1,56 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: root
logging:
level:
root: info
club.joylink.xiannccda.ats: info
club.joylink.xiannccda.mapper: debug
com.zaxxer.hikari: debug
file:
path: /usr/xianncc
max-size: 40MB
occ-client:
clientInfoMap:
3:
server-host: 10.254.5.21
real-port: 4603
un-real-port: 4703
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
filterRtuIds:
- 81
- 82
nameChanger: UNIVERSAL
lineTypes:
- OCC
- NCC
4:
nameChanger: LINE_4
server-host: 10.254.5.21
real-port: 4604
un-real-port: 4704
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
filterRtuIds:
- 10
- 11
lineTypes:
- OCC
- NCC
mock-alert-test: true
load-mock-history-data: false
#延时加载告警处理
loadAlertTaskDelayMin: 0

View File

@ -32,7 +32,7 @@ occ-client:
collector-data: false
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
connectionOcc: false
filterRtuIds:
- 81
- 82

View File

@ -41,7 +41,7 @@ occ-client:
collector-data: true
monitor-handware-change: false
receiveMsgTimeout: 6
connectionOcc: true
connectionOcc: false
filterRtuIds:
- 10
- 11

View File

@ -3,7 +3,8 @@ server:
shutdown: "graceful"
spring:
profiles:
active: local
# active: local
active: master-local
banner:
location: classpath:banner.txt
datasource:
@ -33,6 +34,7 @@ spring-doc:
enabled: true
path: /api-docs
mybatis-plus:
# 映射文件的位置
mapper-locations: classpath:mybatis/mapper/*.xml
configuration:
@ -47,28 +49,10 @@ jwt:
key:
pub: classpath:app.pub
prv: classpath:app.key
occ-not-handle:
lineId: 3
#过滤OCC 数据中的rtu
filterRtuIds:
- 81
- 82
#长时间没有接收occ数据超时重新获取基础数据时间小时
receive-msg-timeout: 1
#检测硬件变化(cpu,内存)
monitor-handware-change: true
password-sult: "4a6d74126bfd06d69406fcccb7e7d5d9"
#management:
# endpoints:
# web:
# exposure:
# include: '*'
# server:
# port: 9081
# endpoint:
# shutdown:
# enabled: true
# health:
# show-details: always

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.xiannccda.mapper.EventLogMapper">
<select id="detailPage" resultType="club.joylink.xiannccda.dto.event.EventLogPageDTO">
select A.id,
select A.id,A.line_id,
A.face_name,
A.event_type,
A.sub_event_type,

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.xiannccda.mapper.MockAtsCollectorDataMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.MockAtsCollectorData">
<id column="id" property="id"/>
<result column="line_id" property="lineId"/>
<result column="source_date" property="sourceDate"/>
<result column="create_time" property="createTime"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id
, line_id, source_date, create_time
</sql>
<select id="selectAll" resultMap="BaseResultMap">
select *
from mock_ats_collector_data
where 1 = 1
<if test="ew.sqlSegment !=null and ew.sqlSegment !=''">
and ${ew.sqlSegment}
</if>
</select>
</mapper>

View File

@ -106,7 +106,9 @@ public class DeviceStatusCheckTest {
public void switchJammed() {
for (int i = 0; i < 999999999; i++) {
Switch.Builder p1 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, i);
if (p1.getIpSingleSwitchStusJammed()) {
boolean ledRed = p1.getIpSingleSwitchStusCiOccupied();//&& !p1.getIpSingleSwitchStusCbtcOccupied();
boolean orange = p1.getIpSingleSwitchStusAtcInvalid();
if (p1.getIpSingleSwitchStusJammed() && (ledRed || orange)) {
System.out.println(i);
}
}

View File

@ -124,25 +124,4 @@ public class DeviceStatusTest {
}
@Autowired
private NccMockDataService dataService;
@Test
public void findDeviceTypeEnum() throws Exception {
Wrapper<NccMockData> wrapper = Wrappers.<NccMockData>lambdaQuery().eq(NccMockData::getMsgId, MessageId.DEVICE_STATUS_BITMAP);
/*.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name());*/
this.dataService.reset(99999999);
List<MessageResponse> messageData = this.dataService.loadALLData(wrapper);
Set<Integer> rtuSet = new HashSet<>();
for (MessageResponse messageDatum : messageData) {
List<? extends GeneratedMessageV3.Builder> msgs = messageDatum.generateProto(NameChangerEnum.UNIVERSAL);
for (Builder msg : msgs) {
Integer rtuId = DeviceStatusDataOperate.findFieldVal(msg, "rtuId", Integer.class);
rtuSet.add(rtuId);
}
}
System.out.println(rtuSet);
}
}

View File

@ -195,21 +195,5 @@ public class TrainDataTest {
}
@Autowired
private NccMockDataService dataService;
@Test
public void findDeviceTypeEnum() throws Exception {
Wrapper<NccMockData> wrapper = Wrappers.<NccMockData>lambdaQuery()
.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name());
List<MessageResponse> messageData = this.dataService.loadALLData(wrapper);
for (MessageResponse messageDatum : messageData) {
List<? extends GeneratedMessageV3.Builder> msgs = messageDatum.generateProto(NameChangerEnum.UNIVERSAL);
System.out.println(messageDatum);
System.out.println(messageDatum.generateProto(NameChangerEnum.UNIVERSAL));
}
}
}

View File

@ -5,13 +5,32 @@ import club.joylink.xiannccda.ats.message.FrameSchemaParse;
import club.joylink.xiannccda.ats.message.FrameSchemaParse.DecodeResult;
import club.joylink.xiannccda.ats.message.MessageData;
import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.changer.NameChangerEnum;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertorManager;
import club.joylink.xiannccda.ats.message.collect.convertor.PlanScheduleConvertor;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse.DeviceEntity;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse.DeviceTypeEntity;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusChangeResponse;
import club.joylink.xiannccda.ats.message.line3.rep.HistoryScheduleResponse;
import club.joylink.xiannccda.ats.message.line3.rep.InusedScheduleResponse;
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse;
import club.joylink.xiannccda.ats.message.line3.rep.TrainRecordResponse;
import club.joylink.xiannccda.entity.MockAtsCollectorData;
import club.joylink.xiannccda.repository.IMockAtsCollectorDataRepository;
import com.google.common.collect.Maps;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@ -22,6 +41,160 @@ public class AtsCollectorDataTest {
@Resource
private IMockAtsCollectorDataRepository mockAtsCollectorDataRepository;
@Test
public void loadHistoryTest() throws Exception {
Map<Short, Set<String>> resultMap = Maps.newHashMap();
List<MockAtsCollectorData> collDataList = this.mockAtsCollectorDataRepository.lambdaQuery().eq(MockAtsCollectorData::getLineId, 4).list();
for (MockAtsCollectorData cd : collDataList) {
ByteBuf in = Unpooled.wrappedBuffer(cd.getSourceDate());
ByteBuf out = Unpooled.buffer();
if (schemaParse(in, out)) {
List<MessageData> messages = new ArrayList<MessageData>();
messageDecode(out, messages);
List<DeviceStatusBitmapResponse> bitMapList = messages.stream().filter(d -> d instanceof DeviceStatusBitmapResponse).map(d -> (DeviceStatusBitmapResponse) d).toList();
for (DeviceStatusBitmapResponse bitmap : bitMapList) {
List<DeviceTypeEntity> pfList = bitmap.getEntityList().stream().filter(d -> d.getType() == DeviceType.DEVICE_TYPE_TRACK).toList();
Set<String> names = resultMap.computeIfAbsent(bitmap.getRtuId(), d -> new HashSet<>());
for (DeviceTypeEntity entity : pfList) {
for (DeviceEntity de : entity.getDeviceList()) {
names.add(de.getDevName());
}
}
}
}
}
resultMap.forEach((k, v) -> {
System.out.println("rtuId:" + k);
System.out.println(v.stream().sorted().filter(d -> StringUtils.startsWith(d, "G")).toList());
System.out.println(v.stream().sorted().filter(d -> StringUtils.startsWith(d, "DG")).toList());
});
}
@Test
public void loadPlanTest4() throws Exception {
Map<Short, Map<String, Set<String>>> resultMap = Maps.newHashMap();
List<MockAtsCollectorData> collDataList = this.mockAtsCollectorDataRepository.lambdaQuery().eq(MockAtsCollectorData::getLineId, 4).list();
for (MockAtsCollectorData cd : collDataList) {
ByteBuf in = Unpooled.wrappedBuffer(cd.getSourceDate());
ByteBuf out = Unpooled.buffer();
if (schemaParse(in, out)) {
List<MessageData> messages = new ArrayList<MessageData>();
messageDecode(out, messages);
List<MessageData> bitMapList = messages.stream()
.filter(d -> (d instanceof TrainRecordResponse))
.toList();
for (MessageData messageData : bitMapList) {
if (messageData instanceof TrainRecordResponse cr) {
System.out.println(cr);
}
}
}
}
resultMap.forEach((k, v) -> {
System.out.println("rtuId:" + k);
v.forEach((t, l) -> {
System.out.println("type:" + t);
if (StringUtils.equals(t, DeviceType.DEVICE_TYPE_TRACK.name())) {
System.out.println(l.stream().sorted().filter(d -> StringUtils.startsWith(d, "G")).toList());
System.out.println(l.stream().sorted().filter(d -> StringUtils.startsWith(d, "DG")).toList());
} else {
System.out.println(l.stream().sorted().toList());
}
System.out.println("---------------------------------");
});
});
}
@Test
public void loadHistoryTest3() throws Exception {
Map<Short, Map<String, Set<String>>> resultMap = Maps.newHashMap();
List<MockAtsCollectorData> collDataList = this.mockAtsCollectorDataRepository.lambdaQuery().eq(MockAtsCollectorData::getLineId, 4).list();
for (MockAtsCollectorData cd : collDataList) {
ByteBuf in = Unpooled.wrappedBuffer(cd.getSourceDate());
ByteBuf out = Unpooled.buffer();
if (schemaParse(in, out)) {
List<MessageData> messages = new ArrayList<MessageData>();
messageDecode(out, messages);
List<MessageData> bitMapList = messages.stream()
.filter(d -> (d instanceof TrainIndicationUpdateResponse))
.toList();
for (MessageData messageData : bitMapList) {
if (messageData instanceof DeviceStatusChangeResponse cr) {
// Map<String, MessageData> d = resultMap.computeIfAbsent(cr.getType(), d -> new HashMap<>());
} else if (messageData instanceof TrainIndicationUpdateResponse t) {
if (StringUtils.startsWith(t.getDevName(), "DG")) {
System.out.println("aaaaaaaaaaaaaaa");
}
DeviceStatusConvertorManager.doConvertor(NameChangerEnum.LINE_4, List.of(messageData));
Map<String, Set<String>> chMap = resultMap.computeIfAbsent(t.getRtuId(), d -> new HashMap<>());
Set<String> sets = chMap.computeIfAbsent(t.getDevType().name(), d -> new HashSet<>());
sets.add(t.getDevName());
}
}
}
}
resultMap.forEach((k, v) -> {
System.out.println("rtuId:" + k);
v.forEach((t, l) -> {
System.out.println("type:" + t);
if (StringUtils.equals(t, DeviceType.DEVICE_TYPE_TRACK.name())) {
System.out.println(l.stream().sorted().filter(d -> StringUtils.startsWith(d, "G")).toList());
System.out.println(l.stream().sorted().filter(d -> StringUtils.startsWith(d, "DG")).toList());
} else {
System.out.println(l.stream().sorted().toList());
}
System.out.println("---------------------------------");
});
});
}
@Test
public void loadHistoryTest2() throws Exception {
Map<Short, Map<String, Set<String>>> resultMap = Maps.newHashMap();
List<MockAtsCollectorData> collDataList = this.mockAtsCollectorDataRepository.lambdaQuery().eq(MockAtsCollectorData::getLineId, 4).list();
for (MockAtsCollectorData cd : collDataList) {
ByteBuf in = Unpooled.wrappedBuffer(cd.getSourceDate());
ByteBuf out = Unpooled.buffer();
if (schemaParse(in, out)) {
List<MessageData> messages = new ArrayList<MessageData>();
messageDecode(out, messages);
List<DeviceStatusChangeResponse> bitMapList = messages.stream().filter(d -> d instanceof DeviceStatusChangeResponse).map(d -> (DeviceStatusChangeResponse) d).toList();
List<DeviceStatusChangeResponse> ch = bitMapList.stream().filter(d -> d.getType() == DeviceType.DEVICE_TYPE_TRACK || d.getType() == DeviceType.DEVICE_TYPE_SWITCH).collect(Collectors.toList());
for (DeviceStatusChangeResponse cr : ch) {
Map<String, Set<String>> chMap = resultMap.computeIfAbsent(cr.getRtuId(), d -> new HashMap<>());
Set<String> sets = chMap.computeIfAbsent(cr.getType().name(), d -> new HashSet<>());
sets.add(cr.getDevName());
if (StringUtils.startsWith(cr.getDevName(), "DG")) {
System.out.println("aaaaaaaaaaaaa");
}
}
}
}
resultMap.forEach((k, v) -> {
System.out.println("rtuId:" + k);
v.forEach((t, l) -> {
System.out.println("type:" + t);
if (StringUtils.equals(t, DeviceType.DEVICE_TYPE_TRACK.name())) {
System.out.println(l.stream().sorted().filter(d -> StringUtils.startsWith(d, "G")).toList());
System.out.println(l.stream().sorted().filter(d -> StringUtils.startsWith(d, "DG")).toList());
} else {
System.out.println(l.stream().sorted().toList());
}
System.out.println("---------------------------------");
});
});
}
@Test
public void loadEncodeTest() throws Exception {
List<MockAtsCollectorData> collDataList = this.mockAtsCollectorDataRepository.list();

View File

@ -9,7 +9,6 @@ import club.joylink.xiannccda.ats.message.line3.rep.ActionReportResponse;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse;
import club.joylink.xiannccda.mock.message.MockAppContext;
import club.joylink.xiannccda.mock.message.NccMockDataService;
import club.joylink.xiannccda.mock.message.NccMockDataService.DataType;
import club.joylink.xiannccda.protocal.x.TestUtil;
import club.joylink.xiannccda.repository.INccMockDataRepository;
import com.alibaba.fastjson2.JSON;
@ -105,24 +104,6 @@ public class MockMsgTest {
}
@Autowired
private NccMockDataService dataService;
@Test
public void findMockData() {
List<MessageResponse> dataList = this.dataService.getMessageData(DataType.DEVICE);
System.out.println(dataList);
}
@Test
public void findAll() {
int i = 0;
while (!this.dataService.finish()) {
List<MessageResponse> dataList = this.dataService.getMessageData(DataType.DEVICE);
System.out.println((i++) + "----->" + dataList.size());
}
}
@Test
public void collectTest() throws InterruptedException {
String s = """

View File

@ -1,162 +0,0 @@
package club.joylink.xiannccda.util;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse.DeviceEntity;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse.DeviceTypeEntity;
import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse;
import club.joylink.xiannccda.mock.message.NccMockData;
import club.joylink.xiannccda.mock.message.NccMockDataService;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Table;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class CollectorData {
@Autowired
NccMockDataService nccMockDataService;
@Test
public void collectorTrack() {
Table<DeviceType, String, List<String>> dataTable = this.loadData();
for (DeviceType dt : dataTable.rowKeySet()) {
Map<String, List<String>> mapList = dataTable.row(dt);
if (dt == DeviceType.DEVICE_TYPE_PLATFORM) {
System.out.println("aaaaaaaaaaaaaaaaa");
}
mapList.forEach((k, v) -> {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("d:\\usr\\" + dt.name(), true)))) {
writer.write(String.format("集中站:%s \n", k));
List<String> newList = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (String s : v) {
String[] ssss = s.split("\u0000");
String trackName = ssss[0];
if (StringUtils.startsWith(trackName, "DG")) {
newList.add(ssss[0]);
}
}
writer.write("\t\t" + newList.stream().sorted().collect(Collectors.joining(",")) + "\n");
writer.write("-----------------------------------\n");
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
@Test
public void collector() {
Table<DeviceType, String, List<String>> dataTable = this.loadData();
JSONObject jo = this.readData();
for (DeviceType deviceType : dataTable.rowKeySet()) {
Map<String, List<String>> maps = dataTable.row(deviceType);
File file = new File("d:\\usr\\" + deviceType.name());
if (file.exists()) {
file.delete();
}
maps.forEach((k, v) -> {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)))) {
Map<Boolean, List<String>> findMaper = Device.match(v, deviceType, jo);
writer.write(String.format("集中站:%s \n", k));
for (Boolean aBoolean : findMaper.keySet()) {
writer.write("\t\t" + aBoolean + "\n");
writer.write("\t\t" + JSON.toJSONString(findMaper.get(aBoolean)) + "\n");
}
writer.write("-----------------------------------\n");
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
private Table<DeviceType, String, List<String>> loadData() {
this.nccMockDataService.reset(9999999);
LambdaQueryWrapper<NccMockData> queryWrapper = Wrappers.<NccMockData>lambdaQuery();
queryWrapper.eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP");
Set<String> rtuSets = new HashSet<>();
List<MessageResponse> datas = this.nccMockDataService.loadALLData(queryWrapper);
List<DeviceStatusBitmapResponse> bitmapResponses = datas.stream().map(d -> (DeviceStatusBitmapResponse) d).collect(Collectors.toList());
Table<DeviceType, String, List<String>> dataTable = HashBasedTable.create();
List<String> dd = Lists.newArrayList();
for (DeviceStatusBitmapResponse bitmapRespons : bitmapResponses) {
String rtuId = bitmapRespons.getRtuId().toString();
rtuSets.add(rtuId);
for (DeviceTypeEntity deviceTypeEntity : bitmapRespons.getEntityList()) {
DeviceType dt = deviceTypeEntity.getType();
if (!dd.contains(dt.name())) {
dd.add(dt.name());
}
if (CollectionUtils.isNotEmpty(deviceTypeEntity.getDeviceList())) {
for (DeviceEntity deviceEntity : deviceTypeEntity.getDeviceList()) {
String deviceName = deviceEntity.getDevName();
List<String> deviceList = dataTable.get(dt, rtuId);
if (Objects.isNull(deviceList)) {
deviceList = Lists.newArrayList();
}
if (!deviceList.contains(deviceName)) {
deviceList.add(deviceName);
}
dataTable.put(dt, rtuId, deviceList);
}
}
}
}
System.out.println(rtuSets);
return dataTable;
}
private JSONObject readData() {
try (BufferedReader reader = new BufferedReader(new FileReader("G:\\map.txt"))) {
String content = null;
StringBuilder sb = new StringBuilder();
while ((content = reader.readLine()) != null) {
sb.append(content);
}
return JSON.parseObject(sb.toString());
} catch (Exception e) {
}
return null;
}
}

View File

@ -1,30 +0,0 @@
package club.joylink.xiannccda.util;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse;
import club.joylink.xiannccda.mock.message.NccMockData;
import club.joylink.xiannccda.mock.message.NccMockDataService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class RtuCollectorTest {
@Autowired
NccMockDataService nccMockDataService;
@Test
public void parse() {
LambdaQueryWrapper<NccMockData> queryWrapper = Wrappers.<NccMockData>lambdaQuery();
queryWrapper.eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP");
this.nccMockDataService.reset(999999999, 0L);
List<MessageResponse> datas = this.nccMockDataService.loadALLData(queryWrapper);
List<Short> lists = datas.stream().map(d -> (DeviceStatusBitmapResponse) d).map(d -> d.getRtuId()).distinct().collect(Collectors.toList());
System.out.println(lists);
}
}

View File

@ -3,13 +3,25 @@ package club.joylink.xiannccda.util.impo;
import club.joylink.xiannccda.constants.common.LineTypeEnum;
import club.joylink.xiannccda.entity.AlertTip;
import cn.hutool.core.util.HashUtil;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.util.DigestUtils;
public class TestObj {
@Test
public void strTest() {
String sourceName = "DGasd-1";
int flag = StringUtils.indexOf(sourceName, "-");
if (flag > 0) {
System.out.println(sourceName.substring(0, flag));
}
}
public static AlertTip create(Integer lineId, LineTypeEnum lineType, String type, String msg1, String msg2, Long areaId) {
AlertTip tip = new AlertTip();
tip.setAlertType(type);
@ -36,6 +48,16 @@ public class TestObj {
// 202cb962ac59075b964b07152d234b70
}
@Test
public void nameTest() throws UnsupportedEncodingException {
byte[] tt = new byte[]{89, 78, 83, 76, 95, -49, -62, -48, -48, -43, -66, -52, -88, 0, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52};
byte[] tt2 = new byte[]{89, 78, 83, 76, 95, -49, -62, -48, -48, -43, -66, -52, -88};
byte[] tt3 = new byte[]{71, 49, 52, 51, 51, 0, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52};
System.out.println(new String(tt, "GBK"));
System.out.println(new String(tt2, "GBK"));
System.out.println(new String(tt3, "GBK"));
}
public static String md5(String plainString) {
String cipherString = null;
try {

@ -1 +1 @@
Subproject commit 7aef4b876fae6622d93a21c99fe293df7bf7d572
Subproject commit 96ac7065733315ed902d5a6fd6e847d45a49aa64