告警调整

This commit is contained in:
tiger_zhou 2023-08-29 11:25:50 +08:00
parent 5e7ecd3272
commit 9ad40d520b
12 changed files with 152 additions and 144 deletions

View File

@ -36,7 +36,9 @@ public class NccAlertInfo implements AlertInfo {
this.alertType = alertType;
this.lineId = lineId;
this.alertObject = alertObject;
if (alertType != AlertType.ALL_LINE_BLUE_DISPLAY) {
this.locatorDeviceId = locatorDeviceId;
}
this.alertLocationId = alertLocationId;
this.mock = mockData;
this.level = buildLevel();

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.alert.core;
import club.joylink.xiannccda.event.EventEmitter;
import com.google.common.base.Joiner;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Table;
@ -83,10 +84,11 @@ public class AlertManager extends EventEmitter {
detail = new AlertTableDetail(false);
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
}
if (detail.mostShower && detail.mostSize() >= val) {
//已经报警过了且超过了阈值
return false;
} else if (detail.mostShower && detail.mostSize() < val) {
// if (detail.mostShower && detail.mostSize() >= val) {
// //已经报警过了且超过了阈值
// return false;
// } else
if (detail.mostShower && detail.mostSize() < val) {
//已经报警过了但小于阈值
detail.setMostShower(false);
return false;
@ -98,6 +100,14 @@ public class AlertManager extends EventEmitter {
return false;
}
public String findAllWarnDevice(Integer lineId, String customName) {
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
if (Objects.isNull(detail)) {
return null;
}
return detail.getAllDeviceCodes();
}
public static AlertManager getInstance(String id) {
return MANAGER_MAP.computeIfAbsent(id, k -> new AlertManager(id));
}
@ -160,6 +170,10 @@ public class AlertManager extends EventEmitter {
return true;
}
public String getAllDeviceCodes() {
return Joiner.on(",").skipNulls().join(this.deviceCodes);
}
public boolean contains(String deviceCode) {
return this.deviceCodes.contains(deviceCode);
}

View File

@ -63,7 +63,9 @@ public class LineGraphicDataRepository {
private static final HashBasedTable<Integer, String, MessageOrBuilder> line_id_table =
HashBasedTable.create();
/**
* 区段 逻辑 对物理区段的map
* 线路id 逻辑 对物理区段的map
* <p>
* 如果区段是道岔物理区段那么key 就是对应的道岔code
*/
private static final Table<Integer, String, String> LOGIC_SECTION_TO_SECTION_TABLE = HashBasedTable.create();

View File

@ -1,33 +1,26 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.alert.AlertDetailFactory;
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.AlertSourceEventListener;
import club.joylink.xiannccda.alert.util.AlertUtil;
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.DeviceStatusDataOperate;
import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceInfoProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
import club.joylink.xiannccda.entity.DeviceAreaConfig;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
import club.joylink.xiannccda.service.config.Operator;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@ -48,7 +41,6 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
this.alertInfoService = alertInfoService;
}
private final static String DEFAULT_NAME = AlertType.AXLE_LED_RED.name();
@Override
public void accept(SwitchAndTrackLedAlertEvent event) {
@ -95,32 +87,59 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
String id = DeviceStatusDataOperate.findFieldVal(build, "id", String.class);
GuardConfig guardConfig = configService.getGuardConfig(lineId);
AlertType mostType = alertType == AlertType.AXLE_LED_RED ? AlertType.AXLE_LED_RED_MOST : AlertType.AXLE_LED_ORANGE_MOST;
String layoutDeviceId = this.findSectionId(lineId, section, id);
int overNums = guardConfig.getRedLedMostNums();
if (mostType == AlertType.AXLE_LED_ORANGE_MOST) {
overNums = guardConfig.getOrangeLedMostNums();
}
Optional<DeviceAreaConfig> alertInfoOptional = this.alertInfoService.findAreaDevice(alertType, AlertDeviceType.DEVICE_TYPE_TRACK, section.getCommon().getId(), lineId);
Optional<DeviceAreaConfig> alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, section.getCommon().getId(), lineId);
String ledName = alertInfoOptional.isPresent() ? alertInfoOptional.get().getAreaName() : alertType.name();
String ledMostName = alertInfoMostOptional.map(DeviceAreaConfig::getAreaName).orElse(null);
Optional<DeviceAreaConfig> alertInfoOptional = this.alertInfoService.findAreaDevice(alertType, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, lineId);
Optional<DeviceAreaConfig> alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, lineId);
String customName = this.getCustomName(alertInfoOptional, alertInfoMostOptional, alertType);
String ledName = alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带";
if (light) {
if (alertManager.putAlterDevice(lineId, ledName, id)) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode(), false);
if (alertManager.putAlterDevice(lineId, customName, id)) {
String alertMsg = String.format("出现%s设备[%s]", ledName, id);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, alertMsg, false);
alertManager.emit(alertInfo);
}
if (Objects.nonNull(ledMostName) && alertManager.needMostShow(lineId, ledMostName, overNums)) {
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode(), false);
if (alertInfoMostOptional.isPresent() && alertManager.needMostShow(lineId, customName, overNums)) {
String warnDevices = alertManager.findAllWarnDevice(lineId, customName);
String alertMsg = String.format("%s-出现大面积%s设备[%s]", alertInfoMostOptional.get().getAreaName(), ledName, warnDevices);
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, mostType, build, alertMsg, false);
alertManager.emit(alertInfoMost);
}
} else {
alertManager.removeAlterDevice(lineId, ledName, id);
if (StringUtils.isNotEmpty(ledMostName)) {
alertManager.removeAlterDevice(lineId, ledMostName, id);
alertManager.removeAlterDevice(lineId, customName, id);
if (StringUtils.isNotEmpty(customName)) {
alertManager.removeAlterDevice(lineId, customName, id);
}
}
}
private String getCustomName(Optional<DeviceAreaConfig> alertInfoOpt, Optional<DeviceAreaConfig> alertInfoMostOpt, AlertType alertType) {
String customName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null);
if (StringUtils.isNotEmpty(customName)) {
return String.format("%s_%s", customName, alertType.name());
}
return alertInfoOpt.isPresent() ? alertInfoOpt.get().getAreaName() : alertType.name();
}
private String findSectionId(int lineId, Section section, String deviceCode) {
if (section.getSectionType() == SectionType.TurnoutPhysical) {
return section.getCommon().getId();
}
Map<String, Builder> sectionMaper = LineGraphicDataRepository.getLineSectionBuild(lineId);
for (String childId : section.getChildrenList()) {
Builder builder = sectionMaper.get(childId);
String code = DeviceStatusDataOperate.findFieldVal(builder, "code", String.class);
if (StringUtils.equalsIgnoreCase(code, deviceCode) && builder instanceof DeviceInfoProto.Section.Builder section1) {
return section1.getId();
}
}
return section.getCommon().getId();
}
}

View File

@ -35,6 +35,12 @@ public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAl
private final static String ALL_BLUE_DISPLAY_VAL = "全线蓝显";
private final static AlertManager alertManager = AlertManager.getDefault();
private final static String COLL_RTU_NAME = "COLL_RTU_NAMES";
/**
* 集中站集合
* <p>
* key= 线路id val=集中站
*/
private final static Map<Integer, List<Station>> CONTROL_STATION_MAPER = new ConcurrentHashMap<>();
@ -43,27 +49,36 @@ public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAl
Rtu.Builder rtu = event.getSource();
Station station = findAllStation(rtu.getLineId(), rtu.getId());
if (Objects.isNull(station)) {
//TODO logs
log.error("rtuId[{}] 未找到对应的集中站数据", rtu.getId());
return;
}
if (rtu.getIpRtuStusDown()) {
if (alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId())) {
Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(),
rtu.getLineId());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.BLUE_DISPLAY, rtu, station.getName(), false);
alertManager.emit(alertInfo);
if (alertInfoOpt.isEmpty()) {
log.error("rtu[{}] 地图车站id[{}] 线路Id[{}]未找到对应的区域配置,无法蓝显", rtu.getId(), station.getCommon().getId(), rtu.getLineId());
return;
}
DeviceAreaConfig areaConfig = alertInfoOpt.get();
if (rtu.getIpRtuStusDown()) {
//保存出现蓝显的集中站
alertManager.putAlterDevice(rtu.getLineId(), COLL_RTU_NAME, rtu.getId());
//保存蓝显联锁id
if (alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, areaConfig.getId().toString())) {
String alertMsg = String.format("%s 蓝显", areaConfig.getAreaName());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.BLUE_DISPLAY, rtu, alertMsg, false);
alertManager.emit(alertInfo);
}
int allControlStationSize = CONTROL_STATION_MAPER.get(rtu.getLineId()).size();
if (alertManager.needMostShow(rtu.getLineId(), BLUE_DISPLAY_NAME, allControlStationSize)
&& alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL)
) {
//查看是否全部的集中站已经蓝显
if (alertManager.needMostShow(rtu.getLineId(), COLL_RTU_NAME, allControlStationSize)
&& alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL)) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.ALL_LINE_BLUE_DISPLAY, rtu, ALL_BLUE_DISPLAY_VAL, false);
alertManager.emit(alertInfo);
}
} else {
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId());
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, areaConfig.getId().toString());
alertManager.removeAlterDevice(rtu.getLineId(), COLL_RTU_NAME, rtu.getId());
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL);
}
}

View File

@ -10,32 +10,34 @@ import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
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 PlatformAlertMonitoringTask implements AlertMonitoringTask {
private final AlertDetailFactory alertDetailFactory;
private final DeviceGuardConfigService configService;
private final AlertInfoService alertInfoService;
public PlatformAlertMonitoringTask(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
this.alertDetailFactory = alertDetailFactory;
public PlatformAlertMonitoringTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
this.configService = configService;
this.alertInfoService = alertInfoService;
}
private AlertManager alertManager = AlertManager.getDefault();
private final AlertManager alertManager = AlertManager.getDefault();
Map<String, Platform.Builder> platformMap = new ConcurrentHashMap<>();
private Map<String, Platform.Builder> platformMap = new ConcurrentHashMap<>();
private final static String CUSTOM_NAME = AlertDeviceType.DEVICE_TYPE_PLATFORM.name();
public void putSwitchIfNotExist(Platform.Builder platformBuild) {
@ -62,6 +64,11 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
return "PLATFORM_CLOSE_OR_OPEN_ALTER";
}
private String findRefStationName(int lineId, String stationId) {
Stream<Station> stream = LineGraphicDataRepository.getDevices(lineId, Station.class);
Optional<Station> stationOptional = stream.filter(d -> StringUtils.equalsIgnoreCase(d.getCommon().getId(), stationId)).findAny();
return stationOptional.map(Station::getName).orElse(null);
}
@Override
public void run() {
@ -77,7 +84,10 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
if (this.timeOver(build.getReceiveTime(), timeOut)
&& alertManager.putAlterDevice(build.getLineId(), CUSTOM_NAME, build.getId())) {
LayoutGraphicsProto.Platform platform = LineGraphicDataRepository.getDeviceByCode(build.getLineId(), build.getId(), LayoutGraphicsProto.Platform.class);
NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform.getCommon().getId(), build, platform.getCode(), false);
String stationName = this.findRefStationName(build.getLineId(), platform.getRefStation());
String openClose = alertType == AlertType.PLATFORM_DOOR_CANNOT_OPEN ? "打开" : "关闭";
String alertMsg = String.format("%s-%s-屏蔽门无法%s", stationName, platform.getUp() ? "上行" : "下行", openClose);
NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform.getCommon().getId(), build, alertMsg, false);
alertManager.emit(alertInfo);
platformMap.remove(build.getId());
}

View File

@ -57,9 +57,15 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
}
public void removeSwitch(Switch.Builder switchBuilder) {
AlertManager alertManager = AlertManager.getDefault();
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(switchBuilder.getLineId(), switchBuilder.getId(), Turnout.class);
Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
switchBuilder.getLineId());
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
switchBuilder.getLineId());
String customName = this.getCustomName(alertInfoOpt, alertInfoMostOpt);
deviceMap.remove(switchBuilder.getId());
alertManager.removeAlterDevice(switchBuilder.getLineId(), DEVICE_TYPE_NAME, switchBuilder.getId());
alertManager.removeAlterDevice(switchBuilder.getLineId(), customName, switchBuilder.getId());
}
@Override
@ -71,35 +77,42 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
for (Builder savedSwitchBuild : this.deviceMap.values()) {
// String lineIdStr = String.valueOf(savedSwitchBuild.getLineId());
GuardConfig guardConfig = configService.getGuardConfig(savedSwitchBuild.getLineId());
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(savedSwitchBuild.getLineId(), savedSwitchBuild.getId(), Turnout.class);
Integer lineId = savedSwitchBuild.getLineId();
GuardConfig guardConfig = configService.getGuardConfig(lineId);
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(lineId, savedSwitchBuild.getId(), Turnout.class);
Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
String oneName = alertInfoOpt.isPresent() ? alertInfoOpt.get().getAreaName() : AlertType.SWITCH_LOST.name();
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
String customName = this.getCustomName(alertInfoOpt, alertInfoMostOpt);
boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication();
if (saveIsLost && this.timeOver(savedSwitchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) {
//失表超时
if (alertManager.putAlterDevice(savedSwitchBuild.getLineId(), oneName, savedSwitchBuild.getId())) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild, savedSwitchBuild.getId(), false);
if (alertManager.putAlterDevice(lineId, customName, savedSwitchBuild.getId())) {
String alertMsg = String.format("设备[%s]失表", savedSwitchBuild.getId());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild, alertMsg, false);
alertManager.emit(alertInfo);
this.deviceMap.remove(savedSwitchBuild.getId());
}
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
//检测大面积失表
if (alertInfoMostOpt.isPresent() && alertManager.needMostShow(savedSwitchBuild.getLineId(), alertInfoMostOpt.get().getAreaName(), guardConfig.getSwitchLostMostNums())) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild, savedSwitchBuild.getId(), false);
//检测大面积失表
if (alertInfoMostOpt.isPresent() && alertManager.needMostShow(lineId, customName, guardConfig.getSwitchLostMostNums())) {
String warnDevices = alertManager.findAllWarnDevice(lineId, customName);
String alertMsg = String.format("%s-大面积失表设备[%s]", customName, warnDevices);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild, alertMsg, false);
alertManager.emit(alertInfo);
}
}
}
}
private String getCustomName(Optional<DeviceAreaConfig> alertInfoOpt, Optional<DeviceAreaConfig> alertInfoMostOpt) {
String customName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null);
if (StringUtils.isEmpty(customName)) {
customName = alertInfoOpt.isPresent() ? alertInfoOpt.get().getAreaName() : AlertType.SWITCH_LOST.name();
}
return customName;
}
}

View File

@ -39,7 +39,8 @@ public class TrainModeAlertListener implements AlertSourceEventListener<TrainAle
}
Section section = LineGraphicDataRepository.getDeviceByCode(trainInfo.getLineId(), sectionCode, Section.class);
if (alertManager.putAlterDevice(trainInfo.getLineId(), CUSTOM_NAME, trainInfo.getGroupId())) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRAIN, section.getCommon().getId(), trainInfo, trainInfo.getGroupId(), false);
String alertMsg = String.format("列车[%s] 紧制导致ATP切除所在区段[%s]", trainInfo.getGroupId(), section.getCode());
NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRAIN, section.getCommon().getId(), trainInfo, alertMsg, false);
alertManager.emit(alertInfo);
}
} else {

View File

@ -3,44 +3,30 @@ package club.joylink.xiannccda.service;
import club.joylink.xiannccda.alert.NccAlertInfo;
import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.entity.DeviceAreaConfig;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import club.joylink.xiannccda.repository.IDeviceAreaConfigRepository;
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
import club.joylink.xiannccda.service.config.DeviceAreaConfigService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.protobuf.MessageOrBuilder;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
@Service
@Slf4j
public class AlertInfoService {
private final AlertTipService alertTipService;
private final IDeviceAreaConfigRepository areaConfigRepository;
private final DeviceAreaConfigService deviceAreaConfigService;
public AlertInfoService(AlertTipService alertTipService, IDeviceAreaConfigRepository areaConfigRepository, DeviceAreaConfigService deviceAreaConfigService) {
this.alertTipService = alertTipService;
this.areaConfigRepository = areaConfigRepository;
public AlertInfoService(DeviceAreaConfigService deviceAreaConfigService) {
this.deviceAreaConfigService = deviceAreaConfigService;
}
@ -49,53 +35,24 @@ public class AlertInfoService {
if (CollectionUtils.isEmpty(areaConfigList)) {
return Collections.emptyList();
}
List<DeviceAreaConfig> findList = areaConfigList.stream().filter(d -> d.findAlertTypes(alertType)).toList();
/*LambdaQueryWrapper<DeviceAreaConfig> qw = Wrappers.lambdaQuery(DeviceAreaConfig.class);
qw.eq(DeviceAreaConfig::getDeviceType, dt.name());
qw.eq(DeviceAreaConfig::getLineId, lineId);
qw.last(String.format(" and find_in_set('%s',%s) > 0 ", alertType.name(), DeviceAreaConfig.ALERT_TYPES));
List<DeviceAreaConfig> areaConfigList = this.areaConfigRepository.list(qw);*/
return findList;
return areaConfigList.stream().filter(d -> d.findAlertTypes(alertType)).toList();
}
public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb, String targetDeviceCode, boolean mockData) {
public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb, String alertMsg, boolean mockData) {
Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class);
Optional<DeviceAreaConfig> areaConfigOptional = this.findAreaDevice(alertType, dt, layoutId, lineId);
return this.createAlert2(areaConfigOptional, alertType, mb, targetDeviceCode, mockData);
return this.createAlert2(areaConfigOptional, alertType, mb, alertMsg, mockData);
}
public NccAlertInfo createAlert2(Optional<DeviceAreaConfig> areaConfigOpt, AlertType alertType, MessageOrBuilder mb, String targetDeviceCode, boolean mockData) {
public NccAlertInfo createAlert2(Optional<DeviceAreaConfig> areaConfigOpt, AlertType alertType, MessageOrBuilder mb, String alertMsg, boolean mockData) {
Long timestamp = DeviceStatusDataOperate.findFieldVal(mb, "timestamp", Long.class);
Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class);
String deviceCode = DeviceStatusDataOperate.findFieldVal(mb, "id", String.class);
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneId.of("+8"));
DeviceAreaConfig areaConfig = areaConfigOpt.orElse(null);
if (Objects.isNull(areaConfig)) {
return new NccAlertInfo(createTime, alertType, lineId, targetDeviceCode, deviceCode, null, mockData);
}
String alertObject = String.format("%s-设备[%s]", areaConfig.getAreaName(), targetDeviceCode);
return new NccAlertInfo(createTime, alertType, lineId, alertObject, deviceCode, areaConfig.getId(), mockData);
Long areaConfigId = areaConfigOpt.map(DeviceAreaConfig::getId).orElse(null);
return new NccAlertInfo(createTime, alertType, lineId, alertMsg, deviceCode, areaConfigId, mockData);
}
/* @Deprecated
public NccAlertInfo createAlert(DeviceAreaConfig areaConfig, AlertType alertType, MessageOrBuilder mb) {
Long timestamp = DeviceStatusDataOperate.findFieldVal(mb, "timestamp", Long.class);
Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class);
String deviceCode = DeviceStatusDataOperate.findFieldVal(mb, "id", String.class);
Optional<AlertTip> alertTipOptional;
if (Objects.isNull(areaConfig)) {
alertTipOptional = this.alertTipService.queryOne2(alertType.name(), null);
} else {
alertTipOptional = this.alertTipService.queryOne2(alertType.name(), areaConfig.getId());
}
AlertTip at = alertTipOptional.orElse(null);
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneId.of("+8"));
return new NccAlertInfo(createTime, alertType, Objects.nonNull(at) ? at.getId() : null, lineId, deviceCode, deviceCode, null);
}*/
public Optional<DeviceAreaConfig> findAreaDevice(AlertType alertType, AlertDeviceType dt, String layoutId, int lineId) {
List<DeviceAreaConfig> areaConfigList = this.findDevice(alertType, dt, lineId);
@ -110,8 +67,7 @@ public class AlertInfoService {
}
for (DeviceAreaConfig areaConfig : areaConfigList) {
if (areaConfig.getDeviceType() == dt) {
boolean b = Splitter.on(",").splitToStream(areaConfig.getData()).anyMatch(d -> StringUtils.equalsIgnoreCase(d, layoutId));
if (b) {
if (Splitter.on(",").splitToStream(areaConfig.getData()).anyMatch(d -> StringUtils.equalsIgnoreCase(d, layoutId))) {
return areaConfig;
}
}

View File

@ -118,7 +118,7 @@ public class AlertMockService {
Turnout turnout = turnoutOptional.orElse(null);
return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchs, dto.getAll(), true);
}
case AXLE_LED_RED, AXLE_LED_ORANGE -> {
case AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST -> {
Optional<LogicSection> lsOptional = LineGraphicDataRepository.getDevices(lineId, LogicSection.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny();
Track.Builder track = Track.newBuilder();
track.setId(dto.getFrist());
@ -172,7 +172,7 @@ public class AlertMockService {
case SWITCH_LOST, SWITCH_LOST_MOST -> {
return LineGraphicDataRepository.getDevices(lineId, Turnout.class).collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values();
}
case AXLE_LED_RED, AXLE_LED_ORANGE, TRAIN_EB_ATP -> {
case AXLE_LED_RED, AXLE_LED_ORANGE, TRAIN_EB_ATP, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST -> {
return LineGraphicDataRepository.getDevices(lineId, LogicSection.class)
.collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values();

View File

@ -41,7 +41,7 @@ public class AlertRecordService {
if (Objects.nonNull(locationId) && locationId > 0L) {
qw.eq(AlertTip::getAreaConfigId, locationId);
}
AlertTip tip = alertTipRepository.getOne(qw);
AlertTip tip = alertTipRepository.getOne(qw, false);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip), "未找到对应的决策辅助信息");
this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class)

View File

@ -1,29 +1,18 @@
package club.joylink.xiannccda.service.config;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigQueryDto;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.exception.ExceptionAssert;
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -57,20 +46,7 @@ public class DeviceGuardConfigService {
public void saveOrUpdate(DeviceGuardConfig dto) {
/* LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class);
qw.eq(DeviceGuardConfig::getLineId, dto.getLineId())
.eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_USER)
.eq(DeviceGuardConfig::getDeviceType, dto.getDeviceType().name())
.eq(DeviceGuardConfig::getDeviceConfigType, dto.getConfigDeviceType());
DeviceGuardConfig dataConfig = this.convertDB(dto);
if (Objects.nonNull(dto.getId())) {
DeviceGuardConfig guardConfig = this.configRepository.getById(dto.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(guardConfig), "未找到对应的数据");
qw.ne(DeviceGuardConfig::getId, dto.getId());
dataConfig.setId(guardConfig.getId());
}
Long typeCounter = this.configRepository.count(qw);
BusinessExceptionAssertEnum.UNIQUE_FIELD_REPEAT.assertTrue */
this.configRepository.saveOrUpdate(dto);
GUARD_CONFIG_CACHE.invalidateAll();
}