道岔失表调整
This commit is contained in:
parent
a211d2e3c0
commit
2aadd4dab5
@ -17,14 +17,4 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor {
|
||||
return DataTypeEnum.DEVICE;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
protected void eventHandle(List<Builder> builders) {
|
||||
AlertManager alertManager = AlertManager.getDefault();
|
||||
for (Builder builder : builders) {
|
||||
|
||||
if (builder instanceof Switch.Builder switchBuild) {
|
||||
alertManager.emit(new SwitchLostAlertEvent(switchBuild));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -17,15 +17,4 @@ public class DeviceInitConvertor extends DefaultConvertor {
|
||||
return DataTypeEnum.DEVICE;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
protected void eventHandle(List<Builder> builders) {
|
||||
AlertManager alertManager = AlertManager.getDefault();
|
||||
for (Builder builder : builders) {
|
||||
|
||||
if (builder instanceof Switch.Builder switchBuild) {
|
||||
|
||||
alertManager.emit(new SwitchLostAlertEvent(switchBuild));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
package club.joylink.xiannccda.ats.warn.lost;
|
||||
|
||||
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
|
||||
import club.joylink.xiannccda.ats.warn.DeviceAlertEvent;
|
||||
import club.joylink.xiannccda.ats.warn.lost.SwitchLostAlertListener.SwitchLostAlertEvent;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
//@Component
|
||||
@Deprecated
|
||||
public class SwitchLostAlertListener implements AlertSourceEventListener<SwitchLostAlertEvent> {
|
||||
|
||||
@Autowired
|
||||
// private SwitchLostAlertMonitoringTask monitoringTask2;
|
||||
private SwitchLostAlertMonitoringTask2 monitoringTask2;
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(SwitchLostAlertEvent event) {
|
||||
Switch.Builder switchBuild = event.getSource();
|
||||
boolean isLost = switchBuild.getIpSingleSwitchStusLostIndication();
|
||||
if (isLost) {
|
||||
this.monitoringTask2.putSwitchIfNotExist(switchBuild);
|
||||
} else {
|
||||
this.monitoringTask2.removeSwitch(switchBuild);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SwitchLostAlertEvent extends DeviceAlertEvent<Builder> {
|
||||
|
||||
public SwitchLostAlertEvent(Builder source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
package club.joylink.xiannccda.ats.warn.lost;
|
||||
|
||||
import club.joylink.xiannccda.alert.NccAlertInfo;
|
||||
import club.joylink.xiannccda.alert.core.AlertDataSource;
|
||||
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.ats.warn.lost.SwitchLostMostAlertListener.SwitchLostMostEvent;
|
||||
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder;
|
||||
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout;
|
||||
import club.joylink.xiannccda.service.AlertInfoService;
|
||||
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.google.protobuf.GeneratedMessageV3;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
//@Component
|
||||
@Deprecated
|
||||
@Slf4j
|
||||
public class SwitchLostAlertMonitoringTask2 implements AlertMonitoringTask {
|
||||
|
||||
private DeviceGuardConfigService configService;
|
||||
|
||||
private AlertInfoService alertInfoService;
|
||||
|
||||
public SwitchLostAlertMonitoringTask2(DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
|
||||
|
||||
this.configService = configService;
|
||||
this.alertInfoService = alertInfoService;
|
||||
}
|
||||
|
||||
|
||||
private final AlertManager alertManager = AlertManager.getDefault();
|
||||
private final AlertDataSource alertDataSource = AlertDataSource.getInstance();
|
||||
|
||||
private final Map<String, Integer> deviceCodeMap = new ConcurrentHashMap<>();
|
||||
|
||||
public void putSwitchIfNotExist(Builder switchBuilder) {
|
||||
if (!this.deviceCodeMap.containsKey(switchBuilder.getId())) {
|
||||
log.info("线路[{}] 道岔[{}] 添加到道岔失表监控中... 设备状态参数[{}]", switchBuilder.getLineId(), switchBuilder.getId(), switchBuilder.getIpSingleSwitchStusLostIndication());
|
||||
deviceCodeMap.put(switchBuilder.getId(), switchBuilder.getLineId());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSwitch(Builder switchBuilder) {
|
||||
String switchPutName = this.getDefaultName(AlertType.SWITCH_LOST, switchBuilder.getLineId(), switchBuilder.getRtuId());
|
||||
log.info("线路[{}] 道岔[{}] 从监控中移除... 设备状态参数[{}]", switchBuilder.getLineId(), switchBuilder.getId(), switchBuilder);
|
||||
deviceCodeMap.remove(switchBuilder.getId());
|
||||
alertDataSource.removeAlterDevice(switchBuilder.getLineId(), switchPutName, switchBuilder.getId());
|
||||
|
||||
Optional<Turnout> turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(switchBuilder.getLineId(), switchBuilder.getId(), Turnout.class);
|
||||
Turnout turnout = turnoutOpt.orElse(null);
|
||||
if (Objects.nonNull(turnout)) {
|
||||
log.info("道岔失表未找到地图对应的设备 线路[{}],道岔code[{}]", switchBuilder.getLineId(), switchBuilder.getId());
|
||||
|
||||
//大面积失表移除
|
||||
alertManager.emit(new SwitchLostMostEvent(switchBuilder, false, turnout));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SWITCH_LOST_ALTER";
|
||||
}
|
||||
|
||||
private String getDefaultName(AlertType alertType, Integer lineId, Integer rtuId) {
|
||||
return String.format("%s-%s-%s", alertType.name(), lineId, rtuId);
|
||||
}
|
||||
|
||||
|
||||
private Switch.Builder findSwitchDevice(String deviceCode, Integer lineId) {
|
||||
DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.DEVICE);
|
||||
Map<String, GeneratedMessageV3.Builder> switchBuildMap = deviceDataSource.getAllDeviceMap().get(Switch.getDescriptor().getName());
|
||||
if (CollectionUtils.isEmpty(switchBuildMap)) {
|
||||
return null;
|
||||
}
|
||||
GeneratedMessageV3.Builder msgBuild = switchBuildMap.get(deviceCode);
|
||||
if (msgBuild instanceof Switch.Builder switchs) {
|
||||
return switchs;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDevice(Switch.Builder switchBuild, Turnout turnout, Integer lineId, GuardConfig guardConfig) {
|
||||
|
||||
boolean saveIsLost = switchBuild.getIpSingleSwitchStusLostIndication();
|
||||
boolean timeOver = this.timeOver(switchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes());
|
||||
String switchPutName = this.getDefaultName(AlertType.SWITCH_LOST, lineId, switchBuild.getRtuId());
|
||||
if (saveIsLost && timeOver) {
|
||||
//失表超时
|
||||
if (alertDataSource.putAlterDevice(lineId, switchPutName, switchBuild.getId())) {
|
||||
log.info("道岔失表超时,准备报警 线路[{}] 设备[{}] 接受时间[{}] 发送时间[{}] 对应地图设备id[{}]"
|
||||
, lineId, switchBuild.getId(), switchBuild.getReceiveTime(), switchBuild.getTimestamp(), turnout.getCommon().getId());
|
||||
String alertMsg = String.format("设备[%s]失表", switchBuild.getId());
|
||||
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_LOST, switchBuild, alertMsg, String.valueOf(turnout.getCommon().getId()),
|
||||
AlertDeviceType.DEVICE_TYPE_SWITCH, false);
|
||||
alertManager.emit(alertInfo);
|
||||
alertManager.emit(new SwitchLostMostEvent(switchBuild, true, turnout));
|
||||
}
|
||||
this.deviceCodeMap.remove(switchBuild.getId());
|
||||
} else if (!saveIsLost) {
|
||||
this.removeSwitch(switchBuild);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entry<String, Integer> entry : this.deviceCodeMap.entrySet()) {
|
||||
String deviceCode = entry.getKey();
|
||||
Integer lineId = entry.getValue();
|
||||
Switch.Builder switchBuild = this.findSwitchDevice(deviceCode, lineId);
|
||||
if (Objects.isNull(switchBuild)) {
|
||||
this.deviceCodeMap.remove(deviceCode);
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<Turnout> turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(lineId, deviceCode, Turnout.class);
|
||||
Turnout turnout = turnoutOpt.orElse(null);
|
||||
if (Objects.isNull(turnout)) {
|
||||
log.info("道岔失表未找到地图对应的设备 线路[{}],道岔code[{}]", lineId, deviceCode);
|
||||
this.deviceCodeMap.remove(deviceCode);
|
||||
continue;
|
||||
}
|
||||
GuardConfig guardConfig = configService.getGuardConfig(lineId);
|
||||
this.checkDevice(switchBuild, turnout, lineId, guardConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package club.joylink.xiannccda.ats.warn.lost;
|
||||
|
||||
import club.joylink.xiannccda.alert.NccAlertInfo;
|
||||
import club.joylink.xiannccda.alert.core.AlertDataSource;
|
||||
import club.joylink.xiannccda.alert.core.AlertDeviceType;
|
||||
import club.joylink.xiannccda.alert.core.AlertManager;
|
||||
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
|
||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
||||
import club.joylink.xiannccda.ats.warn.DeviceAlertEvent;
|
||||
import club.joylink.xiannccda.ats.warn.lost.SwitchLostMostAlertListener.SwitchLostMostEvent;
|
||||
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder;
|
||||
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout;
|
||||
import club.joylink.xiannccda.service.AlertInfoService;
|
||||
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
|
||||
import club.joylink.xiannccda.vo.AreaConfigVO;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
//@Component
|
||||
@Deprecated
|
||||
@Slf4j
|
||||
public class SwitchLostMostAlertListener implements AlertSourceEventListener<SwitchLostMostEvent> {
|
||||
|
||||
private final AlertInfoService alertInfoService;
|
||||
private final DeviceGuardConfigService configService;
|
||||
|
||||
public SwitchLostMostAlertListener(AlertInfoService alertInfoService, DeviceGuardConfigService configService) {
|
||||
this.alertInfoService = alertInfoService;
|
||||
this.configService = configService;
|
||||
}
|
||||
|
||||
private final AlertManager alertManager = AlertManager.getDefault();
|
||||
private final AlertDataSource alertDataSource = AlertDataSource.getInstance();
|
||||
|
||||
private List<Integer> findDeviceIdFormCode(Integer lineId, List<String> deviceCodes) {
|
||||
List<Integer> list = Lists.newArrayList();
|
||||
for (String deviceCode : deviceCodes) {
|
||||
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(lineId, deviceCode, Turnout.class);
|
||||
list.add(turnout.getCommon().getId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(SwitchLostMostEvent event) {
|
||||
Switch.Builder switchBuild = event.getSource();
|
||||
Integer lineId = switchBuild.getLineId();
|
||||
Turnout turnout = event.turnout;
|
||||
GuardConfig guardConfig = configService.getGuardConfig(lineId);
|
||||
Optional<AreaConfigVO> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
|
||||
switchBuild.getLineId());
|
||||
String mostName = alertInfoMostOpt.map(AreaConfigVO::getAreaName).orElse(null);
|
||||
if (StringUtils.isEmpty(mostName)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info("线路[{}] 设备[{}] 未找到大面失表的区域配置", lineId, switchBuild.getId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.alert) {
|
||||
//检测大面积失表
|
||||
boolean isMost = alertDataSource.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums());
|
||||
alertDataSource.putAlterDevice(lineId, mostName, switchBuild.getId());
|
||||
if (!isMost && alertDataSource.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums())) {
|
||||
String warnDevices = alertDataSource.findAllWarnDevice(lineId, mostName);
|
||||
this.findDeviceIdFormCode(lineId, alertDataSource.findAllWarnDeviceForList(lineId, mostName));
|
||||
String alertMsg = String.format("%s-大面积失表设备[%s]", mostName, warnDevices);
|
||||
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, switchBuild, alertMsg, warnDevices,
|
||||
AlertDeviceType.DEVICE_TYPE_SWITCH, false);
|
||||
alertManager.emit(alertInfo);
|
||||
}
|
||||
} else {
|
||||
alertDataSource.removeAlterDevice(lineId, mostName, switchBuild.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static class SwitchLostMostEvent extends DeviceAlertEvent<Builder> {
|
||||
|
||||
private boolean alert;
|
||||
|
||||
private Turnout turnout;
|
||||
|
||||
public SwitchLostMostEvent(Builder source, boolean alert, Turnout turnout) {
|
||||
super(source);
|
||||
this.alert = alert;
|
||||
this.turnout = turnout;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user