refactor(alarm): 重构报警处置分配功能并优化消息推送机制
parent
beeaa44527
commit
6ef1c34f9c
|
|
@ -2,16 +2,14 @@ package com.zcloud.command;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.jjb.saas.message.client.message.facede.MessageFacade;
|
||||
import com.jjb.saas.message.client.message.request.MessageSendCmd;
|
||||
import com.jjb.saas.message.client.message.request.MessageTargetCmd;
|
||||
import com.zcloud.domain.config.MessageTemplateConfig;
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.zcloud.domain.enums.AlarmRecordStatusEnum;
|
||||
import com.zcloud.domain.gateway.AlarmDisposeLogGateway;
|
||||
import com.zcloud.domain.gateway.AlarmRecordGateway;
|
||||
import com.zcloud.domain.model.AlarmDisposeLogE;
|
||||
import com.zcloud.domain.model.AlarmRecordE;
|
||||
import com.zcloud.dto.AlarmDisposeAssignCmd;
|
||||
import com.zcloud.gbscommon.todolistmq.TodoListEventPusherUtil;
|
||||
|
|
@ -19,9 +17,9 @@ import com.zcloud.gbscommon.todolistmq.event.TodoListAddBatchEvent;
|
|||
import com.zcloud.gbscommon.todolistmq.event.TodoListAddEvent;
|
||||
import com.zcloud.gbscommon.utils.Tools;
|
||||
import com.zcloud.gbscommon.utils.UuidUtil;
|
||||
import com.zcloud.service.AlarmMessageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -42,7 +40,8 @@ import java.util.List;
|
|||
public class AlarmDisposeAssignExe {
|
||||
|
||||
private final AlarmRecordGateway alarmRecordGateway;
|
||||
private final MessageTemplateConfig messageTemplateConfig;
|
||||
private final AlarmDisposeLogGateway alarmDisposeLogGateway;
|
||||
private final AlarmMessageService alarmMessageService;
|
||||
private final TodoListEventPusherUtil todoListEventPusherUtil;
|
||||
|
||||
/**
|
||||
|
|
@ -59,44 +58,38 @@ public class AlarmDisposeAssignExe {
|
|||
}
|
||||
checkAssignStatus(cmd.getStatus());
|
||||
|
||||
// 获取当前时间的LocalDateTime "yyyy-MM-dd HH:mm:ss"
|
||||
LocalDateTime assignTime = LocalDateTime.now();
|
||||
List<TodoListAddEvent> todoListAddEventList = new ArrayList<>();
|
||||
List<AlarmRecordE> alarmRecords = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
// 查询报警记录
|
||||
AlarmRecordE alarmRecord = alarmRecordGateway.getById(id);
|
||||
if (Tools.isEmpty(alarmRecord)) {
|
||||
return SingleResponse.buildFailure("id:"+id+"报警记录不存在;");
|
||||
throw new BizException("id:" + id + "报警记录不存在;");
|
||||
}
|
||||
|
||||
// 检查状态:只有待研判(10)状态可以分配
|
||||
if (!AlarmRecordStatusEnum.PENDING_REVIEW.sameStatus(alarmRecord.getStatus())) {
|
||||
return SingleResponse.buildFailure("报警编码为" + alarmRecord.getAlarmNo() + "报警记录状态不是待研判;");
|
||||
throw new BizException("报警编码为" + alarmRecord.getAlarmNo() + "报警记录状态不是待研判;");
|
||||
}
|
||||
alarmRecords.add(alarmRecord);
|
||||
}
|
||||
|
||||
// 更新报警记录状态和处置人
|
||||
List<TodoListAddEvent> todoListAddEventList = new ArrayList<>();
|
||||
List<AlarmRecordE> notifyRecords = new ArrayList<>();
|
||||
for (AlarmRecordE alarmRecord : alarmRecords) {
|
||||
AlarmRecordE updateEntity = new AlarmRecordE();
|
||||
BeanUtil.copyProperties(cmd, updateEntity);
|
||||
updateEntity.setId(id);
|
||||
updateEntity.setId(alarmRecord.getId());
|
||||
updateEntity.setAssignTime(assignTime);
|
||||
updateEntity.setAssignUserId(AuthContext.getUserId());
|
||||
alarmRecordGateway.update(updateEntity);
|
||||
if (AlarmRecordStatusEnum.PENDING_DISPOSE.sameStatus(cmd.getStatus())) {
|
||||
// 发送站内信
|
||||
sendMessage(messageTemplateConfig.getDispose(), cmd.getDisposeUserId());
|
||||
//待排查 待办
|
||||
TodoListAddEvent event = new TodoListAddEvent();
|
||||
event.setTitle("您有一条【物联网报警】待处置");
|
||||
event.setContent("您有一条报警信息,请及时进行处置。");
|
||||
event.setForeignKey(alarmRecord.getId()); // 业务表ID -申请
|
||||
event.setForeignSubsidiaryKey(alarmRecord.getId()); // 业务附表ID 没有附表时为foreignKey的值
|
||||
event.setReceiveUser(cmd.getDisposeUserId());// user表ID
|
||||
event.setPcFlag(0); // 是否PC端待办 1是 0否
|
||||
event.setAppFlag(1); // 是否APP端待办 1是 0否
|
||||
event.setOtherParams(new JSONObject());
|
||||
todoListAddEventList.add(event);
|
||||
}
|
||||
|
||||
alarmDisposeLogGateway.add(buildAssignLog(alarmRecord, cmd, assignTime));
|
||||
if (AlarmRecordStatusEnum.PENDING_DISPOSE.sameStatus(cmd.getStatus())) {
|
||||
notifyRecords.add(buildNotifyRecord(alarmRecord, cmd, assignTime));
|
||||
todoListAddEventList.add(buildDisposeTodoEvent(alarmRecord.getId(), cmd.getDisposeUserId()));
|
||||
}
|
||||
}
|
||||
|
||||
for (AlarmRecordE notifyRecord : notifyRecords) {
|
||||
alarmMessageService.sendDisposePushMessage(notifyRecord, cmd.getDisposeUserId());
|
||||
}
|
||||
if (AlarmRecordStatusEnum.PENDING_DISPOSE.sameStatus(cmd.getStatus()) && !todoListAddEventList.isEmpty()) {
|
||||
sendTodoBatch(todoListAddEventList);
|
||||
|
|
@ -104,10 +97,6 @@ public class AlarmDisposeAssignExe {
|
|||
return SingleResponse.buildSuccess();
|
||||
}
|
||||
|
||||
|
||||
@DubboReference
|
||||
private MessageFacade messageFacade;
|
||||
|
||||
private void checkAssignStatus(Integer status) {
|
||||
if (!AlarmRecordStatusEnum.PENDING_DISPOSE.sameStatus(status)
|
||||
&& !AlarmRecordStatusEnum.FALSE_ALARM.sameStatus(status)) {
|
||||
|
|
@ -127,23 +116,47 @@ public class AlarmDisposeAssignExe {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendMessage(String template, Long userId) {
|
||||
try {
|
||||
MessageSendCmd messageSendCmd = new MessageSendCmd();
|
||||
messageSendCmd.setBusinessId(UuidUtil.get32UUID());
|
||||
MessageTargetCmd messageTargetCmd = new MessageTargetCmd();
|
||||
messageTargetCmd.setUserId(userId);
|
||||
messageSendCmd.setTargetCmd(messageTargetCmd);
|
||||
messageSendCmd.setSourceCode(template);
|
||||
messageSendCmd.setNeedTokenEnum(false);
|
||||
|
||||
log.info("发送站内信人员:{}", userId);
|
||||
SingleResponse<Boolean> result = messageFacade.send(messageSendCmd);
|
||||
log.info("发送站内信结果:{}", result.toString());
|
||||
} catch (Exception e){
|
||||
log.error("处置分配站内信发送失败,不影响分配主流程,接收人ID:{},错误:{}", userId, e.getMessage(), e);
|
||||
}
|
||||
|
||||
private AlarmDisposeLogE buildAssignLog(AlarmRecordE alarmRecord, AlarmDisposeAssignCmd cmd, LocalDateTime assignTime) {
|
||||
AlarmDisposeLogE log = new AlarmDisposeLogE();
|
||||
log.setAlarmDisposalLogId(UuidUtil.get32UUID());
|
||||
log.setAlarmId(alarmRecord.getId());
|
||||
log.setAlarmNo(alarmRecord.getAlarmNo());
|
||||
log.setActionType("MANUAL_ASSIGN");
|
||||
log.setBeforeStatus(alarmRecord.getStatus());
|
||||
log.setAfterStatus(cmd.getStatus());
|
||||
log.setOperatorId(AuthContext.getUserId());
|
||||
log.setActionDesc("处置分配");
|
||||
log.setActionTime(assignTime);
|
||||
log.setTenantId(alarmRecord.getTenantId());
|
||||
log.setOrgId(alarmRecord.getOrgId());
|
||||
log.setDeleteEnum("FALSE");
|
||||
return log;
|
||||
}
|
||||
|
||||
private AlarmRecordE buildNotifyRecord(AlarmRecordE alarmRecord, AlarmDisposeAssignCmd cmd, LocalDateTime assignTime) {
|
||||
AlarmRecordE notifyRecord = new AlarmRecordE();
|
||||
BeanUtil.copyProperties(alarmRecord, notifyRecord);
|
||||
notifyRecord.setStatus(cmd.getStatus());
|
||||
notifyRecord.setDisposeUserId(cmd.getDisposeUserId());
|
||||
notifyRecord.setAssignTime(assignTime);
|
||||
notifyRecord.setAssignUserId(AuthContext.getUserId());
|
||||
notifyRecord.setAlarmLevel(cmd.getAlarmLevel());
|
||||
notifyRecord.setAlarmLevelName(cmd.getAlarmLevelName());
|
||||
notifyRecord.setAlarmType(cmd.getAlarmType());
|
||||
notifyRecord.setAlarmTypeName(cmd.getAlarmTypeName());
|
||||
return notifyRecord;
|
||||
}
|
||||
|
||||
private TodoListAddEvent buildDisposeTodoEvent(Long alarmId, Long disposeUserId) {
|
||||
TodoListAddEvent event = new TodoListAddEvent();
|
||||
event.setTitle("您有一条【物联网报警】待处理");
|
||||
event.setContent("待处置");
|
||||
event.setForeignKey(alarmId);
|
||||
event.setForeignSubsidiaryKey(alarmId);
|
||||
event.setReceiveUser(disposeUserId);
|
||||
event.setPcFlag(0);
|
||||
event.setAppFlag(1);
|
||||
event.setOtherParams(new JSONObject());
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.zcloud.command;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.zcloud.domain.enums.AlarmRecordStatusEnum;
|
||||
|
|
@ -18,7 +19,6 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -43,8 +43,6 @@ public class AlarmDisposeBatchAssignExe {
|
|||
throw new BizException("请选择要分配的报警记录");
|
||||
}
|
||||
|
||||
String assignTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
for (Long id : ids) {
|
||||
// 查询报警记录
|
||||
AlarmRecordE alarmRecord = alarmRecordGateway.getById(id);
|
||||
|
|
@ -63,9 +61,9 @@ public class AlarmDisposeBatchAssignExe {
|
|||
updateEntity.setStatus(AlarmRecordStatusEnum.PENDING_DISPOSE.getStatus()); // 待处置
|
||||
updateEntity.setManagerId(cmd.getDisposeUserId());
|
||||
updateEntity.setDisposeUserId(cmd.getDisposeUserId());
|
||||
// updateEntity.setAssignTime(assignTime);
|
||||
updateEntity.setTenantId(cmd.getTenantId());
|
||||
updateEntity.setAssignTime(LocalDateTime.now());
|
||||
LocalDateTime assignTime = LocalDateTime.now();
|
||||
updateEntity.setAssignTime(assignTime);
|
||||
updateEntity.setAssignUserId(AuthContext.getUserId());
|
||||
updateEntity.setOrgId(cmd.getOrgId());
|
||||
|
||||
|
|
@ -81,18 +79,32 @@ public class AlarmDisposeBatchAssignExe {
|
|||
log.setAfterStatus(AlarmRecordStatusEnum.PENDING_DISPOSE.getStatus());
|
||||
log.setOperatorId(cmd.getDisposeUserId());
|
||||
log.setActionDesc("批量分配处置");
|
||||
// log.setActionTime(assignTime);
|
||||
log.setActionTime(assignTime);
|
||||
log.setTenantId(cmd.getTenantId());
|
||||
log.setOrgId(cmd.getOrgId());
|
||||
log.setDeleteEnum("FALSE");
|
||||
|
||||
alarmDisposeLogGateway.add(log);
|
||||
|
||||
AlarmRecordE notifyRecord = buildNotifyRecord(alarmRecord, updateEntity);
|
||||
// 发送报警处置推送消息给处置人
|
||||
alarmMessageService.sendDisposePushMessage(updateEntity, cmd.getDisposeUserId());
|
||||
alarmMessageService.sendDisposePushMessage(notifyRecord, cmd.getDisposeUserId());
|
||||
|
||||
// 新增处置人待办
|
||||
alarmTodoService.addDisposeTodo(updateEntity, cmd.getDisposeUserId());
|
||||
alarmTodoService.addDisposeTodo(notifyRecord, cmd.getDisposeUserId());
|
||||
}
|
||||
}
|
||||
|
||||
private AlarmRecordE buildNotifyRecord(AlarmRecordE sourceRecord, AlarmRecordE updateEntity) {
|
||||
AlarmRecordE notifyRecord = new AlarmRecordE();
|
||||
BeanUtil.copyProperties(sourceRecord, notifyRecord);
|
||||
notifyRecord.setStatus(updateEntity.getStatus());
|
||||
notifyRecord.setManagerId(updateEntity.getManagerId());
|
||||
notifyRecord.setDisposeUserId(updateEntity.getDisposeUserId());
|
||||
notifyRecord.setAssignTime(updateEntity.getAssignTime());
|
||||
notifyRecord.setAssignUserId(updateEntity.getAssignUserId());
|
||||
notifyRecord.setTenantId(updateEntity.getTenantId());
|
||||
notifyRecord.setOrgId(updateEntity.getOrgId());
|
||||
return notifyRecord;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.zcloud.service;
|
|||
import com.jjb.saas.message.client.message.facede.MessageFacade;
|
||||
import com.jjb.saas.message.client.message.request.MessageSendCmd;
|
||||
import com.jjb.saas.message.client.message.request.MessageTargetCmd;
|
||||
import com.zcloud.domain.config.MessageTemplateConfig;
|
||||
import com.zcloud.domain.model.AlarmRecordE;
|
||||
import com.zcloud.gbscommon.utils.UuidUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
@ -10,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -28,9 +30,7 @@ public class AlarmMessageService {
|
|||
@DubboReference
|
||||
private MessageFacade messageFacade;
|
||||
|
||||
// TODO: 后续需要配置消息模板编码
|
||||
private static final String AUTO_PUSH_TEMPLATE_CODE = "MT0001XX";
|
||||
private static final String DISPOSE_PUSH_TEMPLATE_CODE = "MT0001XX";
|
||||
private final MessageTemplateConfig messageTemplateConfig;
|
||||
|
||||
/**
|
||||
* 发送报警自动推送消息
|
||||
|
|
@ -51,7 +51,12 @@ public class AlarmMessageService {
|
|||
messageTargetCmd.setUserId(managerId);
|
||||
messageSendCmd.setTargetCmd(messageTargetCmd);
|
||||
|
||||
messageSendCmd.setSourceCode(AUTO_PUSH_TEMPLATE_CODE);
|
||||
String templateCode = messageTemplateConfig.getAssign();
|
||||
if (!StringUtils.hasText(templateCode)) {
|
||||
log.warn("报警自动推送消息模板未配置,跳过发送,报警ID: {}", alarmRecord.getId());
|
||||
return;
|
||||
}
|
||||
messageSendCmd.setSourceCode(templateCode);
|
||||
messageSendCmd.setNeedTokenEnum(false);
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
|
|
@ -89,7 +94,12 @@ public class AlarmMessageService {
|
|||
messageTargetCmd.setUserId(disposeUserId);
|
||||
messageSendCmd.setTargetCmd(messageTargetCmd);
|
||||
|
||||
messageSendCmd.setSourceCode(DISPOSE_PUSH_TEMPLATE_CODE);
|
||||
String templateCode = messageTemplateConfig.getDispose();
|
||||
if (!StringUtils.hasText(templateCode)) {
|
||||
log.warn("报警处置推送消息模板未配置,跳过发送,报警ID: {}", alarmRecord.getId());
|
||||
return;
|
||||
}
|
||||
messageSendCmd.setSourceCode(templateCode);
|
||||
messageSendCmd.setNeedTokenEnum(false);
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
|
|
@ -107,4 +117,4 @@ public class AlarmMessageService {
|
|||
alarmRecord.getId(), disposeUserId, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package com.zcloud.service;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zcloud.domain.enums.AlarmRecordStatusEnum;
|
||||
import com.zcloud.domain.model.AlarmRecordE;
|
||||
|
|
@ -12,6 +15,8 @@ import org.springframework.beans.factory.ObjectProvider;
|
|||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* AlarmTodoService - 报警待办服务
|
||||
* @Author wangyan
|
||||
|
|
@ -128,9 +133,12 @@ public class AlarmTodoService {
|
|||
}
|
||||
|
||||
try {
|
||||
TodoListCompleteEvent event = new TodoListCompleteEvent(alarmId, String.valueOf(alarmId));
|
||||
todoListEventPusherUtil.sendMessageCompleteEvent(event);
|
||||
log.info("待办完成发送成功,报警ID: {}", alarmId);
|
||||
TodoListCompleteEvent event1 = new TodoListCompleteEvent();
|
||||
event1.setForeignSubsidiaryKey(alarmId);// 业务附表ID 没有附表时为foreignKey的值
|
||||
event1.setCreateTime(DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN));
|
||||
log.info("发送待办消息,参数:{}", JSONUtil.toJsonStr(event1));
|
||||
boolean b = todoListEventPusherUtil.sendMessageCompleteEvent(event1);
|
||||
log.info("发送待办消息结果:{}", JSONUtil.toJsonStr(b));
|
||||
} catch (Exception e) {
|
||||
log.error("待办完成发送失败,报警ID: {}, 错误: {}", alarmId, e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ public class AppAlarmDisposeSubmitCmd extends Command {
|
|||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "处置状态 30已消警/40误报", name = "status", required = true)
|
||||
@NotNull(message = "处置状态不能为空")
|
||||
private Integer status;
|
||||
private Integer status=30;
|
||||
|
||||
@ApiModelProperty(value = "处置结果快照", name = "disposeResult")
|
||||
private String disposeResult;
|
||||
|
|
|
|||
Loading…
Reference in New Issue