优化告警规则比较方法
This commit is contained in:
parent
6d0a0f6ac9
commit
55eb24e428
@ -44,10 +44,8 @@ public class MasterSysDataHandler implements DataHandler {
|
|||||||
ChannelHandlerContext currentctx = ctx.getCtx();
|
ChannelHandlerContext currentctx = ctx.getCtx();
|
||||||
//------------从通道中获取当前连接的IP-----------------//
|
//------------从通道中获取当前连接的IP-----------------//
|
||||||
BootNettyClientChannel channel = BootNettyClientChannelCache.get(currentctx.channel().id().asShortText());
|
BootNettyClientChannel channel = BootNettyClientChannelCache.get(currentctx.channel().id().asShortText());
|
||||||
if (ObjUtil.isEmpty(channel)) {
|
if (ObjUtil.isNotEmpty(channel)) {
|
||||||
//通道已关闭
|
//通道已关闭
|
||||||
} else {
|
|
||||||
|
|
||||||
String slaveIp = channel.getCode();
|
String slaveIp = channel.getCode();
|
||||||
String hexString = ByteUtil.byteArrayToHexString(ruleDetail104.getControl());
|
String hexString = ByteUtil.byteArrayToHexString(ruleDetail104.getControl());
|
||||||
if ("83000000".equals(hexString)) {
|
if ("83000000".equals(hexString)) {
|
||||||
|
@ -91,8 +91,6 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
DeviceAlarmRecord deviceAlarmRecord = FillingDeviceAlarmRecord(type, null, map, value);
|
DeviceAlarmRecord deviceAlarmRecord = FillingDeviceAlarmRecord(type, null, map, value);
|
||||||
//首先判断 在不在时间范围之内 判断时间在不在时间范围之内接口
|
//首先判断 在不在时间范围之内 判断时间在不在时间范围之内接口
|
||||||
Map<String, Object> timeInterval = getTimeInterval(7);
|
Map<String, Object> timeInterval = getTimeInterval(7);
|
||||||
//如果在时间范围内
|
|
||||||
if ("1".equals(timeInterval.get("beforeclock").toString())) {
|
|
||||||
//查询表中是否存在该报警记录
|
//查询表中是否存在该报警记录
|
||||||
List<DeviceAlarmRecord> alarmRecords = queryDeviceAlarmRecord(deviceAlarmRecord, timeInterval);
|
List<DeviceAlarmRecord> alarmRecords = queryDeviceAlarmRecord(deviceAlarmRecord, timeInterval);
|
||||||
//如果没有有报警记录 新增记录
|
//如果没有有报警记录 新增记录
|
||||||
@ -101,14 +99,6 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
} else if (alarmRecords.size() > 1) {
|
} else if (alarmRecords.size() > 1) {
|
||||||
this.removeById(alarmRecords.get(0).getRecordId());
|
this.removeById(alarmRecords.get(0).getRecordId());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
List<DeviceAlarmRecord> alarmRecords = queryDeviceAlarmRecord(deviceAlarmRecord, timeInterval);
|
|
||||||
if (alarmRecords.size() == 0) {
|
|
||||||
doAlarmAction(deviceAlarmRecord);
|
|
||||||
} else if (alarmRecords.size() > 1) {
|
|
||||||
this.removeById(alarmRecords.get(0).getRecordId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//紧接者判断 value (1是告警 0是正常) status 同一信号监测到报警状态消除,对当前信号所有未处理历史报警打上已处理标签,并记录消除时间
|
//紧接者判断 value (1是告警 0是正常) status 同一信号监测到报警状态消除,对当前信号所有未处理历史报警打上已处理标签,并记录消除时间
|
||||||
LambdaQueryWrapper<DeviceAlarmRecord> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<DeviceAlarmRecord> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
@ -181,34 +171,34 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
* @return 返回告警记录信息
|
* @return 返回告警记录信息
|
||||||
*/
|
*/
|
||||||
public DeviceAlarmRecord FillingDeviceAlarmRecord(String type, DeviceAlarmParameter deviceAlarmParameter,
|
public DeviceAlarmRecord FillingDeviceAlarmRecord(String type, DeviceAlarmParameter deviceAlarmParameter,
|
||||||
Map<String,Object> singaldata, String value) {
|
Map<String, Object> singalData, String value) {
|
||||||
DeviceAlarmRecord deviceAlarmRecord = new DeviceAlarmRecord();
|
DeviceAlarmRecord deviceAlarmRecord = new DeviceAlarmRecord();
|
||||||
MeterDevice device = meterDeviceMapper.selectById(singaldata.get("meterDeviceId").toString());
|
MeterDevice device = meterDeviceMapper.selectById(singalData.get("meterDeviceId").toString());
|
||||||
|
|
||||||
// 创建 SimpleDateFormat 对象,指定日期格式
|
// 创建 SimpleDateFormat 对象,指定日期格式
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
if ("yx".equals(type)) {
|
if ("yx".equals(type)) {
|
||||||
deviceAlarmRecord.setRecordId(IdUtil.fastSimpleUUID());
|
deviceAlarmRecord.setRecordId(IdUtil.fastSimpleUUID());
|
||||||
deviceAlarmRecord.setStationId(singaldata.get("stationId").toString());
|
deviceAlarmRecord.setStationId(singalData.get("stationId").toString());
|
||||||
//变电站id
|
//变电站id
|
||||||
deviceAlarmRecord.setSystemcode(singaldata.get("systemcode").toString());
|
deviceAlarmRecord.setSystemcode(singalData.get("systemcode").toString());
|
||||||
//所属系统
|
//所属系统
|
||||||
deviceAlarmRecord.setAlarmTime(DateUtil.toLocalDateTime(DateUtil.date()));
|
deviceAlarmRecord.setAlarmTime(DateUtil.toLocalDateTime(DateUtil.date()));
|
||||||
//告警时间
|
//告警时间
|
||||||
deviceAlarmRecord.setDeviceId(singaldata.get("meterDeviceId").toString());
|
deviceAlarmRecord.setDeviceId(singalData.get("meterDeviceId").toString());
|
||||||
//告警设备ID
|
//告警设备ID
|
||||||
deviceAlarmRecord.setDeviceName(singaldata.get("deviceName").toString());
|
deviceAlarmRecord.setDeviceName(singalData.get("deviceName").toString());
|
||||||
//告警设名称
|
//告警设名称
|
||||||
deviceAlarmRecord.setSignalId(singaldata.get("signalId").toString());
|
deviceAlarmRecord.setSignalId(singalData.get("signalId").toString());
|
||||||
//告警信号id
|
//告警信号id
|
||||||
deviceAlarmRecord.setSignalName(singaldata.get("signalName").toString());
|
deviceAlarmRecord.setSignalName(singalData.get("signalName").toString());
|
||||||
//告警信号名称
|
//告警信号名称
|
||||||
deviceAlarmRecord.setAlarmValue(value);
|
deviceAlarmRecord.setAlarmValue(value);
|
||||||
//告警值
|
//告警值
|
||||||
deviceAlarmRecord.setSignalUnit("");
|
deviceAlarmRecord.setSignalUnit("");
|
||||||
//值单位
|
//值单位
|
||||||
String alarmMessage = String.format("[%s]发生了%s!", singaldata.get("deviceName").toString(),
|
String alarmMessage = String.format("[%s]发生了%s!", singalData.get("deviceName").toString(),
|
||||||
singaldata.get("signalName").toString());
|
singalData.get("signalName").toString());
|
||||||
deviceAlarmRecord.setAlarmMessage(alarmMessage);
|
deviceAlarmRecord.setAlarmMessage(alarmMessage);
|
||||||
//告警信息
|
//告警信息
|
||||||
deviceAlarmRecord.setStatus("01");
|
deviceAlarmRecord.setStatus("01");
|
||||||
@ -222,27 +212,27 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
if ("yc".equals(type)) {
|
if ("yc".equals(type)) {
|
||||||
deviceAlarmRecord.setRecordId(IdUtil.fastSimpleUUID());
|
deviceAlarmRecord.setRecordId(IdUtil.fastSimpleUUID());
|
||||||
//变电站id
|
//变电站id
|
||||||
deviceAlarmRecord.setStationId(singaldata.get("stationId").toString());
|
deviceAlarmRecord.setStationId(singalData.get("stationId").toString());
|
||||||
//所属系统
|
//所属系统
|
||||||
deviceAlarmRecord.setSystemcode(singaldata.get("systemcode").toString());
|
deviceAlarmRecord.setSystemcode(singalData.get("systemcode").toString());
|
||||||
//告警时间
|
//告警时间
|
||||||
deviceAlarmRecord.setAlarmTime(DateUtil.toLocalDateTime(DateUtil.date()));
|
deviceAlarmRecord.setAlarmTime(DateUtil.toLocalDateTime(DateUtil.date()));
|
||||||
//告警设备ID
|
//告警设备ID
|
||||||
deviceAlarmRecord.setDeviceId(singaldata.get("meterDeviceId").toString());
|
deviceAlarmRecord.setDeviceId(singalData.get("meterDeviceId").toString());
|
||||||
//告警设备名称
|
//告警设备名称
|
||||||
deviceAlarmRecord.setDeviceName(singaldata.get("deviceName").toString());
|
deviceAlarmRecord.setDeviceName(singalData.get("deviceName").toString());
|
||||||
//告警信号id
|
//告警信号id
|
||||||
deviceAlarmRecord.setSignalId(singaldata.get("signalId").toString());
|
deviceAlarmRecord.setSignalId(singalData.get("signalId").toString());
|
||||||
//告警信号名称
|
//告警信号名称
|
||||||
deviceAlarmRecord.setSignalName(singaldata.get("signalName").toString());
|
deviceAlarmRecord.setSignalName(singalData.get("signalName").toString());
|
||||||
//告警类型
|
//告警类型
|
||||||
deviceAlarmRecord.setAlarmType(deviceAlarmParameter.getAlarmType());
|
deviceAlarmRecord.setAlarmType(deviceAlarmParameter.getAlarmType());
|
||||||
//告警等级
|
//告警等级
|
||||||
deviceAlarmRecord.setAlarmLevel(deviceAlarmParameter.getAlarmLevel());
|
deviceAlarmRecord.setAlarmLevel(deviceAlarmParameter.getAlarmLevel());
|
||||||
//告警值
|
//告警值
|
||||||
deviceAlarmRecord.setAlarmValue(value);
|
deviceAlarmRecord.setAlarmValue(value);
|
||||||
String sinalUnit = ObjUtil.isNotEmpty(singaldata.get("signalUnit")) ?
|
String sinalUnit = ObjUtil.isNotEmpty(singalData.get("signalUnit")) ?
|
||||||
singaldata.get("signalUnit").toString() : "";
|
singalData.get("signalUnit").toString() : "";
|
||||||
//值单位
|
//值单位
|
||||||
deviceAlarmRecord.setSignalUnit(sinalUnit);
|
deviceAlarmRecord.setSignalUnit(sinalUnit);
|
||||||
//正常范围
|
//正常范围
|
||||||
@ -250,7 +240,7 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
|
|
||||||
String alarmLevelname = getDictName(deviceAlarmParameter.getAlarmLevel(), "alarmLevel");
|
String alarmLevelname = getDictName(deviceAlarmParameter.getAlarmLevel(), "alarmLevel");
|
||||||
String alarmMessage = String.format("信号[%s]监测值为[%s]%s,达到了设置的报警阈值范围[%s],发生告警,告警级别为[%s]!",
|
String alarmMessage = String.format("信号[%s]监测值为[%s]%s,达到了设置的报警阈值范围[%s],发生告警,告警级别为[%s]!",
|
||||||
singaldata.get("signal_name").toString(), value, sinalUnit,
|
singalData.get("signal_name").toString(), value, sinalUnit,
|
||||||
deviceAlarmParameter.getAlarmCondition(), alarmLevelname
|
deviceAlarmParameter.getAlarmCondition(), alarmLevelname
|
||||||
);
|
);
|
||||||
//告警信息
|
//告警信息
|
||||||
@ -292,7 +282,6 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
* false 没有触发告警规则
|
* false 没有触发告警规则
|
||||||
*/
|
*/
|
||||||
public boolean TriggerAlarm(DeviceAlarmParameter deviceAlarmParameter, String value) {
|
public boolean TriggerAlarm(DeviceAlarmParameter deviceAlarmParameter, String value) {
|
||||||
boolean alramTrigger = true;
|
|
||||||
List<String> listSymbol = new ArrayList<>();
|
List<String> listSymbol = new ArrayList<>();
|
||||||
List<Double> values = new ArrayList<>();
|
List<Double> values = new ArrayList<>();
|
||||||
// //获取告警触发条件
|
// //获取告警触发条件
|
||||||
@ -329,34 +318,26 @@ public class DeviceAlarmRecordServiceImpl extends ServiceImpl<DeviceAlarmRecordM
|
|||||||
if (listSymbol.size() > 1) {
|
if (listSymbol.size() > 1) {
|
||||||
resultTwo = compare(values.get(1), listSymbol.get(1), values.get(2));
|
resultTwo = compare(values.get(1), listSymbol.get(1), values.get(2));
|
||||||
}
|
}
|
||||||
|
return result && resultTwo;
|
||||||
if (result && resultTwo) {
|
|
||||||
alramTrigger = true;
|
|
||||||
} else {
|
|
||||||
alramTrigger = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return alramTrigger;
|
private static boolean compare(Double value1, String operator, Double value2) {
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean compare(double value1, String operator, double value2) {
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case "<":
|
case "<":
|
||||||
return value1 < value2;
|
return value1.compareTo(value2) < 0;
|
||||||
case "<=":
|
case "<=":
|
||||||
return value1 <= value2;
|
return value1.compareTo(value2) < 0 || value1.compareTo(value2) == 0;
|
||||||
case ">":
|
case ">":
|
||||||
return value1 > value2;
|
return value1.compareTo(value2) > 0;
|
||||||
case ">=":
|
case ">=":
|
||||||
return value1 >= value2;
|
return value1.compareTo(value2) > 0 || value1.compareTo(value2) == 0;
|
||||||
case "==":
|
case "==":
|
||||||
return value1 == value2;
|
|
||||||
case "!=":
|
|
||||||
return value1 != value2;
|
|
||||||
case "=":
|
case "=":
|
||||||
return value1 == value2;
|
return value1.compareTo(value2) == 0;
|
||||||
|
case "!=":
|
||||||
|
return value1.compareTo(value2) != 0;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unsupported comparison operator: " + operator);
|
throw new IllegalArgumentException("错误的告警规则: " + operator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user