处理上下限插入更小的
@Override
public int handleDealAlerm(FunAlerm funAlerm) {
AlermHandleHistory handleRecord = new AlermHandleHistory();
handleRecord.setAlermId(funAlerm.getId());
handleRecord.setIgnoreTime(funAlerm.getIgnoreTime());
handleRecord.setContent(funAlerm.getDealDescription());
handleRecord.setCreateTime(new Date());
Long deviceparamId = funAlerm.getDeviceparamId();
if(ObjectUtils.isEmpty(deviceparamId)){
//厂掉线告警
handleRecord.setIgnoreLimit(new BigDecimal(Double.MAX_VALUE));
handleRecord.setIgnoreType(1);
}
else{
handleRecord.setIgnoreLimit(new BigDecimal(funAlerm.getIgnoreLimit()));
//获取参数不同告警级别的上下限
//需要判断是数值型还是状态型参数
//数值型告警需要判断设置的是上限还是下限忽略值
List<SysDeviceParamLimit> sysDeviceParamLimits = deviceParamLimitMapper.selectByDeviceParamId(deviceparamId);
//没有设置过上下限,直接以当前设置的忽略值和时长为准,直接保存;如果有设置过上下限,则判断上面的内容
if(sysDeviceParamLimits != null &&sysDeviceParamLimits.size() > 0){
SysDeviceParamLimit paramLimit = sysDeviceParamLimits.get(0);
if(paramLimit.getLowLimit() == paramLimit.getUpLimit() &&
(paramLimit.getUpLimit() == 0 || paramLimit.getUpLimit() == 1)){
//这是状态性告警
}
else{
//这是数值型告警
Float value;
Set<Float> upLimitList = new HashSet<>();
Set<Float> lowLimitList = new HashSet<>();
for (SysDeviceParamLimit limit: sysDeviceParamLimits) {
value = limit.getUpLimit();
if(value != null){
upLimitList.add(value);
}
value = limit.getLowLimit();
if(value != null){
lowLimitList.add(value);
}
}
Double ignoreLimit = funAlerm.getIgnoreLimit();
double upMin = Collections.min(upLimitList);
double lowMax = Collections.min(lowLimitList);
if(upLimitList.size() > 0 && ignoreLimit > upMin){
//大于上限的最小值
handleRecord.setIgnoreType(1);
}
else if(lowLimitList.size() > 0 && ignoreLimit < lowMax){
//小于下限的最大值
handleRecord.setIgnoreType(0);
}
else{
//设置的值不符合要求,返回
return -1;
}
}
}
}
alermHandleHistoryMapper.insertAlermHandleHistory(handleRecord);
funAlerm.setStatus(3L);
return funAlermMapper.updateFunAlerm(funAlerm);
}