问题调整
This commit is contained in:
parent
f8a020e968
commit
a6a20e8b49
@ -127,7 +127,7 @@ public class AlertDetailFactory {
|
||||
.map(AlertTip::getId).orElse(null);
|
||||
|
||||
return new NccAlertInfo(alertTime, alertType, alertTipId, lineId, alertObject, locatorDeviceId,
|
||||
"", mock);
|
||||
null, mock);
|
||||
}
|
||||
|
||||
private String getId(MessageOrBuilder messageOrBuilder) {
|
||||
|
@ -23,21 +23,36 @@ public class NccAlertInfo implements AlertInfo {
|
||||
@Setter
|
||||
// private AlertLocation alertLocation;
|
||||
private String alertLocation;
|
||||
private Long alertLocationId;
|
||||
private boolean mock;
|
||||
@Setter
|
||||
private Integer alarmStatus;
|
||||
|
||||
public NccAlertInfo(LocalDateTime alertTime, AlertType alertType, Integer alertTipId,
|
||||
public NccAlertInfo(LocalDateTime alertTime, AlertType alertType,
|
||||
Integer lineId, String alertObject, String locatorDeviceId,
|
||||
String alertLocation, boolean mock) {
|
||||
Long alertLocationId) {
|
||||
this.alertTime = alertTime;
|
||||
this.alertType = alertType;
|
||||
this.alertTipId = alertTipId;
|
||||
this.lineId = lineId;
|
||||
this.alertObject = alertObject;
|
||||
this.locatorDeviceId = locatorDeviceId;
|
||||
this.alertLocation = alertLocation;
|
||||
this.mock = mock;
|
||||
this.alertLocationId = alertLocationId;
|
||||
this.mock = false;
|
||||
this.level = buildLevel();
|
||||
}
|
||||
|
||||
public NccAlertInfo(LocalDateTime alertTime, AlertType alertType, Integer alertTipId,
|
||||
Integer lineId, String alertObject, String locatorDeviceId,
|
||||
Long alertLocationId) {
|
||||
this.alertTime = alertTime;
|
||||
this.alertType = alertType;
|
||||
this.alertTipId = alertTipId;
|
||||
this.lineId = lineId;
|
||||
this.alertObject = alertObject;
|
||||
this.locatorDeviceId = locatorDeviceId;
|
||||
this.alertLocationId = alertLocationId;
|
||||
this.mock = false;
|
||||
this.level = buildLevel();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
package club.joylink.xiannccda.alert.core;
|
||||
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import java.util.Arrays;
|
||||
import lombok.Getter;
|
||||
|
||||
public enum AlertDeviceType {
|
||||
|
||||
/**
|
||||
* 集中站
|
||||
*/
|
||||
DEVICE_TYPE_RTU,
|
||||
|
||||
/**
|
||||
* 道岔
|
||||
*/
|
||||
DEVICE_TYPE_SWITCH,
|
||||
/**
|
||||
* 轨道
|
||||
*/
|
||||
DEVICE_TYPE_TRACK,
|
||||
|
||||
/**
|
||||
* 站台
|
||||
*/
|
||||
DEVICE_TYPE_PLATFORM,
|
||||
|
||||
/**
|
||||
* 列车设备
|
||||
*/
|
||||
DEVICE_TYPE_TRAIN
|
||||
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 事件任务管理器
|
||||
@ -74,6 +75,9 @@ public class AlertManager extends EventEmitter {
|
||||
}
|
||||
|
||||
public boolean needMostShow(String lineId, String customName, int val) {
|
||||
if (StringUtils.isEmpty(customName)) {
|
||||
return false;
|
||||
}
|
||||
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
||||
if (Objects.isNull(detail)) {
|
||||
detail = new AlertTableDetail(false);
|
||||
@ -149,10 +153,11 @@ public class AlertManager extends EventEmitter {
|
||||
|
||||
public boolean add(String deviceCode) {
|
||||
if (this.contains(deviceCode)) {
|
||||
this.deviceCodes.add(deviceCode);
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
this.deviceCodes.add(deviceCode);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean contains(String deviceCode) {
|
||||
|
@ -12,4 +12,7 @@ public interface AlertMonitoringTask {
|
||||
*/
|
||||
void run();
|
||||
|
||||
default boolean timeOver(Long receiveTime, int val) {
|
||||
return System.currentTimeMillis() > (receiveTime + (val * 1000L));
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor {
|
||||
} else if (builder instanceof Track.Builder trackBuild) {
|
||||
alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild));
|
||||
} else if (builder instanceof Switch.Builder switchBuild) {
|
||||
alertManager.emit(new SwitchAndTrackLedAlertEvent(switchBuild));
|
||||
alertManager.emit(new SwitchLostAlertEvent(switchBuild));
|
||||
alertManager.emit(new SwitchAndTrackLedAlertEvent(switchBuild));
|
||||
} else if (builder instanceof Platform.Builder platformBuild) {
|
||||
alertManager.emit(new PlatformAlertEvent(platformBuild));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ 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;
|
||||
@ -15,8 +16,11 @@ import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
|
||||
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.GuardConfigProto.GuardConfig;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
|
||||
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;
|
||||
@ -26,6 +30,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -33,14 +38,18 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener<SwitchAndTrackLedAlertEvent> {
|
||||
|
||||
private AlertDetailFactory alertDetailFactory;
|
||||
private DeviceGuardConfigService configService;
|
||||
|
||||
public AxleSwitchTrackLedAlertListener(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService) {
|
||||
this.alertDetailFactory = alertDetailFactory;
|
||||
private DeviceGuardConfigService configService;
|
||||
private AlertInfoService alertInfoService;
|
||||
|
||||
public AxleSwitchTrackLedAlertListener(DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
|
||||
|
||||
this.configService = configService;
|
||||
this.alertInfoService = alertInfoService;
|
||||
}
|
||||
|
||||
private final static String DEFAULT_NAME = AlertType.AXLE_LED_RED.name();
|
||||
|
||||
@Override
|
||||
public void accept(SwitchAndTrackLedAlertEvent event) {
|
||||
GeneratedMessageV3.Builder o = event.getSource();
|
||||
@ -83,47 +92,35 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
|
||||
private void emit(boolean light, Builder build, Section section, AlertType alertType) {
|
||||
AlertManager alertManager = AlertManager.getDefault();
|
||||
Integer lineId = DeviceStatusDataOperate.findFieldVal(build, "lineId", Integer.class);
|
||||
Integer rtuId = DeviceStatusDataOperate.findFieldVal(build, "rtuId", Integer.class);
|
||||
String id = DeviceStatusDataOperate.findFieldVal(build, "id", String.class);
|
||||
Long timestemp = DeviceStatusDataOperate.findFieldVal(build, "timestamp", Long.class);
|
||||
String alertTypeName = String.format("%s-%s-%s", alertType.name(), lineId, rtuId);
|
||||
String alertTypeMostName = String.format("%s-%s", alertTypeName, "counter");
|
||||
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestemp), ZoneId.of("+8"));
|
||||
|
||||
//TODO 检查对应的类型下数量是否超过阈值,超过阈值及达到大范围报警
|
||||
Map<AlertType, DeviceGuardConfig> configMaper = configService.getGuardConfig(lineId, DeviceType.DEVICE_TYPE_TRACK);
|
||||
GuardConfig guardConfig = configService.getGuardConfig(lineId);
|
||||
AlertType mostType = alertType == AlertType.AXLE_LED_RED ? AlertType.AXLE_LED_RED_MOST : AlertType.AXLE_LED_ORANGE_MOST;
|
||||
DeviceGuardConfig guardConfig = this.getConfigOrDefault(mostType, configMaper);
|
||||
/* if (alertManager.needMostShow(lineId.toString(), alertTypeMostName, guardConfig.getVal())) {
|
||||
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, lineId, false, section);
|
||||
alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(id).orElse(null));
|
||||
alertManager.emit(alertInfo);
|
||||
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);
|
||||
|
||||
if (light) {
|
||||
if (alertManager.putAlterDevice(lineId.toString(), alertTypeName, id)) {
|
||||
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, lineId, false, section);
|
||||
alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(id).orElse(null));
|
||||
if (alertManager.putAlterDevice(lineId.toString(), ledName, id)) {
|
||||
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build);
|
||||
alertManager.emit(alertInfo);
|
||||
}
|
||||
if (Objects.nonNull(ledMostName) && alertManager.needMostShow(lineId.toString(), ledMostName, overNums)) {
|
||||
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build);
|
||||
alertManager.emit(alertInfoMost);
|
||||
}
|
||||
} else {
|
||||
alertManager.removeAlterDevice(lineId.toString(), alertTypeName, id);
|
||||
}*/
|
||||
alertManager.removeAlterDevice(lineId.toString(), ledName, id);
|
||||
if (StringUtils.isNotEmpty(ledMostName)) {
|
||||
alertManager.removeAlterDevice(lineId.toString(), ledMostName, id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceGuardConfig getConfigOrDefault(AlertType mostType, Map<AlertType, DeviceGuardConfig> configMap) {
|
||||
AlertType configDeviceType = mostType == AlertType.AXLE_LED_RED_MOST ? AlertType.AXLE_LED_RED_MOST : AlertType.AXLE_LED_ORANGE_MOST;
|
||||
|
||||
DeviceGuardConfig guardConfig = configMap.get(configDeviceType);
|
||||
if (Objects.nonNull(guardConfig)) {
|
||||
return guardConfig;
|
||||
}
|
||||
|
||||
if (configDeviceType == AlertType.AXLE_LED_RED_MOST) {
|
||||
guardConfig = this.configService.buildDefault(DeviceType.DEVICE_TYPE_TRACK, configDeviceType, Operator.GE, GuardUnit.NUMS, 5);
|
||||
} else {
|
||||
guardConfig = this.configService.buildDefault(DeviceType.DEVICE_TYPE_TRACK, AlertType.AXLE_LED_ORANGE_MOST, Operator.GE, GuardUnit.NUMS, 5);
|
||||
}
|
||||
return guardConfig;
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,16 @@ 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.AlertMonitoringTask;
|
||||
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
|
||||
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.DeviceStatusProto.Platform;
|
||||
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
|
||||
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 java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -26,19 +22,21 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
|
||||
|
||||
private AlertDetailFactory alertDetailFactory;
|
||||
private DeviceGuardConfigService configService;
|
||||
private final AlertDetailFactory alertDetailFactory;
|
||||
private final DeviceGuardConfigService configService;
|
||||
private final AlertInfoService alertInfoService;
|
||||
|
||||
public PlatformAlertMonitoringTask(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService) {
|
||||
public PlatformAlertMonitoringTask(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
|
||||
this.alertDetailFactory = alertDetailFactory;
|
||||
this.configService = configService;
|
||||
this.alertInfoService = alertInfoService;
|
||||
}
|
||||
|
||||
private AlertManager alertManager = AlertManager.getDefault();
|
||||
private final static String DEVICE_TYPE_NAME = Platform.getDescriptor().getName();
|
||||
|
||||
|
||||
Map<String, Platform.Builder> platformMap = new ConcurrentHashMap<>();
|
||||
private final static String CUSTOM_NAME = AlertDeviceType.DEVICE_TYPE_PLATFORM.name();
|
||||
|
||||
public void putSwitchIfNotExist(Platform.Builder platformBuild) {
|
||||
Platform.Builder saveBuilder = this.platformMap.get(platformBuild.getId());
|
||||
@ -54,7 +52,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
|
||||
|
||||
public void removeSwitch(Platform.Builder platformBuild) {
|
||||
platformMap.remove(platformBuild.getId());
|
||||
alertManager.removeAlterDevice(String.valueOf(platformBuild.getLineId()), DEVICE_TYPE_NAME, platformBuild.getId());
|
||||
alertManager.removeAlterDevice(String.valueOf(platformBuild.getLineId()), CUSTOM_NAME, platformBuild.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,40 +65,21 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
|
||||
public void run() {
|
||||
for (Platform.Builder build : platformMap.values()) {
|
||||
String lineId = String.valueOf(build.getLineId());
|
||||
Map<AlertType, DeviceGuardConfig> configMaper = configService.getGuardConfig(build.getLineId(), DeviceType.DEVICE_TYPE_PLATFORM);
|
||||
DeviceGuardConfig guardConfig = this.getConfigOrDefault(AlertType.PLATFORM_DOOR_CANNOT_OPEN, configMaper);
|
||||
GuardConfig guardConfig = configService.getGuardConfig(build.getLineId());
|
||||
AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_OPEN;
|
||||
int timeOut = guardConfig.getCanNotOpenTimes();
|
||||
if (build.getPsdOpen()) {
|
||||
guardConfig = this.getConfigOrDefault(AlertType.PLATFORM_DOOR_CANNOT_CLOSE, configMaper);
|
||||
alertType = AlertType.PLATFORM_DOOR_CANNOT_CLOSE;
|
||||
timeOut = guardConfig.getCanNotCloseTimes();
|
||||
}
|
||||
if (/*guardConfig.getDeviceOperator().contrast(guardConfig.getDeviceUnit(), build.getReceiveTime(), guardConfig.getVal())
|
||||
&&*/ alertManager.putAlterDevice(lineId, "", build.getId())) {
|
||||
NccAlertInfo alertInfo = this.createAlertTip(build, alertType);
|
||||
if (this.timeOver(build.getReceiveTime(), timeOut)
|
||||
&& alertManager.putAlterDevice(lineId, 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);
|
||||
alertManager.emit(alertInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NccAlertInfo createAlertTip(Platform.Builder platformBuild, AlertType alertType) {
|
||||
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(platformBuild.getTimestamp()), ZoneId.of("+8"));
|
||||
LayoutGraphicsProto.Platform platform = LineGraphicDataRepository.getDeviceByCode(platformBuild.getLineId(), platformBuild.getId(), LayoutGraphicsProto.Platform.class);
|
||||
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, platformBuild.getLineId(), false, platform);
|
||||
return alertInfo;
|
||||
}
|
||||
|
||||
private DeviceGuardConfig getConfigOrDefault(AlertType configDeviceType, Map<AlertType, DeviceGuardConfig> configMap) {
|
||||
DeviceGuardConfig guardConfig = configMap.get(configDeviceType);
|
||||
if (Objects.nonNull(guardConfig)) {
|
||||
return guardConfig;
|
||||
}
|
||||
if (configDeviceType == AlertType.PLATFORM_DOOR_CANNOT_OPEN) {
|
||||
guardConfig = this.configService.buildDefault(DeviceType.DEVICE_TYPE_SWITCH, configDeviceType, Operator.GE, GuardUnit.TIMES, 30);
|
||||
} else {
|
||||
guardConfig = this.configService.buildDefault(DeviceType.DEVICE_TYPE_SWITCH, AlertType.PLATFORM_DOOR_CANNOT_CLOSE, Operator.GE, GuardUnit.TIMES, 60);
|
||||
}
|
||||
return guardConfig;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ 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.AlertMonitoringTask;
|
||||
import club.joylink.xiannccda.alert.util.AlertUtil;
|
||||
@ -11,7 +12,9 @@ import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
|
||||
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.entity.DeviceAreaConfig;
|
||||
import club.joylink.xiannccda.entity.DeviceGuardConfig;
|
||||
import club.joylink.xiannccda.service.AlertInfoService;
|
||||
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
|
||||
@ -21,21 +24,22 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
|
||||
|
||||
private AlertDetailFactory alertDetailFactory;
|
||||
private DeviceGuardConfigService configService;
|
||||
|
||||
private AlertInfoService alertInfoService;
|
||||
|
||||
public SwitchLostAlertMonitoringTask(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
|
||||
this.alertDetailFactory = alertDetailFactory;
|
||||
public SwitchLostAlertMonitoringTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
|
||||
|
||||
this.configService = configService;
|
||||
this.alertInfoService = alertInfoService;
|
||||
}
|
||||
@ -63,52 +67,37 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
|
||||
return "SWITCH_LOST_ALTER";
|
||||
}
|
||||
|
||||
/* private NccAlertInfo createAlterTip(Switch.Builder switchBuild, String lineId, AlertType alertType) {
|
||||
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(switchBuild.getTimestamp()), ZoneId.of("+8"));
|
||||
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, Integer.valueOf(lineId), false, switchBuild);
|
||||
alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(String.valueOf(switchBuild.getRtuId())).orElse(null));
|
||||
return alertInfo;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// for (Builder savedSwitchBuild : this.deviceMap.values()) {
|
||||
// String lineIdStr = String.valueOf(savedSwitchBuild.getLineId());
|
||||
// Map<AlertType, DeviceGuardConfig> configMaper = configService.getGuardConfig(savedSwitchBuild.getLineId(), DeviceType.DEVICE_TYPE_SWITCH);
|
||||
// DeviceGuardConfig guardConfig = this.getConfigOrDefault(AlertType.SWITCH_LOST, configMaper);
|
||||
// boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication();
|
||||
// if (saveIsLost && guardConfig.getDeviceOperator().contrast(guardConfig.getDeviceUnit(), savedSwitchBuild.getReceiveTime(), guardConfig.getVal())) {
|
||||
// Turnout turnout = LineGraphicDataRepository.getDeviceByCode(savedSwitchBuild.getLineId(), savedSwitchBuild.getId(), Turnout.class);
|
||||
// //失表超时
|
||||
// if (alertManager.putAlterDevice(lineIdStr, DEVICE_TYPE_NAME, savedSwitchBuild.getId())) {
|
||||
// NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.SWITCH_LOST, DeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
|
||||
// savedSwitchBuild);
|
||||
// alertManager.emit(alertInfo);
|
||||
// }
|
||||
// //检测大面积失表
|
||||
// DeviceGuardConfig mostGuardConfig = this.getConfigOrDefault(AlertType.SWITCH_LOST_MOST, configMaper);
|
||||
// if (alertManager.needMostShow(lineIdStr, "", mostGuardConfig.getVal())) {
|
||||
// NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.SWITCH_LOST_MOST, DeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
|
||||
// savedSwitchBuild);
|
||||
// alertManager.emit(alertInfo);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
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);
|
||||
|
||||
private DeviceGuardConfig getConfigOrDefault(AlertType configDeviceType, Map<AlertType, DeviceGuardConfig> configMap) {
|
||||
DeviceGuardConfig guardConfig = configMap.get(configDeviceType);
|
||||
if (Objects.nonNull(guardConfig)) {
|
||||
return guardConfig;
|
||||
}
|
||||
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();
|
||||
|
||||
boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication();
|
||||
if (saveIsLost && this.timeOver(savedSwitchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) {
|
||||
//失表超时
|
||||
if (alertManager.putAlterDevice(lineIdStr, oneName, savedSwitchBuild.getId())) {
|
||||
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild);
|
||||
alertManager.emit(alertInfo);
|
||||
}
|
||||
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
|
||||
savedSwitchBuild.getLineId());
|
||||
//检测大面积失表
|
||||
if (alertInfoMostOpt.isPresent() && alertManager.needMostShow(lineIdStr, alertInfoMostOpt.get().getAreaName(), guardConfig.getSwitchLostMostNums())) {
|
||||
|
||||
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild);
|
||||
alertManager.emit(alertInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (configDeviceType == AlertType.SWITCH_LOST) {
|
||||
guardConfig = this.configService.buildDefault(DeviceType.DEVICE_TYPE_SWITCH, configDeviceType, Operator.GE, GuardUnit.TIMES, 13);
|
||||
} else {
|
||||
guardConfig = this.configService.buildDefault(DeviceType.DEVICE_TYPE_SWITCH, AlertType.SWITCH_LOST_MOST, Operator.GE, GuardUnit.NUMS, 2);
|
||||
}
|
||||
return guardConfig;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,11 +1,19 @@
|
||||
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.ats.cache.LineGraphicDataRepository;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout;
|
||||
import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
|
||||
import club.joylink.xiannccda.service.AlertInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -13,14 +21,15 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class TrainModeAlertListener implements AlertSourceEventListener<TrainAlertEvent> {
|
||||
|
||||
private AlertDetailFactory alertDetailFactory;
|
||||
private final AlertInfoService alertInfoService;
|
||||
|
||||
public TrainModeAlertListener(AlertDetailFactory alertDetailFactory) {
|
||||
this.alertDetailFactory = alertDetailFactory;
|
||||
public TrainModeAlertListener(AlertInfoService alertInfoService) {
|
||||
this.alertInfoService = alertInfoService;
|
||||
}
|
||||
|
||||
private AlertManager alertManager = AlertManager.getDefault();
|
||||
|
||||
private final static String CUSTOM_NAME = AlertType.TRAIN_SIGNAL.name();
|
||||
|
||||
@Override
|
||||
public void accept(TrainAlertEvent event) {
|
||||
@ -28,9 +37,13 @@ public class TrainModeAlertListener implements AlertSourceEventListener<TrainAle
|
||||
TrainMode trainMode = trainInfo.getMode();
|
||||
String lineIdStr = String.valueOf(trainInfo.getLineId());
|
||||
if (trainMode.getIpModeTrainAtpCut() && trainMode.getIpModeTrainEbAlarm()) {
|
||||
|
||||
Section section = LineGraphicDataRepository.getDeviceByCode(trainInfo.getLineId(), trainInfo.getDevName(), Section.class);
|
||||
if (alertManager.putAlterDevice(lineIdStr, CUSTOM_NAME, trainInfo.getGroupId())) {
|
||||
NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.TRAIN_SIGNAL, AlertDeviceType.DEVICE_TYPE_TRAIN, section.getCommon().getId(), trainInfo);
|
||||
alertManager.emit(alertInfo);
|
||||
}
|
||||
} else {
|
||||
alertManager.removeAlterDevice(lineIdStr, "", trainInfo.getGroupId());
|
||||
alertManager.removeAlterDevice(lineIdStr, CUSTOM_NAME, trainInfo.getGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@ -40,8 +41,8 @@ public class AlertRecordController {
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "报警信息确认")
|
||||
@ApiResponse(description = "报警信息确认")
|
||||
public AlertTip confirm(@PathVariable("recordId") Long recordId, @PathVariable("tipType") String tipId) {
|
||||
return this.alertRecordService.confirm(recordId, tipId);
|
||||
public AlertTip confirm(@PathVariable("recordId") Long recordId, @PathVariable("tipType") String tipId, @RequestParam(value = "alertLocationId", required = false) Long locationId) {
|
||||
return this.alertRecordService.confirm(recordId, tipId, locationId);
|
||||
}
|
||||
|
||||
@GetMapping("/fail/{recordId}")
|
||||
|
@ -32,10 +32,10 @@ public class DeviceGuardConfigController {
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "initData")
|
||||
@GetMapping("/initData/{lineId}")
|
||||
public List<DeviceGuardConfig> initData(@PathVariable("lineId") Integer lineId) {
|
||||
public DeviceGuardConfig initData(@PathVariable("lineId") Integer lineId) {
|
||||
LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class);
|
||||
qw.eq(DeviceGuardConfig::getLineId, lineId);
|
||||
return this.iDeviceGuardConfigRepository.list(qw);
|
||||
return this.iDeviceGuardConfigRepository.getOne(qw, false);
|
||||
}
|
||||
|
||||
@SecurityRequirement(name = "jwt")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package club.joylink.xiannccda.dto.config;
|
||||
|
||||
import club.joylink.xiannccda.alert.core.AlertDeviceType;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
@ -10,7 +11,7 @@ public class DeviceAreaConfigDto {
|
||||
private Long id;
|
||||
private Integer lineId;
|
||||
private String areaName;
|
||||
private DeviceType deviceType;
|
||||
private AlertDeviceType deviceType;
|
||||
private List<String> data;
|
||||
private List<String> alertTypes;
|
||||
}
|
||||
|
@ -327,6 +327,14 @@ public final class AlertConstProto {
|
||||
* <code>SWITCH_LOST_MOST = 17;</code>
|
||||
*/
|
||||
SWITCH_LOST_MOST(17),
|
||||
/**
|
||||
* <pre>
|
||||
*信号故障
|
||||
* </pre>
|
||||
*
|
||||
* <code>TRAIN_SIGNAL = 18;</code>
|
||||
*/
|
||||
TRAIN_SIGNAL(18),
|
||||
UNRECOGNIZED(-1),
|
||||
;
|
||||
|
||||
@ -454,6 +462,14 @@ public final class AlertConstProto {
|
||||
* <code>SWITCH_LOST_MOST = 17;</code>
|
||||
*/
|
||||
public static final int SWITCH_LOST_MOST_VALUE = 17;
|
||||
/**
|
||||
* <pre>
|
||||
*信号故障
|
||||
* </pre>
|
||||
*
|
||||
* <code>TRAIN_SIGNAL = 18;</code>
|
||||
*/
|
||||
public static final int TRAIN_SIGNAL_VALUE = 18;
|
||||
|
||||
|
||||
public final int getNumber() {
|
||||
@ -496,6 +512,7 @@ public final class AlertConstProto {
|
||||
case 15: return AXLE_LED_ORANGE;
|
||||
case 16: return AXLE_LED_ORANGE_MOST;
|
||||
case 17: return SWITCH_LOST_MOST;
|
||||
case 18: return TRAIN_SIGNAL;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
@ -564,7 +581,7 @@ public final class AlertConstProto {
|
||||
"\n\020alertConst.proto\022\005alert*g\n\rAlertLocati" +
|
||||
"on\022\032\n\026ALERT_LOCATION_UNKNOWN\020\000\022\006\n\002QX\020\001\022\013" +
|
||||
"\n\007YHZ_LSQ\020\002\022\013\n\007HJM_LSQ\020\003\022\013\n\007BCT_LSQ\020\004\022\013\n" +
|
||||
"\007BSQ_LSQ\020\005*\200\003\n\tAlertType\022\026\n\022ALERT_TYPE_U" +
|
||||
"\007BSQ_LSQ\020\005*\222\003\n\tAlertType\022\026\n\022ALERT_TYPE_U" +
|
||||
"NKNOWN\020\000\022\020\n\014BLUE_DISPLAY\020\001\022\021\n\rTRAIN_DELA" +
|
||||
"Y_2\020\002\022\022\n\016TRAIN_DELAY_10\020\003\022\'\n#PLATFORM_DO" +
|
||||
"OR_WITHOUT_LOCKED_SIGNAL\020\004\022\035\n\031PLATFORM_D" +
|
||||
@ -573,9 +590,9 @@ public final class AlertConstProto {
|
||||
"_LOST\020\010\022\022\n\016SWITCH_DW_LOST\020\t\022\022\n\016SWITCH_FW" +
|
||||
"_LOST\020\n\022\020\n\014AXLE_LED_RED\020\r\022\025\n\021AXLE_LED_RE" +
|
||||
"D_MOST\020\016\022\023\n\017AXLE_LED_ORANGE\020\017\022\030\n\024AXLE_LE" +
|
||||
"D_ORANGE_MOST\020\020\022\024\n\020SWITCH_LOST_MOST\020\021B4\n" +
|
||||
"!club.joylink.xiannccda.dto.protosB\017Aler" +
|
||||
"tConstProtob\006proto3"
|
||||
"D_ORANGE_MOST\020\020\022\024\n\020SWITCH_LOST_MOST\020\021\022\020\n" +
|
||||
"\014TRAIN_SIGNAL\020\022B4\n!club.joylink.xiannccd" +
|
||||
"a.dto.protosB\017AlertConstProtob\006proto3"
|
||||
};
|
||||
descriptor = com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
|
@ -36,6 +36,7 @@ public class AlertRecord {
|
||||
private LocalDateTime alertTime;
|
||||
|
||||
private String alertLocation;
|
||||
private Long alertLocationId;
|
||||
private Long alertTipId;
|
||||
|
||||
private Integer alarmStatus;
|
||||
@ -50,6 +51,7 @@ public class AlertRecord {
|
||||
public static final String ALERT_TIME = "alert_time";
|
||||
|
||||
public static final String ALERT_LOCATION = "alert_location";
|
||||
public static final String ALERT_LOCATION_ID = "alert_location_id";
|
||||
public static final String ALERT_TIP_ID = "alert_tip_id";
|
||||
public static final String ALARM_STATUS = "alarm_status";
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
package club.joylink.xiannccda.entity;
|
||||
|
||||
import club.joylink.xiannccda.alert.core.AlertDeviceType;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.google.common.base.Splitter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -31,7 +36,7 @@ public class DeviceAreaConfig {
|
||||
|
||||
private String areaName;
|
||||
|
||||
private DeviceType deviceType;
|
||||
private AlertDeviceType deviceType;
|
||||
|
||||
private String data;
|
||||
private String alertTypes;
|
||||
@ -46,4 +51,11 @@ public class DeviceAreaConfig {
|
||||
|
||||
public static final String DATA = "data";
|
||||
public static final String ALERT_TYPES = "alert_types";
|
||||
|
||||
public boolean findAlertTypes(AlertType at) {
|
||||
if (StringUtils.isEmpty(this.alertTypes)) {
|
||||
return false;
|
||||
}
|
||||
return Splitter.on(",").splitToStream(this.alertTypes).anyMatch(d -> StringUtils.equalsIgnoreCase(d, at.name()));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -9,6 +10,7 @@ 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;
|
||||
@ -19,12 +21,14 @@ 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 org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
|
||||
@Service
|
||||
public class AlertInfoService {
|
||||
@ -32,31 +36,55 @@ public class AlertInfoService {
|
||||
|
||||
private final AlertTipService alertTipService;
|
||||
private final IDeviceAreaConfigRepository areaConfigRepository;
|
||||
private final DeviceAreaConfigService deviceAreaConfigService;
|
||||
|
||||
public AlertInfoService(AlertTipService alertTipService, IDeviceAreaConfigRepository areaConfigRepository) {
|
||||
public AlertInfoService(AlertTipService alertTipService, IDeviceAreaConfigRepository areaConfigRepository, DeviceAreaConfigService deviceAreaConfigService) {
|
||||
this.alertTipService = alertTipService;
|
||||
this.areaConfigRepository = areaConfigRepository;
|
||||
this.deviceAreaConfigService = deviceAreaConfigService;
|
||||
}
|
||||
|
||||
private List<DeviceAreaConfig> findDevice(AlertType alertType, AlertDeviceType dt, int lineId) {
|
||||
List<DeviceAreaConfig> areaConfigList = this.deviceAreaConfigService.getCache(lineId, dt);
|
||||
if (CollectionUtils.isEmpty(areaConfigList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<DeviceAreaConfig> findList = areaConfigList.stream().filter(d -> d.findAlertTypes(alertType)).toList();
|
||||
|
||||
private List<DeviceAreaConfig> findDevice(AlertType alertType, DeviceType dt, int lineId) {
|
||||
LambdaQueryWrapper<DeviceAreaConfig> qw = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
||||
/*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 areaConfigList;
|
||||
|
||||
List<DeviceAreaConfig> areaConfigList = this.areaConfigRepository.list(qw);*/
|
||||
return findList;
|
||||
}
|
||||
|
||||
public NccAlertInfo createAlert(AlertType alertType, DeviceType dt, String layoutId, MessageOrBuilder mb) {
|
||||
public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb) {
|
||||
Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class);
|
||||
Optional<DeviceAreaConfig> areaConfigOptional = this.findAreaDevice(alertType, dt, layoutId, lineId);
|
||||
return this.createAlert2(areaConfigOptional, alertType, mb);
|
||||
}
|
||||
|
||||
public NccAlertInfo createAlert2(Optional<DeviceAreaConfig> areaConfigOpt, AlertType alertType, MessageOrBuilder mb) {
|
||||
Long timestamp = DeviceStatusDataOperate.findFieldVal(mb, "timestamp", Long.class);
|
||||
int lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.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, deviceCode, deviceCode, null);
|
||||
}
|
||||
return new NccAlertInfo(createTime, alertType, lineId, String.format("%-设备[%s]", areaConfig.getAreaName(), deviceCode), deviceCode, areaConfig.getId());
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
List<DeviceAreaConfig> areaConfigList = this.findDevice(alertType, dt, lineId);
|
||||
DeviceAreaConfig areaConfig = this.findAreaDevice(areaConfigList, dt, layoutId);
|
||||
Optional<AlertTip> alertTipOptional;
|
||||
|
||||
if (Objects.isNull(areaConfig)) {
|
||||
alertTipOptional = this.alertTipService.queryOne2(alertType.name(), null);
|
||||
} else {
|
||||
@ -65,10 +93,16 @@ public class AlertInfoService {
|
||||
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, Objects.nonNull(areaConfig) ? areaConfig.getAreaName() : null, false);
|
||||
return new NccAlertInfo(createTime, alertType, Objects.nonNull(at) ? at.getId() : null, lineId, deviceCode, deviceCode, null);
|
||||
}
|
||||
|
||||
private DeviceAreaConfig findAreaDevice(List<DeviceAreaConfig> areaConfigList, DeviceType dt, String layoutId) {
|
||||
public Optional<DeviceAreaConfig> findAreaDevice(AlertType alertType, AlertDeviceType dt, String layoutId, int lineId) {
|
||||
List<DeviceAreaConfig> areaConfigList = this.findDevice(alertType, dt, lineId);
|
||||
DeviceAreaConfig areaConfig = this.findAreaDevice(areaConfigList, dt, layoutId);
|
||||
return Optional.ofNullable(areaConfig);
|
||||
}
|
||||
|
||||
private DeviceAreaConfig findAreaDevice(List<DeviceAreaConfig> areaConfigList, AlertDeviceType dt, String layoutId) {
|
||||
if (CollectionUtils.isEmpty(areaConfigList)) {
|
||||
//TODO
|
||||
return null;
|
||||
@ -85,36 +119,4 @@ public class AlertInfoService {
|
||||
}
|
||||
|
||||
|
||||
public interface AreaConfigFinder {
|
||||
|
||||
DeviceType deviceType();
|
||||
|
||||
boolean matcher(DeviceAreaConfig areaConfig, String deviceCode);
|
||||
}
|
||||
|
||||
public static class SwitchFinder implements AreaConfigFinder {
|
||||
|
||||
@Override
|
||||
public DeviceType deviceType() {
|
||||
return DeviceType.DEVICE_TYPE_SWITCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matcher(DeviceAreaConfig areaConfig, String deviceCode) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrackFinder implements AreaConfigFinder {
|
||||
|
||||
@Override
|
||||
public DeviceType deviceType() {
|
||||
return DeviceType.DEVICE_TYPE_TRACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matcher(DeviceAreaConfig areaConfig, String deviceCode) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import club.joylink.xiannccda.entity.AlertTip;
|
||||
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.xiannccda.repository.IAlertRecordRepository;
|
||||
import club.joylink.xiannccda.repository.impl.AlertTipRepository;
|
||||
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.collect.Lists;
|
||||
@ -35,9 +36,14 @@ public class AlertRecordService {
|
||||
this.alertTipRepository = alertTipRepository;
|
||||
}
|
||||
|
||||
public AlertTip confirm(Long recordId, String tipType) {
|
||||
AlertTip tip = alertTipRepository.getOne(Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, tipType));
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip));
|
||||
public AlertTip confirm(Long recordId, String tipType, Long locationId) {
|
||||
LambdaQueryWrapper<AlertTip> qw = Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, tipType);
|
||||
if (Objects.nonNull(locationId)) {
|
||||
qw.eq(AlertTip::getAreaConfigId, locationId);
|
||||
}
|
||||
AlertTip tip = alertTipRepository.getOne(qw);
|
||||
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip), "未找到对应的决策辅助信息");
|
||||
this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class)
|
||||
.set(AlertRecord::getAlertTipId, tip.getId()).set(AlertRecord::getAlarmStatus, 1)
|
||||
.eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus));
|
||||
@ -59,7 +65,7 @@ public class AlertRecordService {
|
||||
for (AlertRecord record : ars) {
|
||||
NccAlertInfo nccAlertInfo = new NccAlertInfo(record.getAlertTime(),
|
||||
AlertType.valueOf(record.getAlertType()), Objects.isNull(record.getAlertTipId()) ? null : record.getAlertTipId().intValue(), record.getLineId(),
|
||||
record.getAlertObject(), "", "", false);
|
||||
record.getAlertObject(), "", record.getAlertLocationId());
|
||||
nccAlertInfo.setId(record.getId());
|
||||
nccAlertInfo.setAlarmStatus(record.getAlarmStatus());
|
||||
alertInfos.add(nccAlertInfo);
|
||||
|
@ -1,7 +1,10 @@
|
||||
package club.joylink.xiannccda.service.config;
|
||||
|
||||
import club.joylink.xiannccda.alert.core.AlertDeviceType;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import club.joylink.xiannccda.dto.config.DeviceAreaConfigDto;
|
||||
import club.joylink.xiannccda.dto.config.DeviceAreaConfigQueryDto;
|
||||
import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
|
||||
import club.joylink.xiannccda.entity.DeviceAreaConfig;
|
||||
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.xiannccda.repository.impl.DeviceAreaConfigRepository;
|
||||
@ -12,10 +15,16 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.Lists;
|
||||
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.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -28,6 +37,21 @@ public class DeviceAreaConfigService {
|
||||
|
||||
@Autowired
|
||||
private DeviceAreaConfigRepository deviceAreaConfigRepository;
|
||||
private final static Cache<Integer, Map<AlertDeviceType, List<DeviceAreaConfig>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(5 * 60, TimeUnit.SECONDS).build();
|
||||
|
||||
|
||||
public List<DeviceAreaConfig> getCache(int lineId, AlertDeviceType dt) {
|
||||
try {
|
||||
Map<AlertDeviceType, List<DeviceAreaConfig>> configList = AREA_CONFIG_CACHE.get(lineId, () -> {
|
||||
List<DeviceAreaConfig> configs = deviceAreaConfigRepository.list(Wrappers.lambdaQuery(DeviceAreaConfig.class).eq(DeviceAreaConfig::getLineId, lineId));
|
||||
Map<AlertDeviceType, List<DeviceAreaConfig>> maper = configs.stream().collect(Collectors.groupingBy(DeviceAreaConfig::getDeviceType));
|
||||
return maper;
|
||||
});
|
||||
return configList.get(dt);
|
||||
} catch (ExecutionException e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveOrUpdate(DeviceAreaConfigDto dto) {
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getAlertTypes()), "绑定数据类型不能为空");
|
||||
@ -40,6 +64,7 @@ public class DeviceAreaConfigService {
|
||||
areaConfig.setId(dto.getId());
|
||||
}
|
||||
this.deviceAreaConfigRepository.saveOrUpdate(areaConfig);
|
||||
AREA_CONFIG_CACHE.invalidate(dto.getLineId());
|
||||
}
|
||||
|
||||
private DeviceAreaConfig convertDB(DeviceAreaConfigDto dto) {
|
||||
|
@ -5,8 +5,10 @@ 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;
|
||||
@ -33,42 +35,26 @@ public class DeviceGuardConfigService {
|
||||
@Autowired
|
||||
private IDeviceGuardConfigRepository configRepository;
|
||||
|
||||
private final static Cache<Integer, Table<DeviceType, AlertType, DeviceGuardConfig>> GUARD_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(10 * 60, TimeUnit.SECONDS).build();
|
||||
private final static Cache<Integer, GuardConfig> GUARD_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(10 * 60, TimeUnit.SECONDS).build();
|
||||
|
||||
public Map<AlertType, DeviceGuardConfig> getGuardConfig(int lineId, DeviceType deviceType) {
|
||||
/* try {
|
||||
Table<DeviceType, AlertType, DeviceGuardConfig> cacheTable = GUARD_CONFIG_CACHE.get(lineId, () -> {
|
||||
public GuardConfig getGuardConfig(int lineId) {
|
||||
try {
|
||||
GuardConfig guardConfig = GUARD_CONFIG_CACHE.get(lineId, () -> {
|
||||
LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class);
|
||||
qw.eq(DeviceGuardConfig::getLineId, lineId).eq(DeviceGuardConfig::getDeviceType, deviceType)
|
||||
.eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_USER);
|
||||
List<DeviceGuardConfig> configList = this.configRepository.list(qw);
|
||||
Table<DeviceType, AlertType, DeviceGuardConfig> table = HashBasedTable.create();
|
||||
for (DeviceGuardConfig guardConfig : configList) {
|
||||
table.put(guardConfig.getDeviceType(), guardConfig.getDeviceConfigType(), guardConfig);
|
||||
}
|
||||
return table;
|
||||
qw.eq(DeviceGuardConfig::getLineId, lineId);
|
||||
DeviceGuardConfig deviceGuardConfig = configRepository.getOne(qw, false);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(deviceGuardConfig), "未找到对应的配置数据");
|
||||
GuardConfig gc = GuardConfig.parseFrom(deviceGuardConfig.getConfigData());
|
||||
return gc;
|
||||
|
||||
});
|
||||
if (Objects.isNull(cacheTable) || cacheTable.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return cacheTable.row(deviceType);
|
||||
return guardConfig;
|
||||
} catch (ExecutionException e) {
|
||||
log.error("获取设备保护配置信息出错 msg:[{}]", e.getMessage(), e);
|
||||
return Collections.emptyMap();
|
||||
}*/
|
||||
return null;
|
||||
return GuardConfig.newBuilder().build();
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceGuardConfig buildDefault(DeviceType deviceType, AlertType configDeviceType, Operator operator, GuardUnit unit, int val) {
|
||||
/* DeviceGuardConfig guardConfig = new DeviceGuardConfig();
|
||||
guardConfig.setDeviceConfigType(configDeviceType);
|
||||
guardConfig.setDeviceType(deviceType);
|
||||
guardConfig.setDeviceUnit(unit);
|
||||
guardConfig.setVal(val);
|
||||
guardConfig.setDeviceOperator(operator);
|
||||
return guardConfig;*/
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveOrUpdate(DeviceGuardConfig dto) {
|
||||
/* LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class);
|
||||
@ -86,6 +72,7 @@ public class DeviceGuardConfigService {
|
||||
Long typeCounter = this.configRepository.count(qw);
|
||||
BusinessExceptionAssertEnum.UNIQUE_FIELD_REPEAT.assertTrue */
|
||||
this.configRepository.saveOrUpdate(dto);
|
||||
GUARD_CONFIG_CACHE.invalidateAll();
|
||||
}
|
||||
|
||||
public Page<DeviceGuardConfig> page(DeviceGuardConfigQueryDto queryDTO) {
|
||||
|
@ -3,6 +3,7 @@ package club.joylink.xiannccda.config;
|
||||
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.GuardConfigProto.GuardConfig;
|
||||
import club.joylink.xiannccda.entity.DeviceGuardConfig;
|
||||
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
|
||||
import club.joylink.xiannccda.service.config.Operator;
|
||||
@ -18,7 +19,18 @@ public class DataConfigTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
GuardConfig.Builder gb = GuardConfig.newBuilder();
|
||||
gb.setCanNotCloseTimes(60);
|
||||
gb.setCanNotOpenTimes(30);
|
||||
gb.setOrangeLedMostNums(2);
|
||||
gb.setSwitchLostTimes(13);
|
||||
gb.setRedLedMostNums(5);
|
||||
gb.setOrangeLedMostNums(5);
|
||||
gb.setSwitchLostMostNums(2);
|
||||
DeviceGuardConfig gc = new DeviceGuardConfig();
|
||||
gc.setLineId(3);
|
||||
gc.setConfigData(gb.build().toByteArray());
|
||||
this.iDeviceGuardConfigRepository.save(gc);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class DeviceStatusCheckTest {
|
||||
DeviceStatusProto.Switch.Builder s2 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 134217992);
|
||||
System.out.println(s2);
|
||||
System.out.println("-----------------");
|
||||
DeviceStatusProto.Switch.Builder s3 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 72);
|
||||
DeviceStatusProto.Switch.Builder s3 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 2);
|
||||
System.out.println(s3);
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5b065e1951829ad21e7ee7310b480547f9d32cd5
|
||||
Subproject commit aec7512cf09e451aca396de2f6e8b98e9b68c624
|
Loading…
Reference in New Issue
Block a user