|
|
|
@ -3,13 +3,12 @@ package com.hnac.hzims.alarm.show.service.impl;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.alarm.constants.AlarmConstants; |
|
|
|
|
import com.hnac.hzims.alarm.entity.AlarmEntity; |
|
|
|
|
import com.hnac.hzims.alarm.entity.SystemAlarmEntity; |
|
|
|
|
import com.hnac.hzims.alarm.show.service.AlarmService; |
|
|
|
|
import com.hnac.hzims.alarm.show.service.MessageService; |
|
|
|
|
import com.hnac.hzims.alarm.show.service.SystemAlarmService; |
|
|
|
|
import com.hnac.hzims.equipment.feign.IEmInfoClient; |
|
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
|
import com.hnac.hzims.message.dto.MessagePushRecordDto; |
|
|
|
|
import com.hnac.hzims.alarm.vo.SystemAlarmVo; |
|
|
|
|
import com.hnac.hzims.message.fegin.IMessageClient; |
|
|
|
|
import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; |
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
@ -20,49 +19,50 @@ import org.springblade.core.log.exception.ServiceException;
|
|
|
|
|
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.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.util.*; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 等级告警实现类 |
|
|
|
|
* @author ysj |
|
|
|
|
* 华自3000告警实现类 |
|
|
|
|
* |
|
|
|
|
* @author ty |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
public class SystemAlarmServiceImpl implements SystemAlarmService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final IEmInfoClient deviceClient; |
|
|
|
|
private final MessageService messageService; |
|
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
private final IMessageClient messageClient; |
|
|
|
|
private final AlarmService alarmService; |
|
|
|
|
private final IStationClient stationClient; |
|
|
|
|
private final IStationClient stationClient; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 定时发送消息内容 |
|
|
|
|
* |
|
|
|
|
* @return String |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public String sendMessage() { |
|
|
|
|
R<List<StationEntity>> listAll = stationClient.getListAll(); |
|
|
|
|
if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){ |
|
|
|
|
throw new ServiceException("level send message is null"); |
|
|
|
|
if (!listAll.isSuccess() || CollectionUtil.isEmpty(listAll.getData())) { |
|
|
|
|
throw new ServiceException("systemAlarm send message is null"); |
|
|
|
|
} |
|
|
|
|
List<StationEntity> stations = listAll.getData(); |
|
|
|
|
Map<String,String> map = new ConcurrentHashMap<>(); |
|
|
|
|
map.put("stations",stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); |
|
|
|
|
Map<String, String> map = new ConcurrentHashMap<>(); |
|
|
|
|
map.put("stations", stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); |
|
|
|
|
map.put("soe_type", AbnormalAlarmConstant.SYSTEM_TYPE_LIST); |
|
|
|
|
return JSONObject.toJSONString(map); |
|
|
|
|
} |
|
|
|
@ -75,38 +75,43 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
|
|
|
|
|
@Override |
|
|
|
|
public void receiveMessage(String message) { |
|
|
|
|
// 对象转换
|
|
|
|
|
List<SystemAlarmEntity> alarms = JSONObject.parseArray(message, SystemAlarmEntity.class); |
|
|
|
|
if(CollectionUtil.isEmpty(alarms)){ |
|
|
|
|
List<SystemAlarmVo> alarms = JSONObject.parseArray(message, SystemAlarmVo.class); |
|
|
|
|
if (CollectionUtil.isEmpty(alarms)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
R<List<StationEntity>> listAll = stationClient.getListAll(); |
|
|
|
|
if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){ |
|
|
|
|
throw new ServiceException("level send message is null"); |
|
|
|
|
if (!listAll.isSuccess() || CollectionUtil.isEmpty(listAll.getData())) { |
|
|
|
|
throw new ServiceException("systemAlarm send message is null"); |
|
|
|
|
} |
|
|
|
|
List<StationEntity> stations = listAll.getData(); |
|
|
|
|
// 查询当天已经记录的告警
|
|
|
|
|
List<AlarmEntity> historys = alarmService.list(Wrappers.<AlarmEntity>lambdaQuery(). |
|
|
|
|
ge(AlarmEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00")); |
|
|
|
|
|
|
|
|
|
ge(AlarmEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00") |
|
|
|
|
.eq(AlarmEntity::getAlarmSource, AlarmConstants.HZ3000_ALARM)); |
|
|
|
|
// 数据过滤
|
|
|
|
|
List<AlarmEntity> entitys = alarms.stream() |
|
|
|
|
.filter(alarm -> CollectionUtil.isNotEmpty(historys) || !historys.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(alarm.getId())) |
|
|
|
|
.map(item->{ |
|
|
|
|
AlarmEntity entity = getAlarmEntity(item); |
|
|
|
|
return entity; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(entitys)){ |
|
|
|
|
.map(item -> { |
|
|
|
|
AlarmEntity entity = getAlarmEntity(item); |
|
|
|
|
if (ObjectUtils.isNotEmpty(entity)){ |
|
|
|
|
// 短信
|
|
|
|
|
CompletableFuture.runAsync(() -> messageService.message(entity)); |
|
|
|
|
// web/app消息推送
|
|
|
|
|
CompletableFuture.runAsync(() -> messageService.webAppMessage(entity)); |
|
|
|
|
// 微信公众号推送
|
|
|
|
|
CompletableFuture.runAsync(() -> messageService.weChatMessage(entity)); |
|
|
|
|
} |
|
|
|
|
return entity; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isEmpty(entitys)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 批量保存
|
|
|
|
|
alarmService.saveBatch(entitys); |
|
|
|
|
|
|
|
|
|
// 消息推送
|
|
|
|
|
CompletableFuture.runAsync(()->this.sendAlarmMessage(entitys,stations.stream().filter(station -> entitys.stream().filter(stationId -> !StringUtil.isEmpty(stationId)).map(AlarmEntity::getStationId).collect(Collectors.toList()).contains(station.getCode())).collect(Collectors.toList()))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private AlarmEntity getAlarmEntity(SystemAlarmEntity item) { |
|
|
|
|
private AlarmEntity getAlarmEntity(SystemAlarmVo item) { |
|
|
|
|
AlarmEntity entity = new AlarmEntity(); |
|
|
|
|
entity.setAlarmId(item.getId()); |
|
|
|
|
entity.setAlarmTime(DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s")); |
|
|
|
@ -115,107 +120,11 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
|
|
|
|
|
entity.setAlarmStatus(item.getSoeStatus()); |
|
|
|
|
entity.setAlarmValue(item.getOptionvals()); |
|
|
|
|
entity.setStationId(item.getStation()); |
|
|
|
|
entity.setAlarmSource(AlarmConstants.HZ3000_ALARM); |
|
|
|
|
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation()); |
|
|
|
|
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){ |
|
|
|
|
if (stationByCode.isSuccess() && ObjectUtils.isNotEmpty(stationByCode.getData())) { |
|
|
|
|
entity.setCreateDept(stationByCode.getData().getCreateDept()); |
|
|
|
|
} |
|
|
|
|
return entity; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 告警消息推送 |
|
|
|
|
* @param entitys |
|
|
|
|
*/ |
|
|
|
|
private void sendAlarmMessage(List<AlarmEntity> entitys,List<StationEntity> stations) { |
|
|
|
|
if(CollectionUtil.isEmpty(entitys)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// // 告警等级 :一级、二级告警发送通知
|
|
|
|
|
// List<HistoryLevelAlarmEntity> alarms = entitys.stream().filter(entity -> AbnormalAlarmConstant.LEVEL_LIST.contains(entity.getAlarmLevel())).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; |
|
|
|
|
} |
|
|
|
|
// app,web消息推送
|
|
|
|
|
this.sendMessageByWebApp(depts.get(0),entity); |
|
|
|
|
// 短信推送
|
|
|
|
|
//this.message(depts.get(0),entity);
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void sendMessageByWebApp(Long dept,AlarmEntity entity) { |
|
|
|
|
// 获取站点用户
|
|
|
|
|
R<List<User>> result = userClient.userListByDeptId(dept); |
|
|
|
|
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.getAlarmContext()); |
|
|
|
|
message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); |
|
|
|
|
message.setPushType(MessageConstants.IMMEDIATELY); |
|
|
|
|
message.setDeptId(dept); |
|
|
|
|
message.setCreateDept(dept); |
|
|
|
|
R<String> deptName = sysClient.getDeptName(dept); |
|
|
|
|
if (deptName.isSuccess()) { |
|
|
|
|
message.setDeptName(deptName.getData()); |
|
|
|
|
} |
|
|
|
|
message.setCreateDept(dept); |
|
|
|
|
result.getData().forEach(user->{ |
|
|
|
|
message.setPusher(String.valueOf(user.getId())); |
|
|
|
|
message.setPusherName(user.getName()); |
|
|
|
|
message.setAccount(String.valueOf(user.getId())); |
|
|
|
|
message.setCreateUser(user.getId()); |
|
|
|
|
messageClient.sendMessage(message); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 发送短信 |
|
|
|
|
* @param dept |
|
|
|
|
* @param entity |
|
|
|
|
*/ |
|
|
|
|
private void message(Long dept,AlarmEntity entity) { |
|
|
|
|
// 获取站点用户
|
|
|
|
|
R<List<User>> result = userClient.relationUserListByRoleAlias("200000",dept,"projectManager"); |
|
|
|
|
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.getAlarmContext()); |
|
|
|
|
message.setTypes(Collections.singletonList(MessageConstants.SMS_PUSH)); |
|
|
|
|
message.setPushType(MessageConstants.IMMEDIATELY); |
|
|
|
|
message.setDeptId(dept); |
|
|
|
|
R<String> deptName = sysClient.getDeptName(dept); |
|
|
|
|
if (deptName.isSuccess()) { |
|
|
|
|
message.setDeptName(deptName.getData()); |
|
|
|
|
} |
|
|
|
|
User admin = userClient.userByAccount("200000", "admin").getData(); |
|
|
|
|
message.setCreateDept(admin.getCreateDept()); |
|
|
|
|
message.setCreateUser(admin.getId()); |
|
|
|
|
result.getData().forEach(user->{ |
|
|
|
|
message.setPusher(String.valueOf(user.getId())); |
|
|
|
|
message.setPusherName(user.getName()); |
|
|
|
|
message.setAccount(String.valueOf(user.getId())); |
|
|
|
|
messageClient.sendMessage(message); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|