From c92b1d16d5c70519d2a9b8480b6431c009e07538 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Sun, 7 Apr 2024 17:06:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=91=8A=E8=AD=A6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarm/monitor/service/impl/AlarmSaveServiceImpl.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java index 91e9ea4..fef9ffc 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java @@ -7,8 +7,10 @@ import com.hnac.hzims.alarm.config.entity.AlarmEntity; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import com.hnac.hzims.alarm.show.service.AlarmService; import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; +import com.hnac.hzims.message.entity.MessagePushRecordEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzims.safeproduct.constants.RedisConstants; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; @@ -18,6 +20,8 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -49,12 +53,20 @@ public class AlarmSaveServiceImpl implements AlarmSaveService { log.error("alarm_query_station_is_null : {}",alarms.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList())); return false; } + Set keys = stringRedisTemplate.keys("hzims:queue:filter:alarm" + "*"); // 步骤2.遍历保存告警数据 alarms.forEach(alarm->{ List stations = result.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).collect(Collectors.toList()); if(CollectionUtil.isEmpty(stations)){ return; } + //根据最近5分钟的数据,做去重 + for (String key : keys) { + String value = stringRedisTemplate.opsForValue().get(key); + if (value.equals(alarm.getAlarmContext())){ + return; + } + } // 步骤3.站点参数设置 alarm.setCreateDept(stations.get(0).getCreateDept()); alarm.setStationName(stations.get(0).getName()); @@ -81,7 +93,9 @@ public class AlarmSaveServiceImpl implements AlarmSaveService { log.error("alarm_save_fail : {}",alarm.getAlarmId()); return; } - + String key="hzims:queue:filter:alarm"+alarm.getAlarmId(); + stringRedisTemplate.opsForValue().set(key,alarm.getAlarmContext()); + stringRedisTemplate.expire(key,5, TimeUnit.MINUTES); // 步骤7.发生数据至redis告警队列 stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm)); });