diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java index 1f18d55..9ece78b 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java @@ -8,6 +8,8 @@ import java.util.List; */ public interface AbnormalAlarmConstant { + List INTERRUPT_LIST = Arrays.asList("13","14"); + List TYPE_LIST = Arrays.asList("3","2","5","10","13","14"); List LONG_TYPE_LIST = Arrays.asList(3L,2L,5L,10L,13L,14L); diff --git a/hzims-service/operational/pom.xml b/hzims-service/operational/pom.xml index e015f6c..13d036a 100644 --- a/hzims-service/operational/pom.xml +++ b/hzims-service/operational/pom.xml @@ -169,6 +169,7 @@ org.springblade blade-user-api + 5.0.1.RELEASE diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java index 759feab..da37623 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java @@ -1,8 +1,8 @@ package com.hnac.hzims.operational.alert.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.BusinessMessageDTO; -import com.hnac.hzims.message.dto.MessagePushRecordDto; import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; @@ -33,8 +33,6 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; import java.util.stream.Collectors; /** @@ -59,61 +57,77 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl stations = stationService.list(); if(CollectionUtil.isEmpty(stations)){ return; } + // 查询告警数据: 间隔3分钟 SoeQueryConditionByStation query = new SoeQueryConditionByStation(); query.setTypes(AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST); query.setStationIds(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); Calendar calendar = Calendar.getInstance(); query.setEndTime(LocalDateTime.parse(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); - calendar.add(Calendar.MINUTE,-2); + calendar.add(Calendar.MINUTE,-3); query.setBeginTime(LocalDateTime.parse(DateUtil.format(calendar.getTime() , DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); query.setNeedPage(false); - log.error("alarm_data_handle_param : {}",query); + query.setPage(1); + query.setLimit(100000); Result> result = soeClient.getByStationsAndTime(query); // 未查询到告警信息 - if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData().getRecords())){ + if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())) { return; } - log.error("alarm_data_handle_begin_result : {}",result.getData().getRecords()); // 遍历告警信息 - List list = new ArrayList<>(result.getData().getRecords().stream().sorted(Comparator.comparing(SoeData::getTs).reversed()) - .collect(Collectors.toMap(o -> o.getStation() + o.getSoeType(), Function.identity(), (o1, o2) -> o1)).values()); - log.error("alarm_data_handle_end_result : {}",list); - list.forEach(item -> { - AbnormalAlarmEntity queryEntity = this.baseMapper.getAbnormalAlarm(item.getStation(),item.getSoeType()); - boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); - String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); - if(ObjectUtil.isEmpty(queryEntity)){ - AbnormalAlarmEntity entity = new AbnormalAlarmEntity(); - entity.setStationId(item.getStation()); - entity.setStationName(stationName); - entity.setRealId(item.getRealId()); - entity.setSoeExplain(item.getSoeExplain()); - entity.setType(item.getSoeType()); - entity.setStartTime(item.getTs()); - entity.setEndTime(null); - entity.setStatus(0); - if(flag){ - entity.setStartTime(null); - entity.setEndTime(item.getTs()); - entity.setStatus(1); - } - // 保存告警信息 - this.save(entity); + result.getData().getRecords().forEach(item -> { + if(!AbnormalAlarmConstant.INTERRUPT_LIST.contains(item.getSoeType())){ return; } + this.interrupt(stations,item); + }); + + // 历史数据处理 + this.saveHistoryAlarm(stations,result.getData().getRecords()); + } + + /** + * 中断、异常数据处理 + * @param stations + * @param item + */ + private void interrupt(List stations,SoeData item) { + // 查询中断数据 + AbnormalAlarmEntity queryEntity = this.baseMapper.getAbnormalAlarm(item.getStation(),item.getSoeType()); + // 是否为中断恢复 + boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); + // 站点名称 + String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); + // 不存在记录进行保存 + if(ObjectUtil.isEmpty(queryEntity)){ + AbnormalAlarmEntity entity = new AbnormalAlarmEntity(); + entity.setStationId(item.getStation()); + entity.setStationName(stationName); + entity.setRealId(item.getRealId()); + entity.setSoeExplain(item.getSoeExplain()); + entity.setType(item.getSoeType()); + entity.setStartTime(item.getTs()); + entity.setEndTime(null); + entity.setStatus(0); + if(flag){ + entity.setStartTime(null); + entity.setEndTime(item.getTs()); + entity.setStatus(1); + } + // 保存告警信息 + this.save(entity); + // 存在记录进行修改 + }else{ queryEntity.setSoeExplain(item.getSoeExplain()); - queryEntity.setStationName(stationName); - queryEntity.setType(item.getSoeType()); queryEntity.setStartTime(queryEntity.getStartTime()); queryEntity.setUpdateTime(new Date()); queryEntity.setEndTime(null); @@ -123,60 +137,46 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl this.saveHistoryAlarm(result.getData().getRecords(),stations)); - } - - /** - * 查询实时告警数据 - * @return - */ - @Override - public List getAbnormalAlarmList() { - List alarmList = this.baseMapper.getAbnormalAlarmList(); - if(CollectionUtil.isEmpty(alarmList)){ - return new ArrayList<>(); } - return alarmList; } /** - * 保存告警历史信息 + * 历史数据处理 + * + * @param stations * @param list - * @return */ - private String saveHistoryAlarm(List list,List stations) { - list.forEach(item -> { - Date ts = DateUtil.parse(DateUtil.format(item.getTs(),DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMAT); - // 历史数据异常查询 - HistoryAbnormalAlarmEntity queryEntity = this.historyAbnormalAlarmService.getAbnormalAlarm(item.getStation(),item.getSoeType()); - // 数据中断恢复 - boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); - String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); - if(ObjectUtil.isEmpty(queryEntity) || !flag){ - HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); - entity.setAlarmId(item.getId()); - entity.setStationId(item.getStation()); - entity.setStationName(stationName); - entity.setRealId(item.getRealId()); - entity.setSoeExplain(item.getSoeExplain()); - entity.setType(item.getSoeType()); - entity.setStartTime(ts); - entity.setStatus(0); - this.historyAbnormalAlarmService.save(entity); - // 消息推送 - this.sendAlarmMessage(Collections.singletonList(entity),stations); + private void saveHistoryAlarm(List stations, List list) { + List historys = historyAbnormalAlarmService.list(Wrappers.lambdaQuery() + .in(HistoryAbnormalAlarmEntity::getAlarmId,list.stream().map(SoeData::getId).collect(Collectors.toList())) + ); + Set explainSet = new HashSet<>(); + list.forEach(item->{ + if(CollectionUtil.isNotEmpty(historys) && historys.stream().map(HistoryAbnormalAlarmEntity::getAlarmId).collect(Collectors.toList()).contains(item.getId())){ return; } - queryEntity.setSoeExplain(item.getSoeExplain()); - queryEntity.setUpdateTime(new Date()); - queryEntity.setEndTime(ts); - queryEntity.setStatus(1); - this.historyAbnormalAlarmService.updateById(queryEntity); + if(explainSet.contains(item.getSoeExplain())){ + return; + } + HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); + String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); + entity.setAlarmId(item.getId()); + entity.setStationId(item.getStation()); + entity.setStationName(stationName); + entity.setRealId(item.getRealId()); + entity.setSoeExplain(item.getSoeExplain()); + entity.setType(item.getSoeType()); + entity.setStartTime(item.getTs()); + if(AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType())){ + entity.setStatus(1); + }else{ + entity.setStatus(1); + } + this.historyAbnormalAlarmService.save(entity); + // 相同告警只允许添加一次,发送一次消息 + explainSet.add(item.getSoeExplain()); + this.sendAlarmMessage(Collections.singletonList(entity),stations); }); - return "success"; } /** @@ -203,12 +203,13 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl users = this.parentAuthUser(depts.get(0)); if(CollectionUtil.isEmpty(users)){ + log.error("alarmmessagestation {} user is null",entity.getStationId()); return; } BusinessMessageDTO message = new BusinessMessageDTO(); message.setDeptId(depts.get(0)); message.setBusinessClassify("warning"); - message.setUserIds(users.stream().map(o->String.valueOf(o.getId())).collect(Collectors.joining(","))); + message.setUserIds(users.stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); message.setTaskId(entity.getId()); @@ -237,11 +238,25 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl dept = sysClient.getDept(deptId); if(dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())){ - R> parents = userClient.userListByDeptId(dept.getData().getParentId()); + R> parents = userClient.userByDeptId("200000",deptId); if(parents.isSuccess() && CollectionUtil.isNotEmpty(parents.getData())){ - users.addAll(parents.getData().stream().filter(o->!users.stream().map(User::getId).collect(Collectors.toList()).contains(o.getId())).collect(Collectors.toList())); + users.addAll(parents.getData()); } } return users; } + + /** + * 查询实时告警数据 + * @return + */ + @Override + public List getAbnormalAlarmList() { + List alarmList = this.baseMapper.getAbnormalAlarmList(); + if(CollectionUtil.isEmpty(alarmList)){ + return new ArrayList<>(); + } + return alarmList; + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index af62210..6f1508b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -1532,7 +1532,7 @@ public class HydropowerServiceImpl implements HydropowerService { @Override public List area(Long deptId) { // 查询水电站站点 - List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), HomePageConstant.HYDROPOWER_SERVETYPE); + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), null); if (CollectionUtil.isEmpty(stations)) { return new ArrayList<>(); }