|
|
|
@ -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.entity.AlarmEntity; |
|
|
|
|
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.config.vo.AlarmHandleMarkVo; |
|
|
|
|
import com.hnac.hzims.message.entity.MessagePushRecordEntity; |
|
|
|
@ -21,6 +22,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -35,6 +37,8 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
|
|
|
|
|
|
|
|
|
|
private final AlarmService alarmService; |
|
|
|
|
|
|
|
|
|
private final AlarmHandleService handleService; |
|
|
|
|
|
|
|
|
|
private final AlarmConfigService alarmConfigService; |
|
|
|
|
|
|
|
|
|
private final IStationClient stationClient; |
|
|
|
@ -49,33 +53,49 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
|
|
|
|
|
@Override |
|
|
|
|
public Boolean save(List<AlarmEntity> alarms) { |
|
|
|
|
// 步骤1.查询告警数据对应站点
|
|
|
|
|
R<List<StationEntity>> result = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList())); |
|
|
|
|
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ |
|
|
|
|
R<List<StationEntity>> stations = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList())); |
|
|
|
|
if(!stations.isSuccess() || CollectionUtil.isEmpty(stations.getData())){ |
|
|
|
|
log.error("alarm_query_station_is_null : {}",alarms.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList())); |
|
|
|
|
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" + "*"); |
|
|
|
|
// 步骤2.遍历保存告警数据
|
|
|
|
|
// 步骤5.遍历保存告警数据
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
// 告警已处理
|
|
|
|
|
if(CollectionUtil.isNotEmpty(handlers) && handlers.contains(alarm.getAlarmContext())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 根据最近5分钟的数据,做去重
|
|
|
|
|
// 告警已延后处理
|
|
|
|
|
if(CollectionUtil.isNotEmpty(delays) && delays.contains(alarm.getAlarmContext())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 近5分钟内告警重复
|
|
|
|
|
if(CollectionUtil.isNotEmpty(keys)){ |
|
|
|
|
for (String key : keys) { |
|
|
|
|
String value = stringRedisTemplate.opsForValue().get(key); |
|
|
|
|
if (value.equals(stations.get(0).getName()+alarm.getAlarmContext())){ |
|
|
|
|
if (value.equals(optional.get().getName()+alarm.getAlarmContext())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// fpd告警拼接
|
|
|
|
|
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.setStationName(stations.get(0).getName()); |
|
|
|
|
alarm.setTenantId(stations.get(0).getTenantId()); |
|
|
|
|
alarm.setCreateDept(optional.get().getCreateDept()); |
|
|
|
|
alarm.setStationName(optional.get().getName()); |
|
|
|
|
alarm.setTenantId(optional.get().getTenantId()); |
|
|
|
|
alarm.setStatus(0); |
|
|
|
|
// 步骤4.根据站点查询配置标识
|
|
|
|
|
AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType()); |
|
|
|
@ -99,7 +119,7 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
// 步骤7.发生数据至redis告警队列
|
|
|
|
|
stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm)); |
|
|
|
|