蓝显告警逻辑调整

This commit is contained in:
tiger_zhou 2023-12-22 10:05:09 +08:00
parent 3ac9997460
commit 172d3b977b
6 changed files with 4790 additions and 185 deletions

View File

@ -18,6 +18,7 @@ import org.springframework.stereotype.Component;
//@Component //@Component
@Slf4j @Slf4j
@Deprecated
public class AllLineBlueAlertListener implements AlertSourceEventListener<AllLineBlueDisplayAlertEvent> { public class AllLineBlueAlertListener implements AlertSourceEventListener<AllLineBlueDisplayAlertEvent> {
@Autowired @Autowired

View File

@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
//@Component //@Component
@Slf4j @Slf4j
@Deprecated
public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAlertEvent> { public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAlertEvent> {

View File

@ -11,6 +11,7 @@ import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto; import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.service.AlertInfoService; import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService; import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
@ -19,19 +20,20 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -40,17 +42,15 @@ import org.springframework.stereotype.Component;
@Slf4j @Slf4j
public class BuleDisplayMonitoringTask implements AlertMonitoringTask { public class BuleDisplayMonitoringTask implements AlertMonitoringTask {
private final DeviceGuardConfigService configService;
private final AlertInfoService alertInfoService; private final AlertInfoService alertInfoService;
public BuleDisplayMonitoringTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { public BuleDisplayMonitoringTask(AlertInfoService alertInfoService) {
this.configService = configService;
this.alertInfoService = alertInfoService; this.alertInfoService = alertInfoService;
} }
private final AlertManager alertManager = AlertManager.getDefault(); private final AlertManager alertManager = AlertManager.getDefault();
private final static Map<Integer, List<Station>> CONTROL_STATION_MAPER = new ConcurrentHashMap<>();
@Override @Override
public String getName() { public String getName() {
@ -71,17 +71,17 @@ public class BuleDisplayMonitoringTask implements AlertMonitoringTask {
return builderMap; return builderMap;
} }
private List<RtuWarnVO> findRtuBuild(Map<String, GeneratedMessageV3.Builder> builderMap) { private List<RtuWarnVO> findRtuBuild(Integer lineId, Map<String, GeneratedMessageV3.Builder> builderMap) {
List<RtuWarnVO> collectRtuList = Lists.newArrayList(); List<RtuWarnVO> collectRtuList2 = Lists.newArrayList();
List<AreaConfigVO> allRtuArea = this.alertInfoService.findDevice2(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, lineId);
for (Builder value : builderMap.values()) { for (AreaConfigVO areaConfigVO : allRtuArea) {
if (value instanceof DeviceStatusProto.Rtu.Builder rtu) { for (Integer data : areaConfigVO.getDatas()) {
Station station = findAllStation(rtu.getLineId(), rtu.getId()); LayoutGraphicsProto.Station station = LineGraphicDataRepository.getDeviceByCode(lineId, data.toString(), LayoutGraphicsProto.Station.class);
Optional<AreaConfigVO> alertInfoMostOptional = this.alertInfoService.findAreaDevice(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(), rtu.getLineId()); DeviceStatusProto.Rtu.Builder rtuBuild = (Rtu.Builder) builderMap.get(station.getCode());
collectRtuList.add(new RtuWarnVO(rtu, station, alertInfoMostOptional)); collectRtuList2.add(new RtuWarnVO(rtuBuild, station, areaConfigVO));
} }
} }
return collectRtuList; return collectRtuList2;
} }
@Override @Override
@ -90,66 +90,51 @@ public class BuleDisplayMonitoringTask implements AlertMonitoringTask {
for (String lineIdStr : allLineSet) { for (String lineIdStr : allLineSet) {
Integer lineId = Integer.parseInt(lineIdStr); Integer lineId = Integer.parseInt(lineIdStr);
Map<String, GeneratedMessageV3.Builder> builderMap = this.findRtuDeviceSource(lineIdStr); Map<String, GeneratedMessageV3.Builder> builderMap = this.findRtuDeviceSource(lineIdStr);
List<RtuWarnVO> collectRtuList = this.findRtuBuild(builderMap); List<RtuWarnVO> collectRtuList = this.findRtuBuild(lineId, builderMap);
List<AreaConfigVO> allRtuArea = this.alertInfoService.findDevice2(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, lineId); Map<Long, List<RtuWarnVO>> rtuVOMapList = collectRtuList.stream().collect(Collectors.groupingBy(d -> d.areaConfigVO.getId()));
Map<Integer, List<RtuWarnVO>> rtuVOMapList = collectRtuList.stream().collect(Collectors.groupingBy(d -> d.rtu.getRtuId())); int interLockCount = rtuVOMapList.keySet().size();
if (rtuVOMapList.keySet().size() != allRtuArea.size()) { List<Boolean> allShutdownList = rtuVOMapList.values().stream().map(Collection::stream).map(ls -> ls.anyMatch(r -> Objects.nonNull(r.rtu) && r.rtu.getIpRtuStusDown())).toList();
for (Entry<Integer, List<RtuWarnVO>> listEntry : rtuVOMapList.entrySet()) { if (allShutdownList.size() == interLockCount && allShutdownList.stream().allMatch(d -> d)) {
Optional<RtuWarnVO> rwVO = listEntry.getValue().stream().filter(d -> d.rtu.getIpRtuStusDown()).findAny(); if (alertManager.putAlterDevice(lineId, ALL_BULE_DISPLAY_NAME, "All")) {
boolean allOnLine = listEntry.getValue().stream().noneMatch(d -> d.rtu.getIpRtuStusDown()); NccAlertInfo alertInfo = this.alertInfoService.createAlert2(null, AlertType.BLUE_DISPLAY, lineId, LocalDateTime.now(), "全线蓝线", null,
AlertDeviceType.DEVICE_TYPE_RTU, false);
alertManager.emit(alertInfo);
}
} else {
for (List<RtuWarnVO> rwvVOist : rtuVOMapList.values()) {
Optional<RtuWarnVO> rwVO = rwvVOist.stream().filter(d -> Objects.nonNull(d.rtu) && d.rtu.getIpRtuStusDown()).findAny();
if (rwVO.isPresent()) { if (rwVO.isPresent()) {
RtuWarnVO rtuVO = rwVO.get(); RtuWarnVO rtuVO = rwVO.get();
if (alertManager.putAlterDevice(lineId, this.getName(), String.valueOf(rtuVO.rtu.getRtuId()))) { if (alertManager.putAlterDevice(lineId, this.getName(), rtuVO.areaConfigVO.getAreaName())) {
String alertInfoMostName = rtuVO.areaConfigVO.map(AreaConfigVO::getAreaName).orElse(String.format("%s 集中站中断连接 ", rtuVO.station.getName())); String alertInfoMostName = rtuVO.areaConfigVO.getAreaName();
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(rtuVO.areaConfigVO, AlertType.BLUE_DISPLAY, rtuVO.rtu, alertInfoMostName, String.valueOf(rtuVO.station.getCommon().getId()), NccAlertInfo alertInfo = this.alertInfoService.createAlert2(rtuVO.areaConfigVO.getId(), AlertType.BLUE_DISPLAY, rtuVO.rtu, alertInfoMostName,
AlertDeviceType.DEVICE_TYPE_RTU, rtuVO.station.getCommon().getId(),
false); AlertDeviceType.DEVICE_TYPE_RTU, false);
alertManager.emit(alertInfo); alertManager.emit(alertInfo);
} }
} else if (allOnLine) { } else {
DeviceStatusProto.Rtu.Builder rtu = listEntry.getValue().get(0).rtu; alertManager.removeAlterDevice(lineId, this.getName(), rwvVOist.get(0).areaConfigVO.getAreaName());
alertManager.removeAlterDevice(rtu.getLineId(), this.getName(), String.valueOf(rtu.getRtuId())); alertManager.removeAlterDevice(lineId, ALL_BULE_DISPLAY_NAME, "All");
alertManager.removeAlterDevice(rtu.getLineId(), ALL_BULE_DISPLAY_NAME, "All");
} }
} }
} else if (alertManager.putAlterDevice(lineId, ALL_BULE_DISPLAY_NAME, "All")) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.BLUE_DISPLAY, collectRtuList.get(0).rtu, "全线蓝线", null,
AlertDeviceType.DEVICE_TYPE_RTU,
false);
alertManager.emit(alertInfo);
} }
} }
} }
private static synchronized Station findAllStation(int lineId, String rtuId) { @Getter
if (CollectionUtils.isEmpty(CONTROL_STATION_MAPER)) { public static class RtuWarnVO {
Stream<Station> stream = LineGraphicDataRepository.getDevices(lineId, Station.class);
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)) {
return null;
}
String rtuName = Strings.padStart(rtuId, 2, '0');
Optional<Station> optionalStation = stationList.stream().filter(d -> StringUtils.equalsIgnoreCase(d.getCode(), rtuName)).findAny();
return optionalStation.orElse(null);
}
private static class RtuWarnVO {
DeviceStatusProto.Rtu.Builder rtu; DeviceStatusProto.Rtu.Builder rtu;
Station station; Station station;
Optional<AreaConfigVO> areaConfigVO; AreaConfigVO areaConfigVO;
public RtuWarnVO(Rtu.Builder rtu, Station station, Optional<AreaConfigVO> areaConfigVO) { public RtuWarnVO(Rtu.Builder rtu, Station station, AreaConfigVO areaConfigVO) {
this.rtu = rtu; this.rtu = rtu;
this.station = station; this.station = station;
this.areaConfigVO = areaConfigVO; this.areaConfigVO = areaConfigVO;
} }
} }
} }

View File

@ -1,16 +1,29 @@
package club.joylink.xiannccda.mock.message.occ; package club.joylink.xiannccda.mock.message.occ;
import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.MessageData; import club.joylink.xiannccda.ats.message.MessageData;
import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.OccMessageEncoder; import club.joylink.xiannccda.ats.message.OccMessageEncoder;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
import club.joylink.xiannccda.ats.message.convertor.DeviceStatusConvertor;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType; import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO; import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO.DeviceNameInfo; import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO.DeviceNameInfo;
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.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.mock.message.occ.req.MockDeviceStatusReq; import club.joylink.xiannccda.mock.message.occ.req.MockDeviceStatusReq;
import club.joylink.xiannccda.mock.message.occ.req.MockTrainRecordReq; import club.joylink.xiannccda.mock.message.occ.req.MockTrainRecordReq;
import club.joylink.xiannccda.mock.message.occ.req.MockTrainUpdateReq; import club.joylink.xiannccda.mock.message.occ.req.MockTrainUpdateReq;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.MessageOrBuilder;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@ -24,8 +37,10 @@ import jakarta.annotation.PostConstruct;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import lombok.Data; import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -109,30 +124,66 @@ public class MockOccServer {
private List<MessageData> convertor(NewAlertMockDTO md) { private List<MessageData> convertor(NewAlertMockDTO md) {
MessageId messageId = md.parseMessageId(); MessageId messageId = md.parseMessageId();
short lineId = md.getLineId().shortValue(); short lineId = md.getLineId().shortValue();
short rtuId = md.getRtuId().shortValue();
List<MessageData> list = Lists.newArrayList(); List<MessageData> list = Lists.newArrayList();
if (CollectionUtils.isEmpty(md.getDeviceInfos()) && messageId == MessageId.TRAIN_INDICATION_UPDATE) { if (CollectionUtils.isEmpty(md.getDeviceInfos()) && messageId == MessageId.TRAIN_INDICATION_UPDATE) {
short rtuId = md.getRtuId().shortValue();
MockTrainUpdateReq req = new MockTrainUpdateReq(messageId, lineId, rtuId, DeviceType.DEVICE_TYPE_TRACK, "", md.deviceStatus()); MockTrainUpdateReq req = new MockTrainUpdateReq(messageId, lineId, rtuId, DeviceType.DEVICE_TYPE_TRACK, "", md.deviceStatus());
req.setTime(Instant.ofEpochMilli(System.currentTimeMillis()).getEpochSecond()); req.setTime(Instant.ofEpochMilli(System.currentTimeMillis()).getEpochSecond());
list.add(req); list.add(req);
} }
for (DeviceNameInfo di : md.getDeviceInfos()) { for (DeviceNameInfo di : md.getDeviceInfos()) {
Integer rtuId_ = findDeviceRtuId((int) lineId, di.getDeviceType(), di.getDeviceName(), md.getAlertType());
if (messageId == MessageId.DEVICE_STATUS_CHANGE) { if (messageId == MessageId.DEVICE_STATUS_CHANGE) {
MockDeviceStatusReq mockDeviceStatusReq = new MockDeviceStatusReq(messageId, lineId, rtuId, di.getDeviceType(), di.getDeviceName(), MockDeviceStatusReq mockDeviceStatusReq = new MockDeviceStatusReq(messageId, lineId, rtuId_.shortValue(), di.getDeviceType(), di.getDeviceName(),
md.deviceStatus()); md.deviceStatus());
mockDeviceStatusReq.setTime(Instant.ofEpochMilli(System.currentTimeMillis()).getEpochSecond()); mockDeviceStatusReq.setTime(Instant.ofEpochMilli(System.currentTimeMillis()).getEpochSecond());
list.add(mockDeviceStatusReq); list.add(mockDeviceStatusReq);
} else if (messageId == MessageId.TRAIN_INDICATION_UPDATE) { } else if (messageId == MessageId.TRAIN_INDICATION_UPDATE) {
MockTrainUpdateReq req = new MockTrainUpdateReq(messageId, lineId, rtuId, di.getDeviceType(), di.getDeviceName(), md.deviceStatus()); MockTrainUpdateReq req = new MockTrainUpdateReq(messageId, lineId, rtuId_.shortValue(), di.getDeviceType(), di.getDeviceName(), md.deviceStatus());
req.setTime(Instant.ofEpochMilli(System.currentTimeMillis()).getEpochSecond()); req.setTime(Instant.ofEpochMilli(System.currentTimeMillis()).getEpochSecond());
list.add(req); list.add(req);
} }
} }
return list; return list;
} }
private Integer findDeviceRtuId(Integer lineId, DeviceType dt, String deviceName, AlertType alertType) {
if (alertType == AlertType.AXLE_LED_RED || alertType == AlertType.AXLE_LED_ORANGE) {
String axleSectionCode = LineGraphicDataRepository.findAxleCodeFromLogicCode(lineId, deviceName);
MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, axleSectionCode);
Integer stationId = DeviceStatusDataOperate.findFieldVal(section, "centralizedStationId", Integer.class);
// LayoutGraphicsProto.Station station = LineGraphicDataRepository.getDeviceByCode(lineId, stationId.toString(), LayoutGraphicsProto.Station.class);
// System.out.println(section);
// return Integer.parseInt(station.getCode());
return this.findRtuStation(lineId, stationId);
} else if (alertType == AlertType.BLUE_DISPLAY) {
Optional<LayoutGraphicsProto.Station> stationOptional = LineGraphicDataRepository.getDevices(lineId, LayoutGraphicsProto.Station.class).filter(d -> StringUtils.equals(d.getCode(), deviceName))
.findFirst();
if (stationOptional.isPresent()) {
return this.findRtuStation(lineId, stationOptional.get().getCommon().getId());
}
} else if (alertType == AlertType.SWITCH_LOST) {
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, deviceName);
MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode);
Integer stationId = DeviceStatusDataOperate.findFieldVal(section, "centralizedStationId", Integer.class);
System.out.println(section);
// LayoutGraphicsProto.Station station = LineGraphicDataRepository.getDeviceByCode(lineId, stationId.toString(), LayoutGraphicsProto.Station.class);
// return Integer.parseInt(station.getCode());
return this.findRtuStation(lineId, stationId);
}
return null;
}
private Integer findRtuStation(Integer lineId, Integer rtuIdCode) {
List<LayoutGraphicsProto.Station> centerStationList = LineGraphicDataRepository.getDevices(lineId, LayoutGraphicsProto.Station.class).filter(Station::getConcentrationStations).toList();
Optional<LayoutGraphicsProto.Station> stationOptional = centerStationList.stream().filter(d -> d.getManageStationsList().contains(rtuIdCode)).findFirst();
if (stationOptional.isPresent()) {
LayoutGraphicsProto.Station station = stationOptional.get();
return Integer.parseInt(station.getCode());
}
return null;
}
private MessageData convertor(OccMockData md) { private MessageData convertor(OccMockData md) {
if (md.getMessageId() == MessageId.DEVICE_STATUS_CHANGE) { if (md.getMessageId() == MessageId.DEVICE_STATUS_CHANGE) {
MockDeviceStatusReq mockDeviceStatusReq = new MockDeviceStatusReq(md.getMessageId(), md.getLineId(), md.getRtuId(), md.getDeviceType(), md.getDeviceName(), md.getDeviceStatus()); MockDeviceStatusReq mockDeviceStatusReq = new MockDeviceStatusReq(md.getMessageId(), md.getLineId(), md.getRtuId(), md.getDeviceType(), md.getDeviceName(), md.getDeviceStatus());

View File

@ -5,11 +5,15 @@ import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus;
import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.SWITCH; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.SWITCH;
import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.TRACK; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.TRACK;
import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.TRAIN_MODE; import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.TRAIN_MODE;
import club.joylink.xiannccda.ats.warn.BuleDisplayMonitoringTask.RtuWarnVO;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto; import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo; import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
import club.joylink.xiannccda.vo.AreaConfigVO;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
import com.mysql.cj.x.protobuf.MysqlxDatatypes; import com.mysql.cj.x.protobuf.MysqlxDatatypes;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
@ -17,14 +21,47 @@ import java.io.UnsupportedEncodingException;
import java.sql.SQLOutput; import java.sql.SQLOutput;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class DeviceStatusCheckTest { public class DeviceStatusCheckTest {
@Test
public void allBuleCheckTest() {
List<RtuWarnVO> list = Lists.newArrayList();
DeviceStatusProto.Rtu.Builder rtu1 = Rtu.newBuilder();
rtu1.setIpRtuStusDown(true);
DeviceStatusProto.Rtu.Builder rtu2 = Rtu.newBuilder();
rtu2.setIpRtuStusDown(false);
AreaConfigVO configVO1 = new AreaConfigVO();
configVO1.setId(1L);
AreaConfigVO configVO2 = new AreaConfigVO();
configVO2.setId(2L);
AreaConfigVO configVO3 = new AreaConfigVO();
configVO3.setId(3L);
list.add(new RtuWarnVO(rtu1, null, configVO1));
list.add(new RtuWarnVO(rtu2, null, configVO1));
list.add(new RtuWarnVO(rtu1, null, configVO2));
list.add(new RtuWarnVO(null, null, configVO2));
list.add(new RtuWarnVO(null, null, configVO3));
list.add(new RtuWarnVO(null, null, configVO3));
System.out.println(list);
Map<Long, List<RtuWarnVO>> rtuVOMapList = list.stream().collect(Collectors.groupingBy(d -> d.getAreaConfigVO().getId()));
System.out.println(rtuVOMapList);
List<Boolean> result = rtuVOMapList.values().stream().map(Collection::stream).map(ls -> ls.anyMatch(r -> Objects.nonNull(r.getRtu()) && r.getRtu().getIpRtuStusDown()))
.collect(Collectors.toList());
System.out.println(result);
}
@Test @Test
public void RtuTest() { public void RtuTest() {
DeviceStatusProto.Rtu.Builder rtu = DeviceStatusConvertor.convert(DeviceStatus.RTU.class, 1); DeviceStatusProto.Rtu.Builder rtu = DeviceStatusConvertor.convert(DeviceStatus.RTU.class, 1);