|
|
@ -6,6 +6,7 @@ import com.hnac.hzims.alarm.config.constants.AlarmConstants; |
|
|
|
import com.hnac.hzims.alarm.config.service.AlarmConfigService; |
|
|
|
import com.hnac.hzims.alarm.config.service.AlarmConfigService; |
|
|
|
import com.hnac.hzims.alarm.config.entity.AlarmEntity; |
|
|
|
import com.hnac.hzims.alarm.config.entity.AlarmEntity; |
|
|
|
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; |
|
|
|
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; |
|
|
|
|
|
|
|
import com.hnac.hzims.alarm.show.service.AlarmHandleService; |
|
|
|
import com.hnac.hzims.alarm.show.service.AlarmService; |
|
|
|
import com.hnac.hzims.alarm.show.service.AlarmService; |
|
|
|
import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; |
|
|
|
import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; |
|
|
|
import com.hnac.hzims.message.entity.MessagePushRecordEntity; |
|
|
|
import com.hnac.hzims.message.entity.MessagePushRecordEntity; |
|
|
@ -21,6 +22,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -35,6 +37,8 @@ public class AlarmSaveServiceImpl implements AlarmSaveService { |
|
|
|
|
|
|
|
|
|
|
|
private final AlarmService alarmService; |
|
|
|
private final AlarmService alarmService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final AlarmHandleService handleService; |
|
|
|
|
|
|
|
|
|
|
|
private final AlarmConfigService alarmConfigService; |
|
|
|
private final AlarmConfigService alarmConfigService; |
|
|
|
|
|
|
|
|
|
|
|
private final IStationClient stationClient; |
|
|
|
private final IStationClient stationClient; |
|
|
@ -49,41 +53,55 @@ public class AlarmSaveServiceImpl implements AlarmSaveService { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Boolean save(List<AlarmEntity> alarms) { |
|
|
|
public Boolean save(List<AlarmEntity> alarms) { |
|
|
|
// 步骤1.查询告警数据对应站点
|
|
|
|
// 步骤1.查询告警数据对应站点
|
|
|
|
R<List<StationEntity>> result = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList())); |
|
|
|
R<List<StationEntity>> stations = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList())); |
|
|
|
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ |
|
|
|
if(!stations.isSuccess() || CollectionUtil.isEmpty(stations.getData())){ |
|
|
|
log.error("alarm_query_station_is_null : {}",alarms.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList())); |
|
|
|
log.error("alarm_query_station_is_null : {}",alarms.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList())); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 步骤2.查询当天处理的告警
|
|
|
|
|
|
|
|
List<String> handlers = handleService.sameDayContent(); |
|
|
|
|
|
|
|
// 步骤3.查询延后未完成的告警
|
|
|
|
|
|
|
|
List<String> delays = handleService.incompleteContent(); |
|
|
|
|
|
|
|
// 步骤4.近5分钟内告警
|
|
|
|
Set<String> keys = stringRedisTemplate.keys("hzims:queue:filter:alarm" + "*"); |
|
|
|
Set<String> keys = stringRedisTemplate.keys("hzims:queue:filter:alarm" + "*"); |
|
|
|
// 步骤2.遍历保存告警数据
|
|
|
|
// 步骤5.遍历保存告警数据
|
|
|
|
alarms.forEach(alarm->{ |
|
|
|
alarms.forEach(alarm->{ |
|
|
|
List<StationEntity> stations = result.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).collect(Collectors.toList()); |
|
|
|
// 未匹配到站点
|
|
|
|
if(CollectionUtil.isEmpty(stations)){ |
|
|
|
Optional<StationEntity> optional = stations.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).findFirst(); |
|
|
|
|
|
|
|
if(!optional.isPresent()){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 根据最近5分钟的数据,做去重
|
|
|
|
// 告警已处理
|
|
|
|
|
|
|
|
if(handlers.contains(alarm.getAlarmContext())){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 告警已延后处理
|
|
|
|
|
|
|
|
if(delays.contains(alarm.getAlarmContext())){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 近5分钟内告警重复
|
|
|
|
for (String key : keys) { |
|
|
|
for (String key : keys) { |
|
|
|
String value = stringRedisTemplate.opsForValue().get(key); |
|
|
|
String value = stringRedisTemplate.opsForValue().get(key); |
|
|
|
if (value.equals(stations.get(0).getName()+alarm.getAlarmContext())){ |
|
|
|
if (value.equals(optional.get().getName()+alarm.getAlarmContext())){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// fpd告警拼接
|
|
|
|
// fpd告警拼接站点名称
|
|
|
|
if(AlarmConstants.EARLY_WARNING.equals(alarm.getAlarmSource())){ |
|
|
|
if(AlarmConstants.EARLY_WARNING.equals(alarm.getAlarmSource())){ |
|
|
|
alarm.setAlarmContext(stations.get(0).getName() + "." + alarm.getAlarmContext()); |
|
|
|
alarm.setAlarmContext(optional.get().getName() + "." + alarm.getAlarmContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
// 步骤3.站点参数设置
|
|
|
|
// 站点参数设置
|
|
|
|
alarm.setCreateDept(stations.get(0).getCreateDept()); |
|
|
|
alarm.setCreateDept(optional.get().getCreateDept()); |
|
|
|
alarm.setStationName(stations.get(0).getName()); |
|
|
|
alarm.setStationName(optional.get().getName()); |
|
|
|
alarm.setTenantId(stations.get(0).getTenantId()); |
|
|
|
alarm.setTenantId(optional.get().getTenantId()); |
|
|
|
alarm.setStatus(0); |
|
|
|
alarm.setStatus(0); |
|
|
|
// 步骤4.根据站点查询配置标识
|
|
|
|
// 根据站点查询配置标识
|
|
|
|
AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType()); |
|
|
|
AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType()); |
|
|
|
if(ObjectUtil.isEmpty(mark)){ |
|
|
|
if(ObjectUtil.isEmpty(mark)){ |
|
|
|
log.error("alarm_obtain_mark_is_null : {}",alarm.getAlarmId()); |
|
|
|
log.error("alarm_obtain_mark_is_null : {}",alarm.getAlarmId()); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 步骤5.告警处理标识赋值
|
|
|
|
// 告警处理标识赋值
|
|
|
|
alarm.setIsRightTabulation(mark.getIsRightTabulation()); |
|
|
|
alarm.setIsRightTabulation(mark.getIsRightTabulation()); |
|
|
|
alarm.setIsBroadcast(mark.getIsBroadcast()); |
|
|
|
alarm.setIsBroadcast(mark.getIsBroadcast()); |
|
|
|
alarm.setIsMask(mark.getIsMask()); |
|
|
|
alarm.setIsMask(mark.getIsMask()); |
|
|
@ -92,16 +110,16 @@ public class AlarmSaveServiceImpl implements AlarmSaveService { |
|
|
|
alarm.setIsSmallBell(mark.getIsSmallBell()); |
|
|
|
alarm.setIsSmallBell(mark.getIsSmallBell()); |
|
|
|
alarm.setIsShortMessage(mark.getIsShortMessage()); |
|
|
|
alarm.setIsShortMessage(mark.getIsShortMessage()); |
|
|
|
alarm.setIsWxMessage(mark.getIsWxMessage()); |
|
|
|
alarm.setIsWxMessage(mark.getIsWxMessage()); |
|
|
|
// 步骤6.保存当日告警数据
|
|
|
|
// 保存告警
|
|
|
|
boolean isSave = alarmService.save(alarm); |
|
|
|
boolean isSave = alarmService.save(alarm); |
|
|
|
if(!isSave){ |
|
|
|
if(!isSave){ |
|
|
|
log.error("alarm_save_fail : {}",alarm.getAlarmId()); |
|
|
|
log.error("alarm_save_fail : {}",alarm.getAlarmId()); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
String key="hzims:queue:filter:alarm"+alarm.getAlarmId(); |
|
|
|
String key="hzims:queue:filter:alarm"+alarm.getAlarmId(); |
|
|
|
stringRedisTemplate.opsForValue().set(key,stations.get(0).getName()+alarm.getAlarmContext()); |
|
|
|
stringRedisTemplate.opsForValue().set(key,optional.get().getName()+alarm.getAlarmContext()); |
|
|
|
stringRedisTemplate.expire(key,5, TimeUnit.MINUTES); |
|
|
|
stringRedisTemplate.expire(key,5, TimeUnit.MINUTES); |
|
|
|
// 步骤7.发生数据至redis告警队列
|
|
|
|
// 发送告警数据进行消息推送队列
|
|
|
|
stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm)); |
|
|
|
stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|