蓝显告警逻辑调整

This commit is contained in:
tiger_zhou 2023-12-21 09:19:23 +08:00
parent ece4ccbba1
commit 8a05537555
7 changed files with 328 additions and 173 deletions

View File

@ -33,9 +33,10 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor {
protected void eventHandle(List<Builder> builders) { protected void eventHandle(List<Builder> builders) {
AlertManager alertManager = AlertManager.getDefault(); AlertManager alertManager = AlertManager.getDefault();
for (Builder builder : builders) { for (Builder builder : builders) {
if (builder instanceof Rtu.Builder rtuBuild) { /* if (builder instanceof Rtu.Builder rtuBuild) {
alertManager.emit(new BlueDisplayAlertEvent(rtuBuild)); alertManager.emit(new BlueDisplayAlertEvent(rtuBuild));
} else if (builder instanceof Track.Builder trackBuild) { } else*/
if (builder instanceof Track.Builder trackBuild) {
// alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild)); // alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild));
alertManager.emit(new AxleLedAlertEvent(trackBuild)); alertManager.emit(new AxleLedAlertEvent(trackBuild));

View File

@ -33,9 +33,10 @@ public class DeviceInitConvertor extends DefaultConvertor {
protected void eventHandle(List<Builder> builders) { protected void eventHandle(List<Builder> builders) {
AlertManager alertManager = AlertManager.getDefault(); AlertManager alertManager = AlertManager.getDefault();
for (Builder builder : builders) { for (Builder builder : builders) {
if (builder instanceof Rtu.Builder rtuBuild) { /* if (builder instanceof Rtu.Builder rtuBuild) {
alertManager.emit(new BlueDisplayAlertEvent(rtuBuild)); alertManager.emit(new BlueDisplayAlertEvent(rtuBuild));
} else if (builder instanceof Track.Builder trackBuild) { } else */
if (builder instanceof Track.Builder trackBuild) {
// alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild)); // alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild));
alertManager.emit(new AxleLedAlertEvent(trackBuild)); alertManager.emit(new AxleLedAlertEvent(trackBuild));
} else if (builder instanceof Switch.Builder switchBuild) { } else if (builder instanceof Switch.Builder switchBuild) {

View File

@ -16,7 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component //@Component
@Slf4j @Slf4j
public class AllLineBlueAlertListener implements AlertSourceEventListener<AllLineBlueDisplayAlertEvent> { public class AllLineBlueAlertListener implements AlertSourceEventListener<AllLineBlueDisplayAlertEvent> {

View File

@ -31,7 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component //@Component
@Slf4j @Slf4j
public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAlertEvent> { public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAlertEvent> {

View File

@ -0,0 +1,153 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.alert.NccAlertInfo;
import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.alert.core.AlertManager;
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.datasource.DeviceStatusData;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
import club.joylink.xiannccda.vo.AreaConfigVO;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
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.springframework.stereotype.Component;
@Component
@Slf4j
public class BuleDisplayMonitoringTask implements AlertMonitoringTask {
private final DeviceGuardConfigService configService;
private final AlertInfoService alertInfoService;
public BuleDisplayMonitoringTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
this.configService = configService;
this.alertInfoService = alertInfoService;
}
private final AlertManager alertManager = AlertManager.getDefault();
private final static Map<Integer, List<Station>> CONTROL_STATION_MAPER = new ConcurrentHashMap<>();
@Override
public String getName() {
return "BULE_DISPLAY";
}
private final String ALL_BULE_DISPLAY_NAME = "ALL_BULE_DISPLAY";
private Map<String, GeneratedMessageV3.Builder> findRtuDeviceSource(String lineIdStr) {
DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineIdStr, DataTypeEnum.DEVICE);
if (deviceStatusData.getAllDeviceMap().isEmpty()) {
return null;
}
Map<String, GeneratedMessageV3.Builder> builderMap = deviceStatusData.getAllDeviceMap().get(Rtu.getDescriptor().getName());
if (builderMap.isEmpty()) {
return null;
}
return builderMap;
}
private List<RtuWarnVO> findRtuBuild(Map<String, GeneratedMessageV3.Builder> builderMap) {
List<RtuWarnVO> collectRtuList = Lists.newArrayList();
for (Builder value : builderMap.values()) {
if (value instanceof DeviceStatusProto.Rtu.Builder rtu) {
Station station = findAllStation(rtu.getLineId(), rtu.getId());
Optional<AreaConfigVO> alertInfoMostOptional = this.alertInfoService.findAreaDevice(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(), rtu.getLineId());
collectRtuList.add(new RtuWarnVO(rtu, station, alertInfoMostOptional));
}
}
return collectRtuList;
}
@Override
public void run() {
Set<String> allLineSet = DeviceDataRepository.getAllLines();
for (String lineIdStr : allLineSet) {
Integer lineId = Integer.parseInt(lineIdStr);
Map<String, GeneratedMessageV3.Builder> builderMap = this.findRtuDeviceSource(lineIdStr);
List<RtuWarnVO> collectRtuList = this.findRtuBuild(builderMap);
List<AreaConfigVO> allRtuArea = this.alertInfoService.findDevice2(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, lineId);
Map<Integer, List<RtuWarnVO>> rtuVOMapList = collectRtuList.stream().collect(Collectors.groupingBy(d -> d.rtu.getRtuId()));
if (rtuVOMapList.keySet().size() != allRtuArea.size()) {
for (Entry<Integer, List<RtuWarnVO>> listEntry : rtuVOMapList.entrySet()) {
Optional<RtuWarnVO> rwVO = listEntry.getValue().stream().filter(d -> d.rtu.getIpRtuStusDown()).findAny();
boolean allOnLine = listEntry.getValue().stream().noneMatch(d -> d.rtu.getIpRtuStusDown());
if (rwVO.isPresent()) {
RtuWarnVO rtuVO = rwVO.get();
if (alertManager.putAlterDevice(lineId, this.getName(), String.valueOf(rtuVO.rtu.getRtuId()))) {
String alertInfoMostName = rtuVO.areaConfigVO.map(AreaConfigVO::getAreaName).orElse(String.format("%s 集中站中断连接 ", rtuVO.station.getName()));
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(rtuVO.areaConfigVO, AlertType.BLUE_DISPLAY, rtuVO.rtu, alertInfoMostName, String.valueOf(rtuVO.station.getCommon().getId()),
AlertDeviceType.DEVICE_TYPE_RTU,
false);
alertManager.emit(alertInfo);
}
} else if (allOnLine) {
DeviceStatusProto.Rtu.Builder rtu = listEntry.getValue().get(0).rtu;
alertManager.removeAlterDevice(rtu.getLineId(), this.getName(), String.valueOf(rtu.getRtuId()));
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) {
if (CollectionUtils.isEmpty(CONTROL_STATION_MAPER)) {
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;
Station station;
Optional<AreaConfigVO> areaConfigVO;
public RtuWarnVO(Rtu.Builder rtu, Station station, Optional<AreaConfigVO> areaConfigVO) {
this.rtu = rtu;
this.station = station;
this.areaConfigVO = areaConfigVO;
}
}
}

View File

@ -28,7 +28,7 @@ public class AlertInfoService {
this.deviceAreaConfigService = deviceAreaConfigService; this.deviceAreaConfigService = deviceAreaConfigService;
} }
private List<AreaConfigVO> findDevice2(AlertType alertType, AlertDeviceType dt, int lineId) { public List<AreaConfigVO> findDevice2(AlertType alertType, AlertDeviceType dt, int lineId) {
List<AreaConfigVO> areaConfigList = this.deviceAreaConfigService.getCache(lineId, dt); List<AreaConfigVO> areaConfigList = this.deviceAreaConfigService.getCache(lineId, dt);
if (CollectionUtils.isEmpty(areaConfigList)) { if (CollectionUtils.isEmpty(areaConfigList)) {
return Collections.emptyList(); return Collections.emptyList();

View File

@ -44,7 +44,7 @@ public class DeviceAreaConfigService {
@Autowired @Autowired
private DeviceAreaConfigRepository deviceAreaConfigRepository; private DeviceAreaConfigRepository deviceAreaConfigRepository;
private final static Cache<Integer, Map<AlertDeviceType, List<AreaConfigVO>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(2 * 60, TimeUnit.MINUTES).build(); private final static Cache<Integer, Map<AlertDeviceType, List<AreaConfigVO>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(5 * 60, TimeUnit.MINUTES).build();
public List<AreaConfigVO> getCache(int lineId, AlertDeviceType dt) { public List<AreaConfigVO> getCache(int lineId, AlertDeviceType dt) {
try { try {