|
|
|
@ -1,8 +1,12 @@
|
|
|
|
|
package com.hnac.hzims.operational.alert.service.impl; |
|
|
|
|
|
|
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
|
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; |
|
|
|
|
import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; |
|
|
|
|
import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; |
|
|
|
|
import com.hnac.hzims.operational.alert.mapper.AbnormalAlarmMapper; |
|
|
|
|
import com.hnac.hzims.operational.alert.service.AbnormalAlarmService; |
|
|
|
|
import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; |
|
|
|
@ -18,9 +22,14 @@ import com.hnac.hzinfo.sdk.core.response.Result;
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
@ -32,6 +41,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 告警实现类 |
|
|
|
|
* @author ysj |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
@ -42,8 +52,14 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
|
|
|
|
|
|
|
|
|
|
private final HistoryAbnormalAlarmService historyAbnormalAlarmService; |
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
private final ISoeClient soeClient; |
|
|
|
|
|
|
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
|
|
private final IMessageClient messageClient; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 数据中断、数据异常告警 |
|
|
|
|
* @param param |
|
|
|
@ -140,8 +156,7 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
|
|
|
|
|
// 历史数据异常查询
|
|
|
|
|
HistoryAbnormalAlarmEntity queryEntity = this.historyAbnormalAlarmService.getAbnormalAlarm(item.getStation(),item.getSoeType()); |
|
|
|
|
// 数据中断恢复
|
|
|
|
|
// boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType());
|
|
|
|
|
boolean flag = true; |
|
|
|
|
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(); |
|
|
|
@ -153,6 +168,8 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
|
|
|
|
|
entity.setStartTime(ts); |
|
|
|
|
entity.setStatus(0); |
|
|
|
|
this.historyAbnormalAlarmService.save(entity); |
|
|
|
|
// 消息推送
|
|
|
|
|
this.sendAlarmMessage(Collections.singletonList(entity),stations); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Random random = new Random(); |
|
|
|
@ -167,4 +184,57 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl<AbnormalAlarmMappe
|
|
|
|
|
}); |
|
|
|
|
return "success"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 告警消息推送 |
|
|
|
|
* @param entitys |
|
|
|
|
*/ |
|
|
|
|
private void sendAlarmMessage(List<HistoryAbnormalAlarmEntity> entitys,List<StationEntity> stations) { |
|
|
|
|
if(CollectionUtil.isEmpty(entitys)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 告警等级 :事故、数据中断
|
|
|
|
|
List<HistoryAbnormalAlarmEntity> alarms = entitys.stream().filter(entity -> AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST.contains(entity.getType())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(alarms)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 查询站点用户
|
|
|
|
|
entitys.forEach(entity->{ |
|
|
|
|
if(StringUtil.isEmpty(entity.getStationId())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
List<Long> depts = stations.stream().filter(station -> station.getCode().equals(entity.getStationId())).map(StationEntity::getRefDept).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(depts)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 获取站点用户
|
|
|
|
|
R<List<User>> result = userClient.userListByDeptId(depts.get(0)); |
|
|
|
|
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
MessagePushRecordDto message = new MessagePushRecordDto(); |
|
|
|
|
message.setBusinessClassify("warning"); |
|
|
|
|
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); |
|
|
|
|
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); |
|
|
|
|
message.setTaskId(entity.getId()); |
|
|
|
|
message.setTenantId("200000"); |
|
|
|
|
message.setContent(entity.getSoeExplain()); |
|
|
|
|
message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); |
|
|
|
|
message.setPushType(MessageConstants.IMMEDIATELY); |
|
|
|
|
message.setDeptId(depts.get(0)); |
|
|
|
|
R<String> deptName = sysClient.getDeptName(depts.get(0)); |
|
|
|
|
if (deptName.isSuccess()) { |
|
|
|
|
message.setDeptName(deptName.getData()); |
|
|
|
|
} |
|
|
|
|
User admin = userClient.userByAccount("200000", "admin").getData(); |
|
|
|
|
message.setCreateDept(admin.getCreateDept()); |
|
|
|
|
message.setCreateUser(admin.getCreateUser()); |
|
|
|
|
result.getData().forEach(user->{ |
|
|
|
|
message.setPusher(String.valueOf(user.getId())); |
|
|
|
|
message.setPusherName(user.getName()); |
|
|
|
|
message.setAccount(String.valueOf(user.getId())); |
|
|
|
|
messageClient.sendMessage(message); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|