From f7df06b6070b0ba612d6e0c114776a572773db3c Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Tue, 29 Aug 2023 15:48:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E4=B8=8D=E9=9C=80=E8=A6=81=E7=9A=84=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ats/message/OccMessageManage.java | 6 --- .../ats/message/OccTcpClientConnection.java | 5 +-- .../ats/message/XianOccMessagingClient.java | 4 +- .../collect/convertor/ConvertorUtil.java | 39 +++++++++++++++++++ .../collect/convertor/DefaultConvertor.java | 10 ++++- .../xiannccda/ats/warn/BlueAlertListener.java | 10 ++++- .../ats/warn/TrainModeAlertListener.java | 1 - src/main/resources/application.yml | 2 + .../device/DeviceStatusCheckTest.java | 2 +- .../joylink/xiannccda/util/CollectorData.java | 5 ++- 10 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/ConvertorUtil.java diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java index b74cdf2..4da9488 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java @@ -37,12 +37,6 @@ public class OccMessageManage implements ApplicationRunner { client.send(md, isRealTime); } -// public void checkWithConnection() { -// Map lineConnStatus = Maps.newHashMap(); -// clientMap.forEach((k, v) -> { -// -// }); -// } public void registerClient(XianOccMessagingClient client) { clientMap.put(client.lineId, client); diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccTcpClientConnection.java b/src/main/java/club/joylink/xiannccda/ats/message/OccTcpClientConnection.java index 1c189c7..c12bc52 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccTcpClientConnection.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccTcpClientConnection.java @@ -45,11 +45,8 @@ public class OccTcpClientConnection { this.channel.writeAndFlush(List.of(messageData)); } -// @Getter -// private final boolean realConnection; + public OccTcpClientConnection(XianOccMessagingClient client, String host, int port, boolean collectorData) { - public OccTcpClientConnection(XianOccMessagingClient client, String host, int port, boolean collectorData/*, boolean realConnections*/) { -// this.realConnection = realConnections; this.client = client; this.host = host; this.port = port; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java index c944d95..b01f502 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java @@ -39,8 +39,8 @@ public class XianOccMessagingClient { this.lineId = lineId; // 创建实时和非实时消息连接 - this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData/*, true*/); - this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false/*, false*/); + this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData); + this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false); } public ConnectionInfo getRTClientConnectionInfo() { diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/ConvertorUtil.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/ConvertorUtil.java new file mode 100644 index 0000000..ac8bce4 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/ConvertorUtil.java @@ -0,0 +1,39 @@ +package club.joylink.xiannccda.ats.message.collect.convertor; + +import com.google.common.base.Splitter; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class ConvertorUtil { + + @Value("#{${occ-not-handle-rtu}}") +// @Value("${occ-not-handle-rtu}") + private Map mapList; + + /** + * 过滤需要处理的rtu消息 + * + * @param lineId + * @param rtuId + * @return + */ + public boolean notMatchHandle(Integer lineId, Integer rtuId) { + if (Objects.isNull(lineId) || Objects.isNull(rtuId)) { + return true; + } + String rtuIds = mapList.get(lineId); + if (StringUtils.isEmpty(rtuIds)) { + return true; + } + List rtuList = Splitter.on(",").splitToList(rtuIds); + if (rtuList.contains(rtuId.toString())) { + return false; + } + return true; + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DefaultConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DefaultConvertor.java index 82e9e1f..7b897ad 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DefaultConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DefaultConvertor.java @@ -5,6 +5,8 @@ import club.joylink.xiannccda.ats.message.MessageResponse; import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository; import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum; import club.joylink.xiannccda.ats.message.collect.DeviceStatusConvertor; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; +import club.joylink.xiannccda.constants.SystemContext; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.google.protobuf.GeneratedMessageV3; import java.util.Collections; @@ -36,7 +38,13 @@ public abstract class DefaultConvertor extends DeviceStatusConvertor { public void run(List messageDataList) { Map> lineMapper = this.groupByLineId(messageDataList); lineMapper.forEach((k, v) -> { - List builders = v.stream().map(MessageResponse::generateProto).flatMap(Collection::stream).collect(Collectors.toList()); + List builders = v.stream().map(MessageResponse::generateProto) + .flatMap(Collection::stream).filter(d -> { + ConvertorUtil cu = SystemContext.getAppContext().getBean(ConvertorUtil.class); + Integer lineId = DeviceStatusDataOperate.findFieldVal(d, "lineId", Integer.class); + Integer rtuId = DeviceStatusDataOperate.findFieldVal(d, "rtuId", Integer.class); + return cu.notMatchHandle(lineId, rtuId); + }).collect(Collectors.toList()); this.eventHandle(builders); DeviceDataRepository.add(k.toString(), builders, this.dataType()); }); diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java index d396e7a..ef4def7 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java @@ -12,14 +12,19 @@ import club.joylink.xiannccda.entity.DeviceAreaConfig; import club.joylink.xiannccda.service.AlertInfoService; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -86,8 +91,9 @@ public class BlueAlertListener implements AlertSourceEventListener stream = LineGraphicDataRepository.getDevices(lineId, Station.class); - List stationList = stream.filter(Station::getConcentrationStations).toList(); - CONTROL_STATION_MAPER.put(lineId, stationList); + Collection stationList = stream.filter(Station::getConcentrationStations) + .collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (o1, o2) -> o2)).values(); + CONTROL_STATION_MAPER.put(lineId, new ArrayList<>(stationList)); } List stationList = CONTROL_STATION_MAPER.get(lineId); if (CollectionUtils.isEmpty(stationList)) { diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java index 3d4d65d..3513f66 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java @@ -32,7 +32,6 @@ public class TrainModeAlertListener implements AlertSourceEventListener> loadData() { + this.nccMockDataService.reset(9999999); LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP"); - + Set rtuSets = new HashSet<>(); List datas = this.nccMockDataService.loadALLData(queryWrapper); List bitmapResponses = datas.stream().map(d -> (DeviceStatusBitmapResponse) d).collect(Collectors.toList()); Table> dataTable = HashBasedTable.create(); List 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())) { @@ -104,6 +106,7 @@ public class CollectorData { } } } + System.out.println(rtuSets); return dataTable; }