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