mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-10-14 14:10:24 +00:00
update 优化 将工作流消息发送从工具类迁移到业务内 便于扩展
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息服务
|
||||
*
|
||||
@@ -13,7 +15,7 @@ public interface RemoteMessageService {
|
||||
* @param sessionKey session主键 一般为用户id
|
||||
* @param message 消息文本
|
||||
*/
|
||||
void publishMessage(Long sessionKey, String message);
|
||||
void publishMessage(List<Long> sessionKey, String message);
|
||||
|
||||
/**
|
||||
* 发布订阅的消息(群发)
|
||||
|
@@ -28,10 +28,10 @@ public class RemoteMessageServiceImpl implements RemoteMessageService {
|
||||
* @param message 消息文本
|
||||
*/
|
||||
@Override
|
||||
public void publishMessage(Long sessionKey, String message) {
|
||||
public void publishMessage(List<Long> sessionKey, String message) {
|
||||
SseMessageDto dto = new SseMessageDto();
|
||||
dto.setMessage(message);
|
||||
dto.setUserIds(List.of(sessionKey));
|
||||
dto.setUserIds(sessionKey);
|
||||
SseMessageUtils.publishMessage(dto);
|
||||
}
|
||||
|
||||
|
@@ -22,26 +22,11 @@
|
||||
<artifactId>ruoyi-common-nacos</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-sms</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-mybatis</artifactId>
|
||||
|
@@ -23,6 +23,8 @@ import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.resource.api.RemoteMailService;
|
||||
import org.dromara.resource.api.RemoteMessageService;
|
||||
import org.dromara.system.api.RemoteUserService;
|
||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||
import org.dromara.warm.flow.core.dto.FlowParams;
|
||||
@@ -36,6 +38,7 @@ import org.dromara.warm.flow.orm.mapper.FlowInstanceMapper;
|
||||
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.enums.MessageTypeEnum;
|
||||
import org.dromara.workflow.common.enums.TaskAssigneeType;
|
||||
import org.dromara.workflow.common.enums.TaskStatusEnum;
|
||||
import org.dromara.workflow.domain.bo.*;
|
||||
@@ -82,6 +85,10 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
|
||||
@DubboReference
|
||||
private RemoteUserService remoteUserService;
|
||||
@DubboReference
|
||||
private RemoteMessageService remoteMessageService;
|
||||
@DubboReference
|
||||
private RemoteMailService remoteMailService;
|
||||
|
||||
/**
|
||||
* 启动任务
|
||||
@@ -170,7 +177,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
Instance instance = taskService.skip(taskId, flowParams);
|
||||
this.setHandler(instance, flowTask, flowCopyList);
|
||||
// 消息通知
|
||||
WorkflowUtils.sendMessage(definition.getFlowName(), ins.getId(), messageType, notice);
|
||||
this.sendMessage(definition.getFlowName(), ins.getId(), messageType, notice);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@@ -397,7 +404,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
Instance instance = insService.getById(inst.getId());
|
||||
this.setHandler(instance, task, null);
|
||||
// 消息通知
|
||||
WorkflowUtils.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
||||
this.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@@ -687,4 +694,47 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
}
|
||||
return remoteUserService.selectListByIds(StreamUtils.toList(userList, e -> Long.valueOf(e.getProcessedBy())));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param flowName 流程定义名称
|
||||
* @param messageType 消息类型
|
||||
* @param message 消息内容,为空则发送默认配置的消息内容
|
||||
*/
|
||||
private void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
|
||||
List<RemoteUserVo> userList = new ArrayList<>();
|
||||
List<FlowTask> list = this.selectByInstId(instId);
|
||||
if (StringUtils.isBlank(message)) {
|
||||
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
|
||||
}
|
||||
for (Task task : list) {
|
||||
List<RemoteUserVo> users = this.currentTaskAllUser(task.getId());
|
||||
if (CollUtil.isNotEmpty(users)) {
|
||||
userList.addAll(users);
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
for (String code : messageType) {
|
||||
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
|
||||
if (ObjectUtil.isNotEmpty(messageTypeEnum)) {
|
||||
switch (messageTypeEnum) {
|
||||
case SYSTEM_MESSAGE:
|
||||
List<Long> userIds = StreamUtils.toList(userList, RemoteUserVo::getUserId).stream().distinct().collect(Collectors.toList());
|
||||
remoteMessageService.publishMessage(userIds, message);
|
||||
break;
|
||||
case EMAIL_MESSAGE:
|
||||
remoteMailService.send(StreamUtils.join(userList, RemoteUserVo::getEmail), "单据审批提醒", message);
|
||||
break;
|
||||
case SMS_MESSAGE:
|
||||
//todo 短信发送
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,21 +1,15 @@
|
||||
package org.dromara.workflow.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mail.utils.MailUtils;
|
||||
import org.dromara.common.sse.dto.SseMessageDto;
|
||||
import org.dromara.common.sse.utils.SseMessageUtils;
|
||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||
import org.dromara.warm.flow.core.constant.ExceptionCons;
|
||||
import org.dromara.warm.flow.core.dto.FlowParams;
|
||||
import org.dromara.warm.flow.core.entity.Node;
|
||||
import org.dromara.warm.flow.core.entity.Task;
|
||||
import org.dromara.warm.flow.core.entity.User;
|
||||
import org.dromara.warm.flow.core.enums.NodeType;
|
||||
import org.dromara.warm.flow.core.enums.SkipType;
|
||||
@@ -28,15 +22,12 @@ import org.dromara.warm.flow.orm.entity.FlowTask;
|
||||
import org.dromara.warm.flow.orm.entity.FlowUser;
|
||||
import org.dromara.warm.flow.orm.mapper.FlowNodeMapper;
|
||||
import org.dromara.warm.flow.orm.mapper.FlowTaskMapper;
|
||||
import org.dromara.workflow.common.enums.MessageTypeEnum;
|
||||
import org.dromara.workflow.service.IFlwTaskAssigneeService;
|
||||
import org.dromara.workflow.service.IFlwTaskService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -96,50 +87,6 @@ public class WorkflowUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param flowName 流程定义名称
|
||||
* @param messageType 消息类型
|
||||
* @param message 消息内容,为空则发送默认配置的消息内容
|
||||
*/
|
||||
public static void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
|
||||
List<RemoteUserVo> userList = new ArrayList<>();
|
||||
List<FlowTask> list = FLW_TASK_SERVICE.selectByInstId(instId);
|
||||
if (StringUtils.isBlank(message)) {
|
||||
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
|
||||
}
|
||||
for (Task task : list) {
|
||||
List<RemoteUserVo> users = FLW_TASK_SERVICE.currentTaskAllUser(task.getId());
|
||||
if (CollUtil.isNotEmpty(users)) {
|
||||
userList.addAll(users);
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
for (String code : messageType) {
|
||||
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
|
||||
if (ObjectUtil.isNotEmpty(messageTypeEnum)) {
|
||||
switch (messageTypeEnum) {
|
||||
case SYSTEM_MESSAGE:
|
||||
SseMessageDto dto = new SseMessageDto();
|
||||
dto.setUserIds(StreamUtils.toList(userList, RemoteUserVo::getUserId).stream().distinct().collect(Collectors.toList()));
|
||||
dto.setMessage(message);
|
||||
SseMessageUtils.publishMessage(dto);
|
||||
break;
|
||||
case EMAIL_MESSAGE:
|
||||
MailUtils.sendText(StreamUtils.join(userList, RemoteUserVo::getEmail), "单据审批提醒", message);
|
||||
break;
|
||||
case SMS_MESSAGE:
|
||||
//todo 短信发送
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驳回
|
||||
*
|
||||
|
Reference in New Issue
Block a user