数据处理过滤不需要的集中站

This commit is contained in:
tiger_zhou 2023-08-29 15:48:57 +08:00
parent 9ad40d520b
commit f7df06b607
10 changed files with 66 additions and 18 deletions

View File

@ -37,12 +37,6 @@ public class OccMessageManage implements ApplicationRunner {
client.send(md, isRealTime);
}
// public void checkWithConnection() {
// Map<Integer, Boolean> lineConnStatus = Maps.newHashMap();
// clientMap.forEach((k, v) -> {
//
// });
// }
public void registerClient(XianOccMessagingClient client) {
clientMap.put(client.lineId, client);

View File

@ -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;

View File

@ -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() {

View File

@ -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<Integer, String> 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<String> rtuList = Splitter.on(",").splitToList(rtuIds);
if (rtuList.contains(rtuId.toString())) {
return false;
}
return true;
}
}

View File

@ -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<MessageData> messageDataList) {
Map<Short, List<MessageResponse>> lineMapper = this.groupByLineId(messageDataList);
lineMapper.forEach((k, v) -> {
List<GeneratedMessageV3.Builder> builders = v.stream().map(MessageResponse::generateProto).flatMap(Collection::stream).collect(Collectors.toList());
List<GeneratedMessageV3.Builder> 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());
});

View File

@ -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<BlueDisplayAl
private static synchronized Station findAllStation(int lineId, String rtuId) {
if (CollectionUtils.isEmpty(CONTROL_STATION_MAPER)) {
Stream<Station> stream = LineGraphicDataRepository.getDevices(lineId, Station.class);
List<Station> stationList = stream.filter(Station::getConcentrationStations).toList();
CONTROL_STATION_MAPER.put(lineId, stationList);
Collection<Station> 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<Station> stationList = CONTROL_STATION_MAPER.get(lineId);
if (CollectionUtils.isEmpty(stationList)) {

View File

@ -32,7 +32,6 @@ public class TrainModeAlertListener implements AlertSourceEventListener<TrainAle
TrainInfo.Builder trainInfo = event.getSource();
TrainMode trainMode = trainInfo.getMode();
if (trainMode.getIpModeTrainAtpCut() && trainMode.getIpModeTrainEbAlarm()) {
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(trainInfo.getLineId(), trainInfo.getDevName());
if (StringUtils.isEmpty(sectionCode)) {
return;

View File

@ -42,3 +42,5 @@ jwt:
key:
pub: classpath:app.pub
prv: classpath:app.key
occ-not-handle-rtu: '{3: "81,82"}'

View File

@ -23,7 +23,7 @@ public class DeviceStatusCheckTest {
@Test
public void RtuTest() {
DeviceStatusProto.Rtu.Builder rtu = DeviceStatusConvertor.convert(DeviceStatus.RTU.class, 1);
DeviceStatusProto.Rtu.Builder rtu2 = DeviceStatusConvertor.convert(DeviceStatus.RTU.class, 2);
DeviceStatusProto.Rtu.Builder rtu2 = DeviceStatusConvertor.convert(DeviceStatus.RTU.class, 32768);
System.out.println(rtu);
System.out.println("--------------------------");
System.out.println(rtu2);

View File

@ -75,15 +75,17 @@ public class CollectorData {
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())) {
@ -104,6 +106,7 @@ public class CollectorData {
}
}
}
System.out.println(rtuSets);
return dataTable;
}