mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-10-14 22:20:29 +00:00
update 优化 优化工作流代码写法
This commit is contained in:
@@ -206,7 +206,7 @@ public class FlwTaskController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/currentTaskAllUser/{taskId}")
|
@GetMapping("/currentTaskAllUser/{taskId}")
|
||||||
public R<List<RemoteUserVo>> currentTaskAllUser(@PathVariable Long taskId) {
|
public R<List<RemoteUserVo>> currentTaskAllUser(@PathVariable Long taskId) {
|
||||||
return R.ok(flwTaskService.currentTaskAllUser(taskId));
|
return R.ok(flwTaskService.currentTaskAllUser(List.of(taskId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package org.dromara.workflow.listener;
|
package org.dromara.workflow.listener;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.lang.TypeReference;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -136,33 +137,36 @@ public class WorkflowGlobalListener implements GlobalListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 只有办理或者退回的时候才执行消息通知和抄送
|
// 只有办理或者退回的时候才执行消息通知和抄送
|
||||||
if (TaskStatusEnum.PASS.getStatus().equals(flowParams.getHisStatus())
|
if (!StringUtils.equalsAny(flowParams.getHisStatus(),
|
||||||
|| TaskStatusEnum.BACK.getStatus().equals(flowParams.getHisStatus())) {
|
TaskStatusEnum.PASS.getStatus(), TaskStatusEnum.BACK.getStatus())) {
|
||||||
if (variable != null) {
|
return;
|
||||||
if (variable.containsKey(FlowConstant.FLOW_COPY_LIST)) {
|
}
|
||||||
List<FlowCopyBo> flowCopyList = (List<FlowCopyBo>) variable.get(FlowConstant.FLOW_COPY_LIST);
|
if (ObjectUtil.isNull(variable)) {
|
||||||
// 添加抄送人
|
return;
|
||||||
flwTaskService.setCopy(task, flowCopyList);
|
}
|
||||||
}
|
|
||||||
if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
|
if (variable.containsKey(FlowConstant.FLOW_COPY_LIST)) {
|
||||||
List<String> messageType = (List<String>) variable.get(FlowConstant.MESSAGE_TYPE);
|
List<FlowCopyBo> flowCopyList = MapUtil.get(variable, FlowConstant.FLOW_COPY_LIST, new TypeReference<>() {});
|
||||||
String notice = (String) variable.get(FlowConstant.MESSAGE_NOTICE);
|
// 添加抄送人
|
||||||
// 消息通知
|
flwTaskService.setCopy(task, flowCopyList);
|
||||||
if (CollUtil.isNotEmpty(messageType)) {
|
}
|
||||||
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
|
||||||
}
|
List<String> messageType = MapUtil.get(variable, FlowConstant.FLOW_COPY_LIST, new TypeReference<>() {});
|
||||||
}
|
String notice = MapUtil.getStr(variable, FlowConstant.MESSAGE_NOTICE);
|
||||||
FlowInstance ins = new FlowInstance();
|
// 消息通知
|
||||||
Map<String, Object> variableMap = instance.getVariableMap();
|
if (CollUtil.isNotEmpty(messageType)) {
|
||||||
variableMap.remove(FlowConstant.FLOW_COPY_LIST);
|
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
||||||
variableMap.remove(FlowConstant.MESSAGE_TYPE);
|
|
||||||
variableMap.remove(FlowConstant.MESSAGE_NOTICE);
|
|
||||||
variableMap.remove(FlowConstant.SUBMIT);
|
|
||||||
ins.setId(instance.getId());
|
|
||||||
ins.setVariable(FlowEngine.jsonConvert.objToStr(variableMap));
|
|
||||||
insService.updateById(ins);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FlowInstance ins = new FlowInstance();
|
||||||
|
Map<String, Object> variableMap = instance.getVariableMap();
|
||||||
|
variableMap.remove(FlowConstant.FLOW_COPY_LIST);
|
||||||
|
variableMap.remove(FlowConstant.MESSAGE_TYPE);
|
||||||
|
variableMap.remove(FlowConstant.MESSAGE_NOTICE);
|
||||||
|
variableMap.remove(FlowConstant.SUBMIT);
|
||||||
|
ins.setId(instance.getId());
|
||||||
|
ins.setVariable(FlowEngine.jsonConvert.objToStr(variableMap));
|
||||||
|
insService.updateById(ins);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -177,10 +177,10 @@ public interface IFlwTaskService {
|
|||||||
/**
|
/**
|
||||||
* 获取当前任务的所有办理人
|
* 获取当前任务的所有办理人
|
||||||
*
|
*
|
||||||
* @param taskId 任务id
|
* @param taskIds 任务id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
List<RemoteUserVo> currentTaskAllUser(Long taskId);
|
List<RemoteUserVo> currentTaskAllUser(List<Long> taskIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按照节点编码查询节点
|
* 按照节点编码查询节点
|
||||||
|
@@ -11,26 +11,17 @@ import org.dromara.common.core.utils.StringUtils;
|
|||||||
import org.dromara.resource.api.RemoteMailService;
|
import org.dromara.resource.api.RemoteMailService;
|
||||||
import org.dromara.resource.api.RemoteMessageService;
|
import org.dromara.resource.api.RemoteMessageService;
|
||||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||||
import org.dromara.warm.flow.core.FlowEngine;
|
|
||||||
import org.dromara.warm.flow.core.entity.Instance;
|
|
||||||
import org.dromara.warm.flow.core.entity.Node;
|
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.SkipType;
|
import org.dromara.warm.flow.core.enums.SkipType;
|
||||||
import org.dromara.warm.flow.core.service.NodeService;
|
import org.dromara.warm.flow.core.service.NodeService;
|
||||||
import org.dromara.warm.flow.core.service.UserService;
|
|
||||||
import org.dromara.warm.flow.core.utils.MapUtil;
|
|
||||||
import org.dromara.warm.flow.orm.entity.FlowTask;
|
import org.dromara.warm.flow.orm.entity.FlowTask;
|
||||||
import org.dromara.warm.flow.orm.entity.FlowUser;
|
|
||||||
import org.dromara.workflow.common.ConditionalOnEnable;
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
||||||
import org.dromara.workflow.common.enums.MessageTypeEnum;
|
import org.dromara.workflow.common.enums.MessageTypeEnum;
|
||||||
import org.dromara.workflow.common.enums.TaskAssigneeType;
|
|
||||||
import org.dromara.workflow.service.IFlwCommonService;
|
import org.dromara.workflow.service.IFlwCommonService;
|
||||||
import org.dromara.workflow.service.IFlwTaskAssigneeService;
|
|
||||||
import org.dromara.workflow.service.IFlwTaskService;
|
import org.dromara.workflow.service.IFlwTaskService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@@ -62,38 +53,34 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
|
|||||||
@Override
|
@Override
|
||||||
public void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
|
public void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
|
||||||
IFlwTaskService flwTaskService = SpringUtils.getBean(IFlwTaskService.class);
|
IFlwTaskService flwTaskService = SpringUtils.getBean(IFlwTaskService.class);
|
||||||
List<RemoteUserVo> userList = new ArrayList<>();
|
|
||||||
List<FlowTask> list = flwTaskService.selectByInstId(instId);
|
List<FlowTask> list = flwTaskService.selectByInstId(instId);
|
||||||
if (StringUtils.isBlank(message)) {
|
if (StringUtils.isBlank(message)) {
|
||||||
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
|
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
|
||||||
}
|
}
|
||||||
for (Task task : list) {
|
List<RemoteUserVo> userList = flwTaskService.currentTaskAllUser(StreamUtils.toList(list, FlowTask::getId));
|
||||||
List<RemoteUserVo> users = flwTaskService.currentTaskAllUser(task.getId());
|
if (CollUtil.isEmpty(userList)) {
|
||||||
if (CollUtil.isNotEmpty(users)) {
|
return;
|
||||||
userList.addAll(users);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(userList)) {
|
for (String code : messageType) {
|
||||||
for (String code : messageType) {
|
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
|
||||||
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
|
if (ObjectUtil.isEmpty(messageTypeEnum)) {
|
||||||
if (ObjectUtil.isNotEmpty(messageTypeEnum)) {
|
continue;
|
||||||
switch (messageTypeEnum) {
|
}
|
||||||
case SYSTEM_MESSAGE:
|
switch (messageTypeEnum) {
|
||||||
List<Long> userIds = StreamUtils.toList(userList, RemoteUserVo::getUserId).stream().distinct().collect(Collectors.toList());
|
case SYSTEM_MESSAGE -> {
|
||||||
remoteMessageService.publishMessage(userIds, message);
|
List<Long> userIds = StreamUtils.toList(userList, RemoteUserVo::getUserId).stream().distinct().collect(Collectors.toList());
|
||||||
break;
|
remoteMessageService.publishMessage(userIds, message);
|
||||||
case EMAIL_MESSAGE:
|
|
||||||
remoteMailService.send(StreamUtils.join(userList, RemoteUserVo::getEmail), "单据审批提醒", message);
|
|
||||||
break;
|
|
||||||
case SMS_MESSAGE:
|
|
||||||
//todo 短信发送
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
case EMAIL_MESSAGE -> {
|
||||||
|
remoteMailService.send(StreamUtils.join(userList, RemoteUserVo::getEmail), "单据审批提醒", message);
|
||||||
|
}
|
||||||
|
case SMS_MESSAGE -> {
|
||||||
|
//todo 短信发送
|
||||||
|
}
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -123,8 +123,8 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
|
|||||||
List<FlowNode> flowNodes = flowNodeMapper.selectList(new LambdaQueryWrapper<FlowNode>().eq(FlowNode::getDefinitionId, id));
|
List<FlowNode> flowNodes = flowNodeMapper.selectList(new LambdaQueryWrapper<FlowNode>().eq(FlowNode::getDefinitionId, id));
|
||||||
List<String> errorMsg = new ArrayList<>();
|
List<String> errorMsg = new ArrayList<>();
|
||||||
if (CollUtil.isNotEmpty(flowNodes)) {
|
if (CollUtil.isNotEmpty(flowNodes)) {
|
||||||
|
String applyNodeCode = flwCommonService.applyNodeCode(id);
|
||||||
for (FlowNode flowNode : flowNodes) {
|
for (FlowNode flowNode : flowNodes) {
|
||||||
String applyNodeCode = flwCommonService.applyNodeCode(id);
|
|
||||||
if (StringUtils.isBlank(flowNode.getPermissionFlag()) && !applyNodeCode.equals(flowNode.getNodeCode()) && NodeType.BETWEEN.getKey().equals(flowNode.getNodeType())) {
|
if (StringUtils.isBlank(flowNode.getPermissionFlag()) && !applyNodeCode.equals(flowNode.getNodeCode()) && NodeType.BETWEEN.getKey().equals(flowNode.getNodeType())) {
|
||||||
errorMsg.add(flowNode.getNodeName());
|
errorMsg.add(flowNode.getNodeName());
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,8 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FlowCategory flowCategory = flwCategoryMapper.selectOne(new LambdaQueryWrapper<FlowCategory>()
|
FlowCategory flowCategory = flwCategoryMapper.selectOne(new LambdaQueryWrapper<FlowCategory>()
|
||||||
.eq(FlowCategory::getTenantId, DEFAULT_TENANT_ID).eq(FlowCategory::getCategoryId, FlowConstant.FLOW_CATEGORY_ID));
|
.eq(FlowCategory::getTenantId, DEFAULT_TENANT_ID)
|
||||||
|
.eq(FlowCategory::getCategoryId, FlowConstant.FLOW_CATEGORY_ID));
|
||||||
flowCategory.setCategoryId(null);
|
flowCategory.setCategoryId(null);
|
||||||
flowCategory.setTenantId(tenantId);
|
flowCategory.setTenantId(tenantId);
|
||||||
flowCategory.setCreateDept(null);
|
flowCategory.setCreateDept(null);
|
||||||
|
@@ -535,12 +535,12 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
//构建以下节点数据
|
//构建以下节点数据
|
||||||
List<Task> buildNextTaskList = StreamUtils.toList(nextNodeList, node -> taskService.addTask(node, instance, definition, FlowParams.build()));
|
List<Task> buildNextTaskList = StreamUtils.toList(nextNodeList, node -> taskService.addTask(node, instance, definition, FlowParams.build()));
|
||||||
//办理人变量替换
|
//办理人变量替换
|
||||||
ExpressionUtil.evalVariable(buildNextTaskList,
|
ExpressionUtil.evalVariable(buildNextTaskList, FlowParams.build().variable(mergeVariable));
|
||||||
FlowParams.build()
|
|
||||||
.variable(mergeVariable)
|
|
||||||
);
|
|
||||||
for (FlowNode flowNode : nextFlowNodes) {
|
for (FlowNode flowNode : nextFlowNodes) {
|
||||||
buildNextTaskList.stream().filter(t -> t.getNodeCode().equals(flowNode.getNodeCode())).findFirst().ifPresent(t -> {
|
Optional<Task> first = buildNextTaskList.stream()
|
||||||
|
.filter(t -> t.getNodeCode().equals(flowNode.getNodeCode()))
|
||||||
|
.findFirst();
|
||||||
|
first.ifPresent(t -> {
|
||||||
if (CollUtil.isNotEmpty(t.getPermissionList())) {
|
if (CollUtil.isNotEmpty(t.getPermissionList())) {
|
||||||
List<RemoteUserVo> users = flwTaskAssigneeService.fetchUsersByStorageIds(String.join(StringUtils.SEPARATOR, t.getPermissionList()));
|
List<RemoteUserVo> users = flwTaskAssigneeService.fetchUsersByStorageIds(String.join(StringUtils.SEPARATOR, t.getPermissionList()));
|
||||||
if (CollUtil.isNotEmpty(users)) {
|
if (CollUtil.isNotEmpty(users)) {
|
||||||
@@ -685,12 +685,12 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
/**
|
/**
|
||||||
* 获取当前任务的所有办理人
|
* 获取当前任务的所有办理人
|
||||||
*
|
*
|
||||||
* @param taskId 任务id
|
* @param taskIds 任务id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<RemoteUserVo> currentTaskAllUser(Long taskId) {
|
public List<RemoteUserVo> currentTaskAllUser(List<Long> taskIds) {
|
||||||
// 获取与当前任务关联的用户列表
|
// 获取与当前任务关联的用户列表
|
||||||
List<User> userList = FlowEngine.userService().getByAssociateds(Collections.singletonList(taskId));
|
List<User> userList = FlowEngine.userService().getByAssociateds(taskIds);
|
||||||
if (CollUtil.isEmpty(userList)) {
|
if (CollUtil.isEmpty(userList)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user