Browse Source

#告警处理限制1天不重复报警

zhongwei
yang_shj 6 months ago
parent
commit
4dd8d3bc4c
  1. 54
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java
  2. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java
  3. 21
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml
  4. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java
  5. 28
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java

54
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java

@ -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)){
return;
// 未匹配到站点
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;
}
// 告警已延后处理
if(CollectionUtil.isNotEmpty(delays) && delays.contains(alarm.getAlarmContext())){
return;
}
// 根据最近5分钟的数据,做去重
for (String key : keys) {
String value = stringRedisTemplate.opsForValue().get(key);
if (value.equals(stations.get(0).getName()+alarm.getAlarmContext())){
return;
}
// 近5分钟内告警重复
if(CollectionUtil.isNotEmpty(keys)){
for (String key : keys) {
String value = stringRedisTemplate.opsForValue().get(key);
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));

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java

@ -21,4 +21,8 @@ public interface AlarmHandleMapper extends UserDataScopeBaseMapper<AlarmHandleEn
IPage<AlarmHandleVo> selectHandlePage(IPage<Object> page, @Param("param") HandleQueryVo param);
List<String> handles(@Param("start") String start,@Param("end") String end);
List<String> sameDayContent(@Param("start") String start,@Param("end") String end);
List<String> incompleteContent(@Param("end") String end);
}

21
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml

@ -40,4 +40,25 @@
AND (HANDLER.DELAY_TIME &gt; #{end} OR HANDLER.DELAY_TIME IS NULL)
</where>
</select>
<select id="sameDayContent" resultType="java.lang.String">
SELECT HANDLER.ALARM_CONTENT
FROM HZIMS_ALARM_HANDLE HANDLER
<where>
HANDLER.IS_DELETED = 0
AND HANDLER.HANDLE_WAY in (5,6)
<if test="start != null and end != null">
AND HANDLER.CREATE_TIME BETWEEN #{start} AND #{end}
</if>
</where>
</select>
<select id="incompleteContent" resultType="java.lang.String">
SELECT HANDLER.ALARM_CONTENT
FROM HZIMS_ALARM_HANDLE HANDLER
<where>
HANDLER.IS_DELETED = 0
AND HANDLER.HANDLE_WAY = 1
AND (HANDLER.DELAY_TIME &gt; #{end})
</where>
</select>
</mapper>

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java

@ -25,4 +25,8 @@ public interface AlarmHandleService extends BaseService<AlarmHandleEntity> {
List<User> handleUser();
List<String> handles();
List<String> sameDayContent();
List<String> incompleteContent();
}

28
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java

@ -31,10 +31,7 @@ import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -170,4 +167,27 @@ public class AlarmHandleServiceImpl extends BaseServiceImpl<AlarmHandleMapper, A
String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME);
return this.baseMapper.handles(start,end);
}
/**
* 查询近一小时处理告警的内容
* @return
*/
@Override
public List<String> sameDayContent() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY,-1);
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00";
String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME);
return this.baseMapper.sameDayContent(start,end);
}
/**
* 查询未到延后期限告警的内容
* @return
*/
@Override
public List<String> incompleteContent() {
String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME);
return this.baseMapper.incompleteContent(end);
}
}

Loading…
Cancel
Save