mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-05-01 01:21:28 +08:00
update 重构 common-sse 与 common-websocket 合并为 ruoyi-common-push 推送模块
update 优化 通知公告页面增加查看详情功能 支持预览已经编辑好的富文本内容 update 优化 消息盒子相关消息可直接跳转到详情页展示富文本内容 update 完成消息盒子功能前后端联动(已读未读在前端浏览器存储) update 工作流消息推送增加前端路由跳转
This commit is contained in:
@@ -58,6 +58,26 @@ public interface FlowConstant {
|
||||
*/
|
||||
String MESSAGE_NOTICE = "messageNotice";
|
||||
|
||||
/**
|
||||
* 我的发起页面路径
|
||||
*/
|
||||
String PATH_MY_DOCUMENT = "/task/myDocument";
|
||||
|
||||
/**
|
||||
* 我的待办页面路径
|
||||
*/
|
||||
String PATH_TASK_WAITING = "/task/taskWaiting";
|
||||
|
||||
/**
|
||||
* 我的已办页面路径
|
||||
*/
|
||||
String PATH_TASK_FINISH = "/task/taskFinish";
|
||||
|
||||
/**
|
||||
* 我的抄送页面路径
|
||||
*/
|
||||
String PATH_TASK_COPY = "/task/taskCopyList";
|
||||
|
||||
/**
|
||||
* 任务状态
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.enums.BusinessStatusEnum;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||
import org.dromara.system.api.RemoteUserService;
|
||||
import org.dromara.warm.flow.core.FlowEngine;
|
||||
import org.dromara.warm.flow.core.dto.FlowParams;
|
||||
@@ -22,6 +23,7 @@ import org.dromara.warm.flow.core.listener.GlobalListener;
|
||||
import org.dromara.warm.flow.core.listener.ListenerVariable;
|
||||
import org.dromara.workflow.common.ConditionalOnEnable;
|
||||
import org.dromara.workflow.common.constant.FlowConstant;
|
||||
import org.dromara.workflow.common.enums.MessageTypeEnum;
|
||||
import org.dromara.workflow.common.enums.TaskStatusEnum;
|
||||
import org.dromara.workflow.domain.bo.FlowCopyBo;
|
||||
import org.dromara.workflow.domain.vo.NodeExtVo;
|
||||
@@ -32,6 +34,7 @@ import org.dromara.workflow.service.IFlwNodeExtService;
|
||||
import org.dromara.workflow.service.IFlwTaskService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -201,12 +204,14 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
String status = determineFlowStatus(instance);
|
||||
if (StringUtils.isNotBlank(status)) {
|
||||
flowProcessEventHandler.processHandler(definition.getFlowCode(), instance, status, params, false);
|
||||
notifyInitiatorIfNeeded(definition, instance, status, variable);
|
||||
}
|
||||
if (!BusinessStatusEnum.initialState(instance.getFlowStatus())) {
|
||||
if (task != null && CollUtil.isNotEmpty(nextTasks) && nextTasks.size() == 1
|
||||
&& flwCommonService.applyNodeCode(definition.getId()).equals(nextTasks.get(0).getNodeCode())) {
|
||||
// 如果为画线指定驳回 线条指定为驳回 驳回得节点为申请人节点 则修改流程状态为退回
|
||||
flowProcessEventHandler.processHandler(definition.getFlowCode(), instance, BusinessStatusEnum.BACK.getStatus(), params, false);
|
||||
notifyInitiatorIfNeeded(definition, instance, BusinessStatusEnum.BACK.getStatus(), variable);
|
||||
// 修改流程实例状态
|
||||
instance.setFlowStatus(BusinessStatusEnum.BACK.getStatus());
|
||||
FlowEngine.insService().updateById(instance);
|
||||
@@ -238,7 +243,9 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
|
||||
List<String> messageType = MapUtil.get(variable, FlowConstant.MESSAGE_TYPE, new TypeReference<>() {});
|
||||
String notice = MapUtil.getStr(variable, FlowConstant.MESSAGE_NOTICE);
|
||||
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
||||
if (shouldSendTaskMessage(flowParams, definition, nextTasks)) {
|
||||
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
||||
}
|
||||
}
|
||||
FlowEngine.insService().removeVariables(instance.getId(),
|
||||
FlowConstant.FLOW_COPY_LIST,
|
||||
@@ -248,6 +255,43 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
);
|
||||
}
|
||||
|
||||
private boolean shouldSendTaskMessage(FlowParams flowParams, Definition definition, List<Task> nextTasks) {
|
||||
if (flowParams == null || !TaskStatusEnum.BACK.getStatus().equals(flowParams.getHisStatus())) {
|
||||
return true;
|
||||
}
|
||||
if (CollUtil.isEmpty(nextTasks) || nextTasks.size() != 1) {
|
||||
return true;
|
||||
}
|
||||
String applyNodeCode = flwCommonService.applyNodeCode(definition.getId());
|
||||
return !StringUtils.equals(applyNodeCode, nextTasks.get(0).getNodeCode());
|
||||
}
|
||||
|
||||
private void notifyInitiatorIfNeeded(Definition definition, Instance instance, String status, Map<String, Object> variable) {
|
||||
if (!StringUtils.equalsAny(status, BusinessStatusEnum.FINISH.getStatus(), BusinessStatusEnum.BACK.getStatus())) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(instance.getCreateBy())) {
|
||||
return;
|
||||
}
|
||||
Long createBy = Convert.toLong(instance.getCreateBy(), null);
|
||||
if (createBy == null) {
|
||||
return;
|
||||
}
|
||||
BusinessStatusEnum statusEnum = BusinessStatusEnum.getByStatus(status);
|
||||
if (statusEnum == null) {
|
||||
return;
|
||||
}
|
||||
List<RemoteUserVo> initiators = remoteUserService.selectListByIds(Collections.singletonList(createBy));
|
||||
if (CollUtil.isEmpty(initiators)) {
|
||||
return;
|
||||
}
|
||||
List<String> messageType = Collections.singletonList(MessageTypeEnum.SYSTEM_MESSAGE.getCode());
|
||||
if (MapUtil.isNotEmpty(variable) && variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
|
||||
messageType = MapUtil.get(variable, FlowConstant.MESSAGE_TYPE, new TypeReference<>() {});
|
||||
}
|
||||
flwCommonService.sendResultMessage(definition.getFlowName(), statusEnum, messageType, initiators);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据流程实例确定最终状态
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.dromara.workflow.service;
|
||||
|
||||
import org.dromara.common.core.enums.BusinessStatusEnum;
|
||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||
|
||||
import java.util.List;
|
||||
@@ -30,6 +31,27 @@ public interface IFlwCommonService {
|
||||
*/
|
||||
void sendMessage(List<String> messageType, String message, String subject, List<RemoteUserVo> userList);
|
||||
|
||||
/**
|
||||
* 发送带跳转路径的消息
|
||||
*
|
||||
* @param messageType 消息类型
|
||||
* @param message 消息内容
|
||||
* @param subject 邮件标题
|
||||
* @param userList 接收用户
|
||||
* @param path 前端跳转路径
|
||||
*/
|
||||
void sendMessage(List<String> messageType, String message, String subject, List<RemoteUserVo> userList, String path);
|
||||
|
||||
/**
|
||||
* 发送流程结果消息
|
||||
*
|
||||
* @param flowName 流程名称
|
||||
* @param status 流程状态
|
||||
* @param messageType 消息类型
|
||||
* @param userList 接收用户
|
||||
*/
|
||||
void sendResultMessage(String flowName, BusinessStatusEnum status, List<String> messageType, List<RemoteUserVo> userList);
|
||||
|
||||
/**
|
||||
* 申请人节点编码
|
||||
*
|
||||
|
||||
@@ -5,6 +5,9 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.enums.BusinessStatusEnum;
|
||||
import org.dromara.common.core.enums.PushSourceEnum;
|
||||
import org.dromara.common.core.enums.PushTypeEnum;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
@@ -12,6 +15,7 @@ import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.resource.api.RemoteMailService;
|
||||
import org.dromara.resource.api.RemoteMessageService;
|
||||
import org.dromara.resource.api.RemoteSmsService;
|
||||
import org.dromara.resource.api.domain.dto.RemotePushPayLoad;
|
||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||
import org.dromara.warm.flow.core.FlowEngine;
|
||||
import org.dromara.warm.flow.core.entity.Node;
|
||||
@@ -24,9 +28,11 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.dromara.workflow.common.constant.FlowConstant.PATH_MY_DOCUMENT;
|
||||
import static org.dromara.workflow.common.constant.FlowConstant.PATH_TASK_WAITING;
|
||||
|
||||
|
||||
/**
|
||||
* 工作流工具
|
||||
@@ -73,7 +79,7 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
|
||||
if (CollUtil.isEmpty(userList)) {
|
||||
return;
|
||||
}
|
||||
sendMessage(messageType, message, DEFAULT_SUBJECT, userList);
|
||||
sendMessage(messageType, message, DEFAULT_SUBJECT, userList, PATH_TASK_WAITING);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,6 +92,20 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(List<String> messageType, String message, String subject, List<RemoteUserVo> userList) {
|
||||
sendMessage(messageType, message, subject, userList, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendResultMessage(String flowName, BusinessStatusEnum status, List<String> messageType, List<RemoteUserVo> userList) {
|
||||
if (status == null || CollUtil.isEmpty(messageType) || CollUtil.isEmpty(userList)) {
|
||||
return;
|
||||
}
|
||||
String message = "您发起的【" + flowName + "】单据审批已" + status.getDesc() + "。";
|
||||
sendMessage(messageType, message, DEFAULT_SUBJECT, userList, PATH_MY_DOCUMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(List<String> messageType, String message, String subject, List<RemoteUserVo> userList, String path) {
|
||||
if (CollUtil.isEmpty(messageType) || CollUtil.isEmpty(userList)) {
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +120,12 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
|
||||
try {
|
||||
switch (messageTypeEnum) {
|
||||
case SYSTEM_MESSAGE -> {
|
||||
remoteMessageService.publishMessage(userIds, message);
|
||||
RemotePushPayLoad payload = RemotePushPayLoad.of(
|
||||
PushTypeEnum.MESSAGE,
|
||||
PushSourceEnum.WORKFLOW,
|
||||
message, null, path
|
||||
);
|
||||
remoteMessageService.publishMessagePayload(userIds, payload);
|
||||
}
|
||||
case EMAIL_MESSAGE -> {
|
||||
remoteMailService.send(emails, subject, message);
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.dromara.warm.flow.orm.mapper.FlowTaskMapper;
|
||||
import org.dromara.workflow.api.domain.RemoteStartProcessReturn;
|
||||
import org.dromara.workflow.common.ConditionalOnEnable;
|
||||
import org.dromara.workflow.common.constant.FlowConstant;
|
||||
import org.dromara.workflow.common.enums.MessageTypeEnum;
|
||||
import org.dromara.workflow.common.enums.TaskAssigneeType;
|
||||
import org.dromara.workflow.common.enums.TaskOperationEnum;
|
||||
import org.dromara.workflow.common.enums.TaskStatusEnum;
|
||||
@@ -367,6 +368,13 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
.setAssociated(taskId));
|
||||
// 批量保存抄送人员
|
||||
FlowEngine.userService().saveBatch(userList);
|
||||
flwCommonService.sendMessage(
|
||||
Collections.singletonList(MessageTypeEnum.SYSTEM_MESSAGE.getCode()),
|
||||
"您收到一条新的流程抄送,请及时查看。",
|
||||
"单据抄送提醒",
|
||||
remoteUserService.selectListByIds(StreamUtils.toList(flowCopyList, FlowCopyBo::getUserId)),
|
||||
PATH_TASK_COPY
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -812,7 +820,8 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
bo.getMessageType(),
|
||||
StringUtils.isNotBlank(bo.getMessage()) ? bo.getMessage() : "单据「" + op.getDesc() + "」通知",
|
||||
"单据「" + op.getDesc() + "」提醒",
|
||||
remoteUserService.selectListByIds(userIdList)
|
||||
remoteUserService.selectListByIds(userIdList),
|
||||
PATH_TASK_WAITING
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -891,7 +900,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
}
|
||||
List<String> messageType = bo.getMessageType();
|
||||
String message = bo.getMessage();
|
||||
flwCommonService.sendMessage(messageType, message, "单据审批提醒", userList);
|
||||
flwCommonService.sendMessage(messageType, message, "单据审批提醒", userList, PATH_TASK_WAITING);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user