refactor(harmonic): 重构事件通知服务并迁移至系统模块
- 移除 AppNotificationService 和 SmsNotificationService 服务类 - 新增消息发送服务相关接口和实现类到系统模块 - 迁移 AsyncConfig 配置类到 cs-system 模块 - 新增事件用户关系表的 Mapper、Service 接口及实现类 - 更新 CsEventPO 添加 landPoint 字段用于存储事件落点信息 - 修改事件处理逻辑使用新的消息发送 Feign 客户端 - 集成事件原因分析功能并更新数据库字段映射 - 更新设备详情 DTO 添加 nDid 属性支持 - 优化事件通知和短信发送的消息内容格式 - 移除旧的设备消息客户端依赖并使用新服务接口
This commit is contained in:
@@ -40,6 +40,9 @@ public class DevDetailDTO {
|
||||
@ApiModelProperty(value = "设备MAC地址")
|
||||
private String devMac;
|
||||
|
||||
@ApiModelProperty(value = "nDid")
|
||||
private String nDid;
|
||||
|
||||
@ApiModelProperty(value = "监测点id集合")
|
||||
private List<String> lineList;
|
||||
}
|
||||
|
||||
@@ -846,6 +846,7 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
device.setEquipmentName(dev.getName());
|
||||
device.setEquipmentId(devId);
|
||||
device.setDevMac(po.getMac());
|
||||
device.setNDid(po.getNdid());
|
||||
device.setProjectId("/");
|
||||
device.setProjectName("/");
|
||||
device.setEngineeringid("/");
|
||||
@@ -854,6 +855,7 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
device.setEquipmentName(dev.getName());
|
||||
device.setEquipmentId(devId);
|
||||
device.setDevMac(po.getMac());
|
||||
device.setNDid(po.getNdid());
|
||||
CsLedger project = this.findDataById(dev.getPid());
|
||||
if (ObjectUtil.isNotNull(project)) {
|
||||
device.setProjectId(project.getId());
|
||||
|
||||
@@ -681,7 +681,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
||||
String dictDataCode = null;
|
||||
switch (volConType) {
|
||||
case 0:
|
||||
dictDataCode = "star";
|
||||
dictDataCode = "Trans_Business";
|
||||
break;
|
||||
case 1:
|
||||
dictDataCode = "Star_Triangle";
|
||||
|
||||
@@ -141,4 +141,7 @@ public class CsEventPO extends BaseEntity {
|
||||
*/
|
||||
@TableField(value = "advance_type")
|
||||
private String advanceType;
|
||||
|
||||
@TableField(value = "land_point")
|
||||
private String landPoint;
|
||||
}
|
||||
@@ -136,4 +136,7 @@ public class EventDetailVO {
|
||||
@ApiModelProperty("F47描述")
|
||||
private String f47;
|
||||
|
||||
@ApiModelProperty("事件落点")
|
||||
private String landPoint;
|
||||
|
||||
}
|
||||
|
||||
@@ -168,7 +168,8 @@
|
||||
b.type type,
|
||||
b.LEVEL LEVEL,
|
||||
b.location location,
|
||||
c.dev_type devType
|
||||
c.dev_type devType,
|
||||
b.land_point landPoint
|
||||
<if test="csEventUserQueryPage != null and csEventUserQueryPage.type != null and csEventUserQueryPage.type != '' and csEventUserQueryPage.type ==0">
|
||||
,d.NAME lineName
|
||||
</if>
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AppNotificationService {
|
||||
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final SendMessageUtil sendMessageUtil;
|
||||
private final DeviceMessageFeignClient deviceMessageClient;
|
||||
private final CsEventUserPOService csEventUserPOService;
|
||||
|
||||
@Async("eventNotificationExecutor")
|
||||
public void asyncSaveEventUserAndNotify(String eventId
|
||||
, List<String> eventUser
|
||||
, DevDetailDTO devDetailDto
|
||||
, LocalDateTime time
|
||||
, Integer eventType
|
||||
, Double amplitude
|
||||
, Double persistTime) {
|
||||
NoticeUserDto noticeUserDto = new NoticeUserDto();
|
||||
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||
List<CsEventUserPO> result = new ArrayList<>();
|
||||
|
||||
eventUser.forEach(item -> {
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(eventId);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
|
||||
DeviceMessageParam param = new DeviceMessageParam();
|
||||
param.setUserList(eventUser);
|
||||
param.setEventType(0);
|
||||
List<User> users = deviceMessageClient.getSendUserByType(param).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)) {
|
||||
List<String> devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
noticeUserDto.setTitle("暂态事件");
|
||||
}
|
||||
|
||||
String eventName = epdFeignClient.findByName(getTag(eventType)).getData().getShowName();
|
||||
String content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + time.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂态事件,事件类型:"
|
||||
+ eventName
|
||||
+ ",特征幅值:" + amplitude + "%"
|
||||
+ ",持续时间:" + persistTime + "s";
|
||||
noticeUserDto.setContent(content);
|
||||
payload.setType(0);
|
||||
payload.setPath("/pages/index/message1?type=" + payload.getType());
|
||||
noticeUserDto.setPayload(payload);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(noticeUserDto.getPushClientId())) {
|
||||
List<String> filteredList = noticeUserDto.getPushClientId().stream()
|
||||
.filter(s -> s != null && !s.isEmpty())
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||
noticeUserDto.setPushClientId(filteredList);
|
||||
sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(result)) {
|
||||
csEventUserPOService.saveBatch(result);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTag(Integer type) {
|
||||
String tag;
|
||||
switch (type) {
|
||||
case 1:
|
||||
tag = "Evt_Sys_DipStr";
|
||||
break;
|
||||
case 2:
|
||||
tag = "Evt_Sys_SwlStr";
|
||||
break;
|
||||
case 3:
|
||||
tag = "Evt_Sys_IntrStr";
|
||||
break;
|
||||
case 4:
|
||||
tag = "Transient";
|
||||
break;
|
||||
default:
|
||||
tag = "Un_Know";
|
||||
break;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.csdevice.api.SmsSendFeignClient;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.cssystem.api.AppMsgSetFeignClient;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class SmsNotificationService {
|
||||
private final AppMsgSetFeignClient appMsgSetFeignClient;
|
||||
private final UserFeignClient userFeignClient;
|
||||
private final SmsSendFeignClient smsSendFeignClient;
|
||||
@Value("${msg.msg_sign:南京灿能电力}")
|
||||
private String msgSign;
|
||||
|
||||
@Async("smsNotificationExecutor")
|
||||
public void asyncSendSmsNotification(String deviceId
|
||||
, DevDetailDTO devDetailDto
|
||||
, LocalDateTime eventTime
|
||||
, Double amplitude
|
||||
, Double persistTime) {
|
||||
List<String> userIdList = appMsgSetFeignClient.queryUserIdsByDeviceId(deviceId).getData();
|
||||
if (CollectionUtil.isNotEmpty(userIdList)) {
|
||||
List<User> userList = userFeignClient.getUserListByIds(userIdList).getData();
|
||||
if (CollectionUtil.isNotEmpty(userList)) {
|
||||
List<User> userList1 = userList.stream()
|
||||
.filter(item -> StrUtil.isNotBlank(item.getPhone()) && Objects.equals(item.getSmsNotice(), 1))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(userList1)) {
|
||||
String msgContent = "【" + msgSign + "】" + devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂降事件"
|
||||
+ ",特征幅值:" + amplitude + "%"
|
||||
+ ",持续时间:" + persistTime + "s";
|
||||
userList1.forEach(item -> {
|
||||
smsSendFeignClient.sendSmsSimple(item.getPhone(), msgContent, "verify_code");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,11 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.advance.api.EventCauseFeignClient;
|
||||
import com.njcn.advance.pojo.dto.EventAnalysisDTO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
@@ -33,11 +34,12 @@ import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsEventVO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsWarnDescVO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
|
||||
import com.njcn.csharmonic.service.AppNotificationService;
|
||||
import com.njcn.csharmonic.service.CsEventPOService;
|
||||
import com.njcn.csharmonic.service.CsEventUserPOService;
|
||||
import com.njcn.csharmonic.service.SmsNotificationService;
|
||||
import com.njcn.cssystem.api.MsgSendFeignClient;
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
import com.njcn.event.common.mapper.WlRmpEventDetailMapper;
|
||||
import com.njcn.event.common.service.EventAnalysisService;
|
||||
import com.njcn.event.file.component.WaveFileComponent;
|
||||
import com.njcn.event.file.component.WavePicComponent;
|
||||
import com.njcn.event.file.pojo.bo.WaveDataDetail;
|
||||
@@ -57,6 +59,7 @@ import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.EleEvtFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.system.pojo.po.EleEvtParm;
|
||||
@@ -71,7 +74,6 @@ import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -120,13 +122,9 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final WlRmpEventDetailMapper wlRmpEventDetailMapper;
|
||||
private final CsLedgerFeignClient csLedgerFeignclient;
|
||||
private final DeviceMessageFeignClient deviceMessageClient;
|
||||
private final AppNotificationService appNotificationService;
|
||||
private final SmsNotificationService smsNotificationService;
|
||||
|
||||
|
||||
@Value("${msg.msg_sign:南京灿能电力}")
|
||||
private String msgSign;
|
||||
private final EventAnalysisService eventAnalysisService;
|
||||
private final EventCauseFeignClient eventCauseFeignClient;
|
||||
private final MsgSendFeignClient msgSendFeignClient;
|
||||
|
||||
@Override
|
||||
public List<EventDetailVO> queryEventList(CsEventUserQueryParam csEventUserQueryParam) {
|
||||
@@ -393,6 +391,8 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
eventPo.setPersistTime(param.getDuration());
|
||||
eventPo.setAmplitude(param.getAmplitude() * 100);
|
||||
eventPo.setPhase(param.getPhase());
|
||||
String dropZone = eventAnalysisService.determineDropZone(String.valueOf(param.getAmplitude() * 100),String.valueOf(param.getDuration()));
|
||||
eventPo.setLandPoint(dropZone);
|
||||
this.baseMapper.insert(eventPo);
|
||||
//influxDB数据录入
|
||||
List<String> records = new ArrayList<String>();
|
||||
@@ -412,8 +412,6 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
//同步数据到 r_mp_event_detail
|
||||
insertEvent(uuid, param, time);
|
||||
|
||||
//根据设备获取主用户、子用户
|
||||
List<String> eventUser = deviceMessageClient.getEventUserByDeviceId(po.getDeviceId(),true).getData();
|
||||
//获取台账信息
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getDeviceId()).getData();
|
||||
LocalDateTime eventTime = LocalDateTime.parse(param.getStartTime(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_MS_PATTERN));
|
||||
@@ -423,7 +421,18 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
|
||||
//异步处理事件用户关系和App消息推送
|
||||
try {
|
||||
appNotificationService.asyncSaveEventUserAndNotify(uuid, eventUser, devDetailDto, time, param.getEventType(), amplitudePercent, durationSeconds);
|
||||
MsgSendParam msgSendParam = new MsgSendParam();
|
||||
msgSendParam.setEventType(1);
|
||||
msgSendParam.setType("2");
|
||||
msgSendParam.setDevId(po.getDeviceId());
|
||||
msgSendParam.setEventName(getTag(param.getEventType()));
|
||||
msgSendParam.setEventTime(eventTime);
|
||||
msgSendParam.setId(uuid);
|
||||
msgSendParam.setNDid(devDetailDto.getNDid());
|
||||
msgSendParam.setAmplitude(amplitudePercent);
|
||||
msgSendParam.setPersistTime(durationSeconds);
|
||||
msgSendParam.setDropZone(dropZone);
|
||||
msgSendFeignClient.appMsgSend(msgSendParam);
|
||||
} catch (Exception e) {
|
||||
log.error("异步保存事件用户和通知失败,事件ID: {}", uuid, e);
|
||||
}
|
||||
@@ -431,22 +440,45 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
//如果是暂降事件,异步发送短信通知
|
||||
if (param.getEventType() == 1) {
|
||||
try {
|
||||
smsNotificationService.asyncSendSmsNotification(po.getDeviceId(), devDetailDto, eventTime, amplitudePercent, durationSeconds);
|
||||
MsgSendParam msgSendParam = new MsgSendParam();
|
||||
msgSendParam.setDevId(po.getDeviceId());
|
||||
msgSendParam.setEventTime(eventTime);
|
||||
msgSendParam.setAmplitude(amplitudePercent);
|
||||
msgSendParam.setPersistTime(durationSeconds);
|
||||
msgSendParam.setDropZone(dropZone);
|
||||
msgSendFeignClient.smsMsgSend(msgSendParam);
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送短信通知失败,事件ID: {}", uuid, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(param.getWavePath())) {
|
||||
EventAnalysisDTO var1 = new EventAnalysisDTO();
|
||||
var1.setWlFilePath(param.getWavePath());
|
||||
EventAnalysisDTO dto = eventCauseFeignClient.analysisCauseAndType(var1).getData();
|
||||
List<DictData> list1 = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_REASON.getCode()).getData();
|
||||
String id1 = list1.stream()
|
||||
.filter(item -> Objects.equals(item.getAlgoDescribe(), dto.getCause()))
|
||||
.map(DictData::getId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
List<DictData> list2 = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData();
|
||||
String id2 = list2.stream()
|
||||
.filter(item -> Objects.equals(item.getAlgoDescribe(), dto.getType()))
|
||||
.map(DictData::getId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
//更新文件信息
|
||||
//先校验两份文件的名称是否一致
|
||||
this.lambdaUpdate()
|
||||
.eq(CsEventPO::getLineId,param.getMonitorId())
|
||||
.eq(CsEventPO::getStartTime,param.getStartTime())
|
||||
.set(CsEventPO::getWavePath,param.getWavePath())
|
||||
.set(CsEventPO::getAdvanceReason,id1)
|
||||
.set(CsEventPO::getAdvanceType,id2)
|
||||
.update();
|
||||
//更新文件信息
|
||||
updateEvent(param);
|
||||
updateEvent(param,id1,id2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -486,11 +518,13 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
wlRmpEventDetailMapper.insert(rmpEventDetailPO);
|
||||
}
|
||||
|
||||
public void updateEvent(CldEventParam param) {
|
||||
public void updateEvent(CldEventParam param,String advanceReason, String advanceType) {
|
||||
LambdaQueryWrapper<RmpEventDetailPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(RmpEventDetailPO::getMeasurementPointId,param.getMonitorId()).eq(RmpEventDetailPO::getStartTime,param.getStartTime());
|
||||
RmpEventDetailPO po = wlRmpEventDetailMapper.selectOne(wrapper);
|
||||
po.setWavePath(param.getWavePath());
|
||||
po.setAdvanceReason(advanceReason);
|
||||
po.setAdvanceType(advanceType);
|
||||
po.setFileFlag(1);
|
||||
wlRmpEventDetailMapper.updateById(po);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.cssystem.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.cssystem.api.fallback.MsgSendFeignClientFallbackFactory;
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_SYSTEM_BOOT, path = "/send", fallbackFactory = MsgSendFeignClientFallbackFactory.class,contextId = "send")
|
||||
public interface MsgSendFeignClient {
|
||||
|
||||
@PostMapping("/appMsgSend")
|
||||
@ApiOperation("app消息推送")
|
||||
HttpResult<Boolean> appMsgSend(@RequestBody MsgSendParam param);
|
||||
|
||||
@PostMapping("/smsMsgSend")
|
||||
@ApiOperation("短信消息推送")
|
||||
HttpResult<Boolean> smsMsgSend(@RequestBody MsgSendParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.cssystem.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.cssystem.api.MsgSendFeignClient;
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MsgSendFeignClientFallbackFactory implements FallbackFactory<MsgSendFeignClient> {
|
||||
@Override
|
||||
public MsgSendFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new MsgSendFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<Boolean> appMsgSend(MsgSendParam param) {
|
||||
log.error("{}异常,降级处理,异常为:{}","app消息推送异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<Boolean> smsMsgSend(MsgSendParam param) {
|
||||
log.error("{}异常,降级处理,异常为:{}","短信消息推送异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.cssystem.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class MsgSendParam implements Serializable {
|
||||
|
||||
@ApiModelProperty("事件类型")
|
||||
private Integer eventType;
|
||||
|
||||
@ApiModelProperty("类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty("设备id")
|
||||
private String devId;
|
||||
|
||||
@ApiModelProperty("事件名称")
|
||||
private String eventName;
|
||||
|
||||
@ApiModelProperty("事件时间")
|
||||
private LocalDateTime eventTime;
|
||||
|
||||
@ApiModelProperty("事件id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("nDid")
|
||||
private String nDid;
|
||||
|
||||
@ApiModelProperty("暂态幅值")
|
||||
private Double amplitude;
|
||||
|
||||
@ApiModelProperty("持续时间")
|
||||
private Double persistTime;
|
||||
|
||||
@ApiModelProperty("落点位置")
|
||||
private String dropZone;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.njcn.csharmonic.config;
|
||||
package com.njcn.cssystem.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.njcn.cssystem.controller.sendmsg;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
import com.njcn.cssystem.service.IMsgSendService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/send")
|
||||
@Api(tags = "消息推送")
|
||||
@AllArgsConstructor
|
||||
public class MsgSendController extends BaseController {
|
||||
|
||||
private final IMsgSendService msgSendService;
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/appMsgSend")
|
||||
@ApiOperation("app消息推送")
|
||||
public HttpResult<Boolean> appMsgSend(@RequestBody MsgSendParam param){
|
||||
String methodDescribe = getMethodDescribe("appMsgSend");
|
||||
msgSendService.sendAppNotification(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/smsMsgSend")
|
||||
@ApiOperation("短信消息推送")
|
||||
public HttpResult<Boolean> smsMsgSend(@RequestBody MsgSendParam param){
|
||||
String methodDescribe = getMethodDescribe("smsMsgSend");
|
||||
msgSendService.sendSmsForDipEvent(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.cssystem.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface CsEventUserMapper extends BaseMapper<CsEventUserPO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.cssystem.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface ICsEventUserService extends IService<CsEventUserPO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.njcn.cssystem.service;
|
||||
|
||||
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IMsgSendService {
|
||||
|
||||
void sendAppNotification(MsgSendParam param);
|
||||
|
||||
void sendSmsForDipEvent(MsgSendParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.cssystem.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.cssystem.mapper.CsEventUserMapper;
|
||||
import com.njcn.cssystem.service.ICsEventUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
@Service
|
||||
public class CsEventUserServiceImpl extends ServiceImpl<CsEventUserMapper, CsEventUserPO> implements ICsEventUserService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.njcn.cssystem.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.cssystem.api.AppMsgSetFeignClient;
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
import com.njcn.cssystem.service.ICsEventUserService;
|
||||
import com.njcn.cssystem.service.IMsgSendService;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class IMsgSendServiceImpl implements IMsgSendService {
|
||||
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final ICsEventUserService csEventUserService;
|
||||
private final SendMessageUtil sendMessageUtil;
|
||||
private final EventLogsFeignClient eventLogsFeignClient;
|
||||
private final CsLedgerFeignClient csLedgerFeignClient;
|
||||
private final AppMsgSetFeignClient appMsgSetFeignClient;
|
||||
private final UserFeignClient userFeignClient;
|
||||
private final SmsSendFeignClient smsSendFeignClient;
|
||||
private final CsLedgerFeignClient csLedgerFeignclient;
|
||||
@Value("${msg.msg_sign:南京灿能电力}")
|
||||
private String msgSign;
|
||||
|
||||
@Override
|
||||
@Async("eventNotificationExecutor")
|
||||
public void sendAppNotification(MsgSendParam param) {
|
||||
int code;
|
||||
List<User> users = new ArrayList<>();
|
||||
List<String> eventUser;
|
||||
List<String> devCodeList;
|
||||
List<String> userList = new ArrayList<>();
|
||||
List<CsEventSendMsg> csEventSendMsgList = new ArrayList<>();
|
||||
NoticeUserDto noticeUserDto = new NoticeUserDto();
|
||||
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||
String content = null;
|
||||
List<CsEventUserPO> result = new ArrayList<>();
|
||||
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(param.getNDid()).getData();
|
||||
if (devModel) {
|
||||
DevDetailDTO devDetailDto = csLedgerFeignClient.queryDevDetail(param.getDevId()).getData();
|
||||
//事件处理
|
||||
if (param.getEventType() == 1){
|
||||
param.setEventName(epdFeignClient.findByName(param.getEventName()).getData().getShowName());
|
||||
switch (param.getType()) {
|
||||
case "1":
|
||||
code = 3;
|
||||
//设备自身事件 不推送给用户,推送给业务管理
|
||||
eventUser = deviceMessageFeignClient.getEventUserByDeviceId(param.getDevId(),false).getData();
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(param.getId());
|
||||
result.add(csEventUser);
|
||||
});
|
||||
|
||||
DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
param1.setUserList(eventUser);
|
||||
param1.setEventType(2);
|
||||
users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
for (User user : users){
|
||||
userList.add(user.getDevCode());
|
||||
}
|
||||
noticeUserDto.setPushClientId(userList);
|
||||
noticeUserDto.setTitle("运行事件");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
code = 0;
|
||||
//暂态事件
|
||||
eventUser = deviceMessageFeignClient.getEventUserByDeviceId(param.getDevId(),true).getData();
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(param.getId());
|
||||
result.add(csEventUser);
|
||||
});
|
||||
DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
param1.setUserList(eventUser);
|
||||
param1.setEventType(0);
|
||||
users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
noticeUserDto.setTitle("暂态事件");
|
||||
content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + param.getEventTime().format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂态事件,事件类型:"
|
||||
+ param.getEventName()
|
||||
+ ",特征幅值:" + param.getAmplitude() + "%"
|
||||
+ ",持续时间:" + param.getPersistTime() + "s"
|
||||
+ ",落点区域:" + (Objects.isNull(param.getDropZone())?"未知":param.getDropZone());
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case "3":
|
||||
// code = 1;
|
||||
// //稳态事件
|
||||
// eventUser = getEventUser(devId,true);
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// users = getSendUser(eventUser,1);
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// noticeUserDto.setTitle("稳态事件");
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
code = 0;
|
||||
break;
|
||||
}
|
||||
//获取台账信息
|
||||
if (Objects.isNull(content)) {
|
||||
content = devDetailDto.getEngineeringName()
|
||||
+ "-" + devDetailDto.getProjectName()
|
||||
+ "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + param.getEventTime().format(DatePattern.NORM_DATETIME_MS_FORMATTER)
|
||||
+ "发生" + param.getEventName();
|
||||
}
|
||||
noticeUserDto.setContent(content);
|
||||
payload.setType(code);
|
||||
payload.setPath("/pages/index/message1?type="+payload.getType());
|
||||
noticeUserDto.setPayload(payload);
|
||||
}
|
||||
// //告警处理
|
||||
// else if (eventType == 2){
|
||||
// switch (type) {
|
||||
// case "1":
|
||||
// //Ⅰ级告警 不推送给用户,推送给业务管理
|
||||
// eventUser = getEventUser(devId,false);
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// users = getSendUser(eventUser,3);
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case "2":
|
||||
// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
// case "3":
|
||||
// //Ⅱ、Ⅲ级告警推送相关用户及业务管理员
|
||||
// eventUser = getEventUser(devId,true);
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// users = getSendUser(eventUser,3);
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// noticeUserDto.setTitle("告警事件");
|
||||
// DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(devId).getData();
|
||||
// content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生告警,告警信息:" + eventName;
|
||||
// noticeUserDto.setContent(content);
|
||||
// payload.setType(3);
|
||||
// payload.setPath("/pages/message/message?type="+payload.getType());
|
||||
// noticeUserDto.setPayload(payload);
|
||||
// }
|
||||
if (CollectionUtil.isNotEmpty(noticeUserDto.getPushClientId())) {
|
||||
List<String> filteredList = noticeUserDto.getPushClientId().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||
noticeUserDto.setPushClientId(filteredList);
|
||||
sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||
}
|
||||
}
|
||||
//记录推送日志
|
||||
for (User item : users) {
|
||||
CsEventSendMsg csEventSendMsg = new CsEventSendMsg();
|
||||
csEventSendMsg.setUserId(item.getId());
|
||||
csEventSendMsg.setEventId(param.getId());
|
||||
csEventSendMsg.setSendTime(LocalDateTime.now());
|
||||
if (Objects.isNull(item.getDevCode())){
|
||||
csEventSendMsg.setStatus(0);
|
||||
csEventSendMsg.setRemark("用户设备识别码为空");
|
||||
} else {
|
||||
csEventSendMsg.setDevCode(item.getDevCode());
|
||||
csEventSendMsg.setStatus(1);
|
||||
}
|
||||
csEventSendMsgList.add(csEventSendMsg);
|
||||
}
|
||||
eventLogsFeignClient.addLogs(csEventSendMsgList);
|
||||
//事件用户关系入库
|
||||
if (CollectionUtil.isNotEmpty(result)){
|
||||
csEventUserService.saveBatch(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("smsNotificationExecutor")
|
||||
public void sendSmsForDipEvent(MsgSendParam param) {
|
||||
try {
|
||||
List<String> userIdList = appMsgSetFeignClient.queryUserIdsByDeviceId(param.getDevId()).getData();
|
||||
if (CollectionUtil.isNotEmpty(userIdList)) {
|
||||
List<User> userList = userFeignClient.getUserListByIds(userIdList).getData();
|
||||
if (CollectionUtil.isNotEmpty(userList)) {
|
||||
List<User> userList1 = userList.stream()
|
||||
.filter(item -> StrUtil.isNotBlank(item.getPhone()) && Objects.equals(item.getSmsNotice(), 1))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(userList1)) {
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(param.getDevId()).getData();
|
||||
String msgContent = "【" + msgSign + "】" + devDetailDto.getEngineeringName()
|
||||
+ "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + param.getEventTime().format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂降事件"
|
||||
+ ",特征幅值:" + param.getAmplitude() + "%"
|
||||
+ ",持续时间:" + param.getPersistTime() + "s"
|
||||
+ ",落点区域:" + (Objects.isNull(param.getDropZone())?"未知":param.getDropZone());
|
||||
userList1.forEach(item -> {
|
||||
try {
|
||||
smsSendFeignClient.sendSmsSimple(item.getPhone(), msgContent, "verify_code");
|
||||
} catch (Exception e) {
|
||||
log.error("发送短信失败,手机号: {}", item.getPhone(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送暂降事件短信失败,设备ID: {}", param.getDevId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user