调整代码
This commit is contained in:
parent
85f76ca4b0
commit
f4826d9b30
@ -1,7 +1,5 @@
|
|||||||
package club.joylink.xiannccda.alert.core;
|
package club.joylink.xiannccda.alert.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.collect.HashBasedTable;
|
import com.google.common.collect.HashBasedTable;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Table;
|
import com.google.common.collect.Table;
|
||||||
@ -11,9 +9,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@ -23,7 +19,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class AlertDataSource {
|
public class AlertDataSource {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存已经报警的设备
|
* 保存已经报警的设备
|
||||||
* <p>
|
* <p>
|
||||||
@ -39,25 +34,20 @@ public class AlertDataSource {
|
|||||||
|
|
||||||
public synchronized static AlertDataSource getInstance() {
|
public synchronized static AlertDataSource getInstance() {
|
||||||
if (Objects.isNull(dataSource)) {
|
if (Objects.isNull(dataSource)) {
|
||||||
return new AlertDataSource();
|
return dataSource = new AlertDataSource();
|
||||||
}
|
}
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 报警监控任务(循环监测式报警)
|
|
||||||
*/
|
|
||||||
Map<String, AlertMonitoringTask> amtMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
public void clearAlertDataMsg(Integer lineId) {
|
public void clearAlertDataMsg(Integer lineId) {
|
||||||
DEVICE_ALTER_TABLE.clear();
|
DEVICE_ALTER_TABLE.row(lineId).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean putAlterDevice(Integer lineId, String customName, String deviceName) {
|
public boolean putAlterDevice(Integer lineId, String customName, String deviceName) {
|
||||||
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
||||||
if (Objects.isNull(detail)) {
|
if (Objects.isNull(detail)) {
|
||||||
detail = new AlertTableDetail(false);
|
detail = new AlertTableDetail();
|
||||||
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
||||||
}
|
}
|
||||||
return detail.add(deviceName);
|
return detail.add(deviceName);
|
||||||
@ -84,44 +74,12 @@ public class AlertDataSource {
|
|||||||
public void removeAlterDevice(Integer lineId, String customName, String deviceName) {
|
public void removeAlterDevice(Integer lineId, String customName, String deviceName) {
|
||||||
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
|
||||||
if (Objects.isNull(detail)) {
|
if (Objects.isNull(detail)) {
|
||||||
detail = new AlertTableDetail(false);
|
detail = new AlertTableDetail();
|
||||||
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
||||||
}
|
}
|
||||||
detail.remove(deviceName);
|
detail.remove(deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needMostShow(Integer 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);
|
|
||||||
DEVICE_ALTER_TABLE.put(lineId, customName, detail);
|
|
||||||
}
|
|
||||||
// if (detail.mostShower && detail.mostSize() >= val) {
|
|
||||||
// //已经报警过了且超过了阈值
|
|
||||||
// return false;
|
|
||||||
// } else
|
|
||||||
if (detail.mostShower && detail.mostSize() < val) {
|
|
||||||
//已经报警过了,但小于阈值
|
|
||||||
detail.setMostShower(false);
|
|
||||||
return false;
|
|
||||||
} else if (detail.mostSize() >= val) {
|
|
||||||
//超过阈值
|
|
||||||
detail.setMostShower(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
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 List<String> findAllWarnDeviceForList(Integer lineId, String customeName) {
|
public List<String> findAllWarnDeviceForList(Integer lineId, String customeName) {
|
||||||
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customeName);
|
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customeName);
|
||||||
@ -134,21 +92,13 @@ public class AlertDataSource {
|
|||||||
|
|
||||||
public static class AlertTableDetail {
|
public static class AlertTableDetail {
|
||||||
|
|
||||||
public AlertTableDetail(boolean shower) {
|
public AlertTableDetail() {
|
||||||
this.mostShower = shower;
|
this.deviceCodes = Lists.newLinkedList();
|
||||||
this.deviceCodes = Lists.newArrayList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private boolean mostShower;
|
|
||||||
@Getter
|
@Getter
|
||||||
private List<String> deviceCodes;
|
private List<String> deviceCodes;
|
||||||
|
|
||||||
public int mostSize() {
|
|
||||||
return this.deviceCodes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean add(String deviceCode) {
|
public boolean add(String deviceCode) {
|
||||||
if (this.contains(deviceCode)) {
|
if (this.contains(deviceCode)) {
|
||||||
return false;
|
return false;
|
||||||
@ -158,11 +108,6 @@ public class AlertDataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getAllDeviceCodes() {
|
|
||||||
return Joiner.on(StringPool.COMMA).skipNulls().join(this.deviceCodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(String deviceCode) {
|
public boolean contains(String deviceCode) {
|
||||||
return this.deviceCodes.contains(deviceCode);
|
return this.deviceCodes.contains(deviceCode);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
|
|||||||
import club.joylink.xiannccda.service.AlertInfoService;
|
import club.joylink.xiannccda.service.AlertInfoService;
|
||||||
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
|
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
|
||||||
import club.joylink.xiannccda.vo.AreaConfigVO;
|
import club.joylink.xiannccda.vo.AreaConfigVO;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -70,7 +73,7 @@ public class AxleLedMostMonitorListener implements AlertSourceEventListener<LedM
|
|||||||
List<String> warnDeviceList = alertDataSource.findAllWarnDeviceForList(lineIdInt, customName);
|
List<String> warnDeviceList = alertDataSource.findAllWarnDeviceForList(lineIdInt, customName);
|
||||||
if (Objects.nonNull(areaConfigVO) && deviceStatusList.stream().anyMatch(d -> d.saveAlertDataSouce) && warnDeviceList.size() >= ledThreshold) {
|
if (Objects.nonNull(areaConfigVO) && deviceStatusList.stream().anyMatch(d -> d.saveAlertDataSouce) && warnDeviceList.size() >= ledThreshold) {
|
||||||
//发布大面积
|
//发布大面积
|
||||||
String warnDevices = String.join(",", warnDeviceList);
|
String warnDevices = Joiner.on(StringPool.COMMA).skipNulls().join(warnDeviceList);
|
||||||
String alertMsg = String.format("%s-出现大面积%s设备[%s]", areaConfigVO.getAreaName(), ledName, warnDevices);
|
String alertMsg = String.format("%s-出现大面积%s设备[%s]", areaConfigVO.getAreaName(), ledName, warnDevices);
|
||||||
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(areaConfigVO.getId(), mostType, lineIdInt, LocalDateTime.now(), alertMsg, null, AlertDeviceType.DEVICE_TYPE_TRACK, false);
|
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(areaConfigVO.getId(), mostType, lineIdInt, LocalDateTime.now(), alertMsg, null, AlertDeviceType.DEVICE_TYPE_TRACK, false);
|
||||||
alertManager.emit(alertInfoMost);
|
alertManager.emit(alertInfoMost);
|
||||||
|
Loading…
Reference in New Issue
Block a user