代码调整
This commit is contained in:
parent
0241414ac5
commit
6a03551107
@ -7,6 +7,7 @@ import club.joylink.xiannccda.ats.warn.BlueDisplayAlertEvent;
|
||||
import club.joylink.xiannccda.ats.warn.SwitchAndTrackLedAlertEvent;
|
||||
import club.joylink.xiannccda.ats.warn.SwitchLostAlertEvent;
|
||||
import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener;
|
||||
import club.joylink.xiannccda.ats.warn.SwitchLostAlertMonitoringTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
|
@ -1,13 +1,13 @@
|
||||
package club.joylink.xiannccda.alert.core;
|
||||
|
||||
import club.joylink.xiannccda.event.EventEmitter;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.common.collect.Tables;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@ -30,7 +30,7 @@ public class AlertManager extends EventEmitter {
|
||||
* <p>
|
||||
* val = 设备code
|
||||
*/
|
||||
private static final Table<String, String, List<String>> DEVICE_ALTER_TABLE = Tables.synchronizedTable(HashBasedTable.create());
|
||||
private static final Table<String, String, AlertTableDetail> DEVICE_ALTER_TABLE = Tables.synchronizedTable(HashBasedTable.create());
|
||||
/**
|
||||
* 报警监控任务(循环监测式报警)
|
||||
*/
|
||||
@ -41,7 +41,7 @@ public class AlertManager extends EventEmitter {
|
||||
ScheduledExecutorService Executor = Executors.newScheduledThreadPool(1);
|
||||
boolean started = false;
|
||||
final int interval = 100; // 执行器默认间隔,单位ms
|
||||
|
||||
|
||||
|
||||
private AlertManager(String id) {
|
||||
super(id);
|
||||
@ -51,33 +51,25 @@ public class AlertManager extends EventEmitter {
|
||||
return getInstance("default");
|
||||
}
|
||||
|
||||
public int getAlertDeviceCount(String lineId, String deviceType) {
|
||||
List<String> deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType);
|
||||
if (CollectionUtils.isEmpty(deviceNames)) {
|
||||
return 0;
|
||||
|
||||
public boolean putAlterDevice(String lineId, String customName, String deviceName) {
|
||||
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
||||
if (Objects.isNull(detail)) {
|
||||
detail = new AlertTableDetail(false);
|
||||
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
||||
}
|
||||
return deviceNames.size();
|
||||
return detail.add(deviceName);
|
||||
}
|
||||
|
||||
public boolean putAlterDevice(String lineId, String deviceType, String deviceName) {
|
||||
List<String> deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType);
|
||||
if (CollectionUtils.isEmpty(deviceNames)) {
|
||||
deviceNames = new ArrayList<>();
|
||||
DEVICE_ALTER_TABLE.put(lineId, deviceType, deviceNames);
|
||||
public void removeAlterDevice(String lineId, String customName, String deviceName) {
|
||||
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
||||
if (Objects.isNull(detail)) {
|
||||
detail = new AlertTableDetail(false);
|
||||
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
||||
}
|
||||
if (deviceNames.contains(deviceName)) {
|
||||
return false;
|
||||
}
|
||||
deviceNames.add(deviceName);
|
||||
return true;
|
||||
detail.remove(deviceName);
|
||||
}
|
||||
|
||||
public void removeAlterDevice(String lineId, String deviceType, String deviceName) {
|
||||
List<String> deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType);
|
||||
if (CollectionUtils.isNotEmpty(deviceNames)) {
|
||||
deviceNames.remove(deviceName);
|
||||
}
|
||||
}
|
||||
|
||||
public static AlertManager getInstance(String id) {
|
||||
return MANAGER_MAP.computeIfAbsent(id, k -> new AlertManager(id));
|
||||
@ -115,4 +107,31 @@ public class AlertManager extends EventEmitter {
|
||||
0, interval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AlertTableDetail {
|
||||
|
||||
public AlertTableDetail(boolean shower) {
|
||||
this.mostShower = shower;
|
||||
this.deviceCodes = Lists.newArrayList();
|
||||
}
|
||||
|
||||
private boolean mostShower;
|
||||
private List<String> deviceCodes;
|
||||
|
||||
public boolean add(String deviceCode) {
|
||||
if (this.contains(deviceCode)) {
|
||||
this.deviceCodes.add(deviceCode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(String deviceCode) {
|
||||
return this.deviceCodes.contains(deviceCode);
|
||||
}
|
||||
|
||||
public void remove(String deviceCode) {
|
||||
this.deviceCodes.remove(deviceCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package club.joylink.xiannccda.ats.warn;
|
||||
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform.Builder;
|
||||
import com.google.protobuf.GeneratedMessageV3;
|
||||
|
||||
public class PlatformAlertEvent extends DeviceAlertEvent<Platform.Builder> {
|
||||
|
||||
public PlatformAlertEvent(Builder source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package club.joylink.xiannccda.ats.warn;
|
||||
|
||||
import club.joylink.xiannccda.alert.AlertDetailFactory;
|
||||
import club.joylink.xiannccda.alert.NccAlertInfo;
|
||||
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.dto.protos.AlertConstProto.AlertType;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
|
||||
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
|
||||
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
|
||||
import com.google.protobuf.GeneratedMessageV3.Builder;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public class PlatformAlertListener implements AlertSourceEventListener<PlatformAlertEvent> {
|
||||
|
||||
private AlertDetailFactory alertDetailFactory;
|
||||
|
||||
public PlatformAlertListener(AlertDetailFactory alertDetailFactory) {
|
||||
this.alertDetailFactory = alertDetailFactory;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(PlatformAlertEvent event) {
|
||||
Platform.Builder platformBuild = event.getSource();
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,18 +1,8 @@
|
||||
package club.joylink.xiannccda.ats.warn;
|
||||
|
||||
import club.joylink.xiannccda.alert.AlertDetailFactory;
|
||||
import club.joylink.xiannccda.alert.NccAlertInfo;
|
||||
import club.joylink.xiannccda.alert.SwitchLostAlertMonitoringTask;
|
||||
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.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.LayoutGraphicsProto.Section;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -29,8 +19,8 @@ public class SwitchLostAlertListener implements AlertSourceEventListener<SwitchL
|
||||
@Override
|
||||
public void accept(SwitchLostAlertEvent event) {
|
||||
Switch.Builder switchBuild = event.getSource();
|
||||
boolean isTurning = /*switchBuild.getIpSingleSwitchStusLocked() &&*/ switchBuild.getIpSingleSwitchStusLostIndication();
|
||||
if (isTurning) {
|
||||
boolean isLost = /*switchBuild.getIpSingleSwitchStusLocked() &&*/ switchBuild.getIpSingleSwitchStusLostIndication();
|
||||
if (isLost) {
|
||||
this.monitoringTask2.putSwitchIfNotExist(switchBuild);
|
||||
} else {
|
||||
this.monitoringTask2.removeSwitch(switchBuild);
|
||||
|
@ -1,26 +1,36 @@
|
||||
package club.joylink.xiannccda.alert;
|
||||
package club.joylink.xiannccda.ats.warn;
|
||||
|
||||
import club.joylink.xiannccda.alert.AlertDetailFactory;
|
||||
import club.joylink.xiannccda.alert.NccAlertInfo;
|
||||
import club.joylink.xiannccda.alert.core.AlertManager;
|
||||
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
|
||||
import club.joylink.xiannccda.alert.util.AlertUtil;
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.ConfigDeviceType;
|
||||
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.entity.DeviceGuardConfig;
|
||||
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
|
||||
|
||||
private AlertDetailFactory alertDetailFactory;
|
||||
private DeviceGuardConfigService configService;
|
||||
|
||||
public SwitchLostAlertMonitoringTask(AlertDetailFactory alertDetailFactory) {
|
||||
public SwitchLostAlertMonitoringTask(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService) {
|
||||
this.alertDetailFactory = alertDetailFactory;
|
||||
this.configService = configService;
|
||||
}
|
||||
|
||||
private final static String DEVICE_TYPE_NAME = Switch.getDescriptor().getName();
|
||||
@ -56,8 +66,11 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
|
||||
public void run() {
|
||||
AlertManager alertManager = AlertManager.getDefault();
|
||||
for (Builder savedSwitchBuild : this.deviceMap.values()) {
|
||||
boolean saveTurning = /*savedSwitchBuild.getIpSingleSwitchStusLocked() &&*/ savedSwitchBuild.getIpSingleSwitchStusLostIndication();
|
||||
if (saveTurning && this.remainTimeOut(savedSwitchBuild.getReceiveTime(), 13)) {
|
||||
Map<ConfigDeviceType, DeviceGuardConfig> configMaper = configService.getGuardConfig(savedSwitchBuild.getLineId(), DeviceType.DEVICE_TYPE_SWITCH);
|
||||
DeviceGuardConfig guardConfig = configMaper.get(ConfigDeviceType.SWITCH_LOST);
|
||||
|
||||
boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication();
|
||||
if (saveIsLost && guardConfig.getDeviceOperator().contrast(guardConfig.getDeviceUnit(), savedSwitchBuild.getReceiveTime(), guardConfig.getVal())) {
|
||||
//失表超时
|
||||
String lineIdStr = String.valueOf(savedSwitchBuild.getLineId());
|
||||
if (alertManager.putAlterDevice(lineIdStr, DEVICE_TYPE_NAME, savedSwitchBuild.getId())) {
|
@ -32,6 +32,6 @@ public class DeviceGuardConfigDto {
|
||||
}
|
||||
|
||||
public enum ConfigDeviceType {
|
||||
SWITCH_LOST, SWITCH_LOST_MOST, AXLE_LED_RED_MOST
|
||||
SWITCH_LOST, SWITCH_LOST_MOST, AXLE_LED_RED, AXLE_LED_RED_MOST, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ public class DeviceGuardConfigService {
|
||||
|
||||
public Page<DeviceGuardConfig> page(DeviceGuardConfigQueryDto queryDTO) {
|
||||
LambdaQueryWrapper<DeviceGuardConfig> queryWrapper = Wrappers.lambdaQuery(DeviceGuardConfig.class);
|
||||
queryWrapper.eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_USER);
|
||||
if (Objects.nonNull(queryDTO.getLineId())) {
|
||||
|
||||
queryWrapper.eq(DeviceGuardConfig::getLineId, queryDTO.getLineId());
|
||||
|
@ -6,7 +6,7 @@ public enum Operator {
|
||||
|
||||
GT {
|
||||
@Override
|
||||
public boolean contrastTimes(GuardUnit unit, int source, int val) {
|
||||
public boolean contrast(GuardUnit unit, Long source, int val) {
|
||||
if (unit == GuardUnit.NUMS) {
|
||||
return source > val;
|
||||
} else if (unit == GuardUnit.TIMES) {
|
||||
@ -17,7 +17,7 @@ public enum Operator {
|
||||
},
|
||||
GE {
|
||||
@Override
|
||||
public boolean contrastTimes(GuardUnit unit, int source, int val) {
|
||||
public boolean contrast(GuardUnit unit, Long source, int val) {
|
||||
if (unit == GuardUnit.NUMS) {
|
||||
return source >= val;
|
||||
} else if (unit == GuardUnit.TIMES) {
|
||||
@ -28,7 +28,7 @@ public enum Operator {
|
||||
},
|
||||
LT {
|
||||
@Override
|
||||
public boolean contrastTimes(GuardUnit unit, int source, int val) {
|
||||
public boolean contrast(GuardUnit unit, Long source, int val) {
|
||||
if (unit == GuardUnit.NUMS) {
|
||||
return source < val;
|
||||
} else if (unit == GuardUnit.TIMES) {
|
||||
@ -39,6 +39,6 @@ public enum Operator {
|
||||
},
|
||||
;
|
||||
|
||||
public abstract boolean contrastTimes(GuardUnit unit, int source, int val);
|
||||
public abstract boolean contrast(GuardUnit unit, Long source, int val);
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,8 @@ public class DataConfigTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
InitData initData = new InitData();
|
||||
initData.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
|
||||
List<DeviceRef> refs = Lists.newArrayList();
|
||||
refs.add(new DeviceRef(ConfigDeviceType.SWITCH_LOST, new Oper(Operator.LT, GuardUnit.TIMES)));
|
||||
refs.add(new DeviceRef(ConfigDeviceType.SWITCH_LOST_MOST, new Oper(Operator.GE, GuardUnit.NUMS)));
|
||||
initData.setRefs(refs);
|
||||
System.out.println(JSON.toJSONString(initData, Feature.WriteEnumsUsingName));
|
||||
|
||||
//道岔失表
|
||||
DeviceGuardConfig guardConfig = new DeviceGuardConfig();
|
||||
guardConfig.setLineId(3);
|
||||
guardConfig.setDeviceType(DeviceType.DEVICE_TYPE_SWITCH);
|
||||
@ -39,6 +33,7 @@ public class DataConfigTest {
|
||||
guardConfig.setDeviceConfigType(ConfigDeviceType.SWITCH_LOST);
|
||||
guardConfig.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
|
||||
|
||||
//大面积道岔失表
|
||||
DeviceGuardConfig guardConfig2 = new DeviceGuardConfig();
|
||||
guardConfig2.setLineId(3);
|
||||
guardConfig2.setDeviceType(DeviceType.DEVICE_TYPE_SWITCH);
|
||||
@ -47,49 +42,47 @@ public class DataConfigTest {
|
||||
guardConfig2.setDeviceConfigType(ConfigDeviceType.SWITCH_LOST_MOST);
|
||||
guardConfig2.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
|
||||
|
||||
//红灯带
|
||||
DeviceGuardConfig guardConfig3 = new DeviceGuardConfig();
|
||||
guardConfig3.setLineId(3);
|
||||
guardConfig3.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
|
||||
guardConfig3.setDeviceOperator(Operator.GE);
|
||||
guardConfig3.setDeviceUnit(GuardUnit.NUMS);
|
||||
guardConfig3.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED_MOST);
|
||||
guardConfig3.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED);
|
||||
guardConfig3.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
|
||||
//大面积红灯带
|
||||
DeviceGuardConfig guardConfig4 = new DeviceGuardConfig();
|
||||
guardConfig4.setLineId(3);
|
||||
guardConfig4.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
|
||||
guardConfig4.setDeviceOperator(Operator.GE);
|
||||
guardConfig4.setDeviceUnit(GuardUnit.NUMS);
|
||||
guardConfig4.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED_MOST);
|
||||
guardConfig4.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
|
||||
|
||||
DeviceGuardConfig guardConfig5 = new DeviceGuardConfig();
|
||||
guardConfig5.setLineId(3);
|
||||
guardConfig5.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
|
||||
guardConfig5.setDeviceOperator(Operator.GE);
|
||||
guardConfig5.setDeviceUnit(GuardUnit.NUMS);
|
||||
guardConfig5.setDeviceConfigType(ConfigDeviceType.AXLE_LED_ORANGE);
|
||||
guardConfig5.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
|
||||
//大面积红灯带
|
||||
DeviceGuardConfig guardConfig6 = new DeviceGuardConfig();
|
||||
guardConfig6.setLineId(3);
|
||||
guardConfig6.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
|
||||
guardConfig6.setDeviceOperator(Operator.GE);
|
||||
guardConfig6.setDeviceUnit(GuardUnit.NUMS);
|
||||
guardConfig6.setDeviceConfigType(ConfigDeviceType.AXLE_LED_ORANGE_MOST);
|
||||
guardConfig6.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
|
||||
|
||||
this.iDeviceGuardConfigRepository.save(guardConfig);
|
||||
this.iDeviceGuardConfigRepository.save(guardConfig2);
|
||||
this.iDeviceGuardConfigRepository.save(guardConfig3);
|
||||
this.iDeviceGuardConfigRepository.save(guardConfig4);
|
||||
this.iDeviceGuardConfigRepository.save(guardConfig5);
|
||||
this.iDeviceGuardConfigRepository.save(guardConfig6);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class InitData {
|
||||
|
||||
private DeviceType deviceType;
|
||||
private List<DeviceRef> refs;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class DeviceRef {
|
||||
|
||||
public DeviceRef(ConfigDeviceType deviceConfig, Oper opers) {
|
||||
this.deviceConfig = deviceConfig;
|
||||
this.opers = opers;
|
||||
}
|
||||
|
||||
private ConfigDeviceType deviceConfig;
|
||||
|
||||
private Oper opers;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class Oper {
|
||||
|
||||
public Oper(Operator operator, GuardUnit unit) {
|
||||
this.operator = operator;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
private Operator operator;
|
||||
private GuardUnit unit;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user