From 4dd8d3bc4c01f96c5d10e3571a07b3774b1a42b1 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 23 May 2024 11:39:12 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E5=A4=84=E7=90=86=E9=99=90?= =?UTF-8?q?=E5=88=B61=E5=A4=A9=E4=B8=8D=E9=87=8D=E5=A4=8D=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitor/service/impl/AlarmSaveServiceImpl.java | 54 +++++++++++++++------- .../hzims/alarm/show/mapper/AlarmHandleMapper.java | 4 ++ .../hzims/alarm/show/mapper/AlarmHandleMapper.xml | 21 +++++++++ .../alarm/show/service/AlarmHandleService.java | 4 ++ .../show/service/impl/AlarmHandleServiceImpl.java | 28 +++++++++-- 5 files changed, 90 insertions(+), 21 deletions(-) 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 15564c3..97633b9 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 @@ -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 alarms) { // 步骤1.查询告警数据对应站点 - R> result = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList())); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + R> 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 handlers = handleService.sameDayContent(); + // 步骤3.查询延后未完成的告警 + List delays = handleService.incompleteContent(); + // 步骤4.近5分钟内告警 Set keys = stringRedisTemplate.keys("hzims:queue:filter:alarm" + "*"); - // 步骤2.遍历保存告警数据 + // 步骤5.遍历保存告警数据 alarms.forEach(alarm->{ - List stations = result.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(stations)){ - return; + // 未匹配到站点 + Optional 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)); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java index 2f4527c..c80c634 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java @@ -21,4 +21,8 @@ public interface AlarmHandleMapper extends UserDataScopeBaseMapper selectHandlePage(IPage page, @Param("param") HandleQueryVo param); List handles(@Param("start") String start,@Param("end") String end); + + List sameDayContent(@Param("start") String start,@Param("end") String end); + + List incompleteContent(@Param("end") String end); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml index 971f958..110909c 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml @@ -40,4 +40,25 @@ AND (HANDLER.DELAY_TIME > #{end} OR HANDLER.DELAY_TIME IS NULL) + + + diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java index e196455..b06840b 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java @@ -25,4 +25,8 @@ public interface AlarmHandleService extends BaseService { List handleUser(); List handles(); + + List sameDayContent(); + + List incompleteContent(); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java index 7fd7cb4..0a954e2 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java +++ b/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 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 incompleteContent() { + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + return this.baseMapper.incompleteContent(end); + } }