Browse Source

#故障消息推送

zhongwei
yang_shj 1 year ago
parent
commit
ec64e7e8c2
  1. 2
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java
  2. 1
      hzims-service/operational/pom.xml
  3. 181
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java
  4. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java

2
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 { public interface AbnormalAlarmConstant {
List<String> INTERRUPT_LIST = Arrays.asList("13","14");
List<String> TYPE_LIST = Arrays.asList("3","2","5","10","13","14"); List<String> TYPE_LIST = Arrays.asList("3","2","5","10","13","14");
List<Long> LONG_TYPE_LIST = Arrays.asList(3L,2L,5L,10L,13L,14L); List<Long> LONG_TYPE_LIST = Arrays.asList(3L,2L,5L,10L,13L,14L);

1
hzims-service/operational/pom.xml

@ -169,6 +169,7 @@
<dependency> <dependency>
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>
<artifactId>blade-user-api</artifactId> <artifactId>blade-user-api</artifactId>
<version>5.0.1.RELEASE</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 --> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->

181
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; 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.MessageConstants;
import com.hnac.hzims.message.dto.BusinessMessageDTO; 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.message.fegin.IMessageClient;
import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant;
import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity;
@ -33,8 +33,6 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -59,61 +57,77 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
private final IMessageClient messageClient; private final IMessageClient messageClient;
/** /**
* 数据中断数据异常告警 * 故障中断异常告警数据处理
* @param param * @param param
*/ */
@Override @Override
public void alarmDataHandle(String param) { public void alarmDataHandle(String param) {
// 查询代运维站点 // 查询站点站点
List<StationEntity> stations = stationService.list(); List<StationEntity> stations = stationService.list();
if(CollectionUtil.isEmpty(stations)){ if(CollectionUtil.isEmpty(stations)){
return; return;
} }
// 查询告警数据: 间隔3分钟
SoeQueryConditionByStation query = new SoeQueryConditionByStation(); SoeQueryConditionByStation query = new SoeQueryConditionByStation();
query.setTypes(AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST); query.setTypes(AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST);
query.setStationIds(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); query.setStationIds(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()));
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
query.setEndTime(LocalDateTime.parse(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); 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.setBeginTime(LocalDateTime.parse(DateUtil.format(calendar.getTime() , DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER));
query.setNeedPage(false); query.setNeedPage(false);
log.error("alarm_data_handle_param : {}",query); query.setPage(1);
query.setLimit(100000);
Result<HzPage<SoeData>> result = soeClient.getByStationsAndTime(query); Result<HzPage<SoeData>> 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; return;
} }
log.error("alarm_data_handle_begin_result : {}",result.getData().getRecords());
// 遍历告警信息 // 遍历告警信息
List<SoeData> list = new ArrayList<>(result.getData().getRecords().stream().sorted(Comparator.comparing(SoeData::getTs).reversed()) result.getData().getRecords().forEach(item -> {
.collect(Collectors.toMap(o -> o.getStation() + o.getSoeType(), Function.identity(), (o1, o2) -> o1)).values()); if(!AbnormalAlarmConstant.INTERRUPT_LIST.contains(item.getSoeType())){
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);
return; return;
} }
this.interrupt(stations,item);
});
// 历史数据处理
this.saveHistoryAlarm(stations,result.getData().getRecords());
}
/**
* 中断异常数据处理
* @param stations
* @param item
*/
private void interrupt(List<StationEntity> 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.setSoeExplain(item.getSoeExplain());
queryEntity.setStationName(stationName);
queryEntity.setType(item.getSoeType());
queryEntity.setStartTime(queryEntity.getStartTime()); queryEntity.setStartTime(queryEntity.getStartTime());
queryEntity.setUpdateTime(new Date()); queryEntity.setUpdateTime(new Date());
queryEntity.setEndTime(null); queryEntity.setEndTime(null);
@ -123,60 +137,46 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
queryEntity.setStatus(1); queryEntity.setStatus(1);
} }
this.updateById(queryEntity); this.updateById(queryEntity);
});
// 异步保存历史告警
CompletableFuture.supplyAsync(()-> this.saveHistoryAlarm(result.getData().getRecords(),stations));
}
/**
* 查询实时告警数据
* @return
*/
@Override
public List<String> getAbnormalAlarmList() {
List<String> alarmList = this.baseMapper.getAbnormalAlarmList();
if(CollectionUtil.isEmpty(alarmList)){
return new ArrayList<>();
} }
return alarmList;
} }
/** /**
* 保存告警历史信息 * 历史数据处理
*
* @param stations
* @param list * @param list
* @return
*/ */
private String saveHistoryAlarm(List<SoeData> list,List<StationEntity> stations) { private void saveHistoryAlarm(List<StationEntity> stations, List<SoeData> list) {
list.forEach(item -> { List<HistoryAbnormalAlarmEntity> historys = historyAbnormalAlarmService.list(Wrappers.<HistoryAbnormalAlarmEntity>lambdaQuery()
Date ts = DateUtil.parse(DateUtil.format(item.getTs(),DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMAT); .in(HistoryAbnormalAlarmEntity::getAlarmId,list.stream().map(SoeData::getId).collect(Collectors.toList()))
// 历史数据异常查询 );
HistoryAbnormalAlarmEntity queryEntity = this.historyAbnormalAlarmService.getAbnormalAlarm(item.getStation(),item.getSoeType()); Set<String> explainSet = new HashSet<>();
// 数据中断恢复 list.forEach(item->{
boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); if(CollectionUtil.isNotEmpty(historys) && historys.stream().map(HistoryAbnormalAlarmEntity::getAlarmId).collect(Collectors.toList()).contains(item.getId())){
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);
return; return;
} }
queryEntity.setSoeExplain(item.getSoeExplain()); if(explainSet.contains(item.getSoeExplain())){
queryEntity.setUpdateTime(new Date()); return;
queryEntity.setEndTime(ts); }
queryEntity.setStatus(1); HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity();
this.historyAbnormalAlarmService.updateById(queryEntity); 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<AbnormalAlarmMappe
} }
List<User> users = this.parentAuthUser(depts.get(0)); List<User> users = this.parentAuthUser(depts.get(0));
if(CollectionUtil.isEmpty(users)){ if(CollectionUtil.isEmpty(users)){
log.error("alarmmessagestation {} user is null",entity.getStationId());
return; return;
} }
BusinessMessageDTO message = new BusinessMessageDTO(); BusinessMessageDTO message = new BusinessMessageDTO();
message.setDeptId(depts.get(0)); message.setDeptId(depts.get(0));
message.setBusinessClassify("warning"); 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.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey());
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription());
message.setTaskId(entity.getId()); message.setTaskId(entity.getId());
@ -237,11 +238,25 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
} }
R<Dept> dept = sysClient.getDept(deptId); R<Dept> dept = sysClient.getDept(deptId);
if(dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())){ if(dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())){
R<List<User>> parents = userClient.userListByDeptId(dept.getData().getParentId()); R<List<User>> parents = userClient.userByDeptId("200000",deptId);
if(parents.isSuccess() && CollectionUtil.isNotEmpty(parents.getData())){ 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 users;
} }
/**
* 查询实时告警数据
* @return
*/
@Override
public List<String> getAbnormalAlarmList() {
List<String> alarmList = this.baseMapper.getAbnormalAlarmList();
if(CollectionUtil.isEmpty(alarmList)){
return new ArrayList<>();
}
return alarmList;
}
} }

2
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 @Override
public List<AppHydropowerStationVo> area(Long deptId) { public List<AppHydropowerStationVo> area(Long deptId) {
// 查询水电站站点 // 查询水电站站点
List<StationEntity> stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), HomePageConstant.HYDROPOWER_SERVETYPE); List<StationEntity> stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), null);
if (CollectionUtil.isEmpty(stations)) { if (CollectionUtil.isEmpty(stations)) {
return new ArrayList<>(); return new ArrayList<>();
} }

Loading…
Cancel
Save