告警事件解析处理
This commit is contained in:
@@ -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 "";
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user