告警事件解析处理
This commit is contained in:
@@ -1032,28 +1032,28 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
showName = "APF模块数据";
|
||||
break;
|
||||
case "Ds$Apf$module$01":
|
||||
showName = "模块1数据";
|
||||
showName = "APF模块1数据";
|
||||
break;
|
||||
case "Ds$Apf$module$02":
|
||||
showName = "模块2数据";
|
||||
showName = "APF模块2数据";
|
||||
break;
|
||||
case "Ds$Apf$module$03":
|
||||
showName = "模块3数据";
|
||||
showName = "APF模块3数据";
|
||||
break;
|
||||
case "Ds$Apf$module$04":
|
||||
showName = "模块4数据";
|
||||
showName = "APF模块4数据";
|
||||
break;
|
||||
case "Ds$Apf$module$05":
|
||||
showName = "模块5数据";
|
||||
showName = "APF模块5数据";
|
||||
break;
|
||||
case "Ds$Apf$module$06":
|
||||
showName = "模块6数据";
|
||||
showName = "APF模块6数据";
|
||||
break;
|
||||
case "Ds$Apf$module$07":
|
||||
showName = "模块7数据";
|
||||
showName = "APF模块7数据";
|
||||
break;
|
||||
case "Ds$Apf$module$08":
|
||||
showName = "模块8数据";
|
||||
showName = "APF模块8数据";
|
||||
break;
|
||||
case "Ds$Pqd$Stat$01":
|
||||
showName = "电网侧数据";
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.zlevent.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.zlevent.api.fallback.AlarmClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_ZL_EVENT_BOOT, path = "/alarm", fallbackFactory = AlarmClientFallbackFactory.class,contextId = "alarm")
|
||||
public interface AlarmFeignClient {
|
||||
|
||||
@PostMapping("/analysis")
|
||||
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.zlevent.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.mq.message.AppEventMessage;
|
||||
import com.njcn.zlevent.api.AlarmFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AlarmClientFallbackFactory implements FallbackFactory<AlarmFeignClient> {
|
||||
@Override
|
||||
public AlarmFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new AlarmFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> analysis(AppEventMessage appEventMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","告警数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.njcn.zlevent.controller;
|
||||
|
||||
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.mq.message.AppEventMessage;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.zlevent.service.ICsAlarmService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
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 xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/14 9:23
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/alarm")
|
||||
@Api(tags = "告警事件处理")
|
||||
@AllArgsConstructor
|
||||
public class AlarmController extends BaseController {
|
||||
|
||||
private final ICsAlarmService csAlarmService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/analysis")
|
||||
@ApiOperation("告警事件解析")
|
||||
@ApiImplicitParam(name = "appEventMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> analysis(@RequestBody AppEventMessage appEventMessage){
|
||||
String methodDescribe = getMethodDescribe("analysis");
|
||||
csAlarmService.analysis(appEventMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 告警事件表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface ICsAlarmService extends IService<CsEventPO> {
|
||||
|
||||
/**
|
||||
* 告警数据解析入库
|
||||
* @param appEventMessage 实体
|
||||
*/
|
||||
void analysis(AppEventMessage appEventMessage);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.pojo.param.EleEpdPqdParam;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.zlevent.mapper.CsEventMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
import com.njcn.zlevent.service.ICsAlarmService;
|
||||
import com.njcn.zlevent.service.ICsEventLogsService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.utils.SendEventUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 告警事件表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> implements ICsAlarmService {
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final EventServiceImpl eventService;
|
||||
private final ICsEventService csEventService;
|
||||
private final SendEventUtils sendEventUtils;
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppEventMessage appEventMessage) {
|
||||
List<CsEventPO> list1 = new ArrayList<>();
|
||||
LocalDateTime eventTime = null;
|
||||
String tag = null;
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
//获取装置id
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
|
||||
try {
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setId(id);
|
||||
csEvent.setDeviceId(po.getId());
|
||||
csEvent.setProcess(po.getProcess());
|
||||
csEvent.setCode(item.getCode());
|
||||
eventTime = eventService.timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
csEvent.setType(3);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
csEvent.setCode(item.getCode());
|
||||
list1.add(csEvent);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(list1)){
|
||||
csEventService.saveBatch(list1);
|
||||
}
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
BeanUtils.copyProperties(eleEpdPqd,updateParam);
|
||||
updateParam.setDefaultValue(item.getCode());
|
||||
epdFeignClient.update(updateParam);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setDeviceId(po.getId());
|
||||
csEventLogs.setStartTime(eventTime);
|
||||
csEventLogs.setTag(tag);
|
||||
csEventLogs.setStatus(0);
|
||||
csEventLogs.setTime(LocalDateTime.now());
|
||||
csEventLogs.setRemark(e.getMessage());
|
||||
csEventLogsService.save(csEventLogs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,10 @@ public class SendEventUtils {
|
||||
NoticeUserDto noticeUserDto = new NoticeUserDto();
|
||||
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||
String content;
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
List<CsEventUserPO> result = new ArrayList<>();
|
||||
//事件处理
|
||||
if (eventType == 1){
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
switch (type) {
|
||||
case "1":
|
||||
code = 2;
|
||||
@@ -159,6 +159,7 @@ public class SendEventUtils {
|
||||
else if (eventType == 2){
|
||||
switch (type) {
|
||||
case "1":
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
//Ⅰ级告警 不推送给用户,推送给业务管理
|
||||
users = appUserFeignClient.getAdminInfo().getData();
|
||||
noticeUserDto.setPushClientId(Collections.singletonList(users.get(0).getDevCode()));
|
||||
@@ -172,6 +173,7 @@ public class SendEventUtils {
|
||||
});
|
||||
break;
|
||||
case "2":
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
case "3":
|
||||
//Ⅱ、Ⅲ级告警推送相关用户及业务管理员
|
||||
users = getEventUser(devId);
|
||||
@@ -192,7 +194,7 @@ public class SendEventUtils {
|
||||
}
|
||||
noticeUserDto.setTitle("告警事件");
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(devId).getData();
|
||||
content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生告警,告警故障编码为:" + eventName;
|
||||
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());
|
||||
@@ -285,23 +287,4 @@ public class SendEventUtils {
|
||||
return users;
|
||||
}
|
||||
|
||||
// public String getPath( Integer type) {
|
||||
//
|
||||
// switch (type) {
|
||||
// case 0:
|
||||
// return "/pages/message/transient";
|
||||
// case 1:
|
||||
// return "/pages/message/steady";
|
||||
// case 2:
|
||||
// return "/pages/message/run";
|
||||
// case 3:
|
||||
// return "/pages/message/report";
|
||||
//
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// return "";
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.njcn.redis.pojo.enums.RedisKeyEnum;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.RocketMqLogFeignClient;
|
||||
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||
import com.njcn.zlevent.api.AlarmFeignClient;
|
||||
import com.njcn.zlevent.api.EventFeignClient;
|
||||
import com.njcn.zlevent.api.WaveFeignClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -48,6 +49,8 @@ public class AppEventConsumer extends EnhanceConsumerMessageHandler<AppEventMess
|
||||
|
||||
@Resource
|
||||
private WaveFeignClient waveFeignClient;
|
||||
@Resource
|
||||
private AlarmFeignClient alarmFeignClient;
|
||||
|
||||
@Override
|
||||
protected void handleMessage(AppEventMessage appEventMessage) {
|
||||
@@ -59,6 +62,7 @@ public class AppEventConsumer extends EnhanceConsumerMessageHandler<AppEventMess
|
||||
break;
|
||||
case 7:
|
||||
log.info("分发至告警事件处理");
|
||||
alarmFeignClient.analysis(appEventMessage);
|
||||
break;
|
||||
case 16:
|
||||
log.info("分发至录波报文处理");
|
||||
|
||||
Reference in New Issue
Block a user