refactor(klp-flowable):移除下一个处理人选择功能- 删除了 NextUserSelector 类- 移除了 UserTaskListener 中关于下一个处理人的逻辑
- 删除了 WfTaskServiceImpl 中保存下一个处理人到流程变量的代码这个改动移除了用户自定义选择下一个处理人的功能,简化了系统架构。
This commit is contained in:
@@ -4,7 +4,7 @@ import org.flowable.engine.delegate.TaskListener;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 用户任务监听器
|
||||
@@ -23,23 +23,6 @@ public class UserTaskListener implements TaskListener {
|
||||
@Override
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
System.out.println("执行任务监听器...");
|
||||
|
||||
// 检查是否有指定的下一个处理人
|
||||
Map<String, Object> variables = delegateTask.getVariables();
|
||||
if (variables.containsKey("nextUserIds")) {
|
||||
String nextUserIds = (String) variables.get("nextUserIds");
|
||||
if (nextUserIds != null && !nextUserIds.isEmpty()) {
|
||||
// 设置任务的处理人
|
||||
String[] userIds = nextUserIds.split(",");
|
||||
if (userIds.length > 0) {
|
||||
delegateTask.setAssignee(userIds[0]);
|
||||
}
|
||||
// 如果有多个处理人,可以设置为候选人
|
||||
for (int i = 1; i < userIds.length; i++) {
|
||||
delegateTask.addCandidateUser(userIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.klp.flowable.utils;
|
||||
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 下一个处理人选择器
|
||||
* 用于处理用户自定义选择下一个处理人的逻辑
|
||||
*
|
||||
* @author CodeBuddy
|
||||
* @since 2025/8/22
|
||||
*/
|
||||
@Component
|
||||
public class NextUserSelector {
|
||||
|
||||
private final TaskService taskService;
|
||||
private final RuntimeService runtimeService;
|
||||
|
||||
public NextUserSelector(TaskService taskService, RuntimeService runtimeService) {
|
||||
this.taskService = taskService;
|
||||
this.runtimeService = runtimeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下一个任务的处理人
|
||||
*
|
||||
* @param taskId 当前任务ID
|
||||
* @param nextUserIds 下一个处理人ID,多个用逗号分隔
|
||||
*/
|
||||
public void setNextTaskUsers(String taskId, String nextUserIds) {
|
||||
if (nextUserIds == null || nextUserIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置流程变量,在任务完成后传递给下一个任务
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
variables.put("nextUserIds", nextUserIds);
|
||||
|
||||
// 更新流程实例变量
|
||||
runtimeService.setVariables(task.getExecutionId(), variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前任务的指定处理人
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 指定的处理人ID,多个用逗号分隔
|
||||
*/
|
||||
public String getNextTaskUsers(String taskId) {
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object nextUserIds = runtimeService.getVariable(task.getExecutionId(), "nextUserIds");
|
||||
return nextUserIds != null ? nextUserIds.toString() : null;
|
||||
}
|
||||
}
|
||||
@@ -74,18 +74,6 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
// 获取 bpmn 模型
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
|
||||
identityService.setAuthenticatedUserId(TaskUtils.getUserId());
|
||||
|
||||
// 处理下一级审批人,将用户选择的下一个处理人保存到流程变量中
|
||||
if (StringUtils.isNotBlank(taskBo.getNextUserIds())) {
|
||||
// 如果有指定下一个处理人,则将其保存到流程变量中
|
||||
Map<String, Object> variables = taskBo.getVariables();
|
||||
if (variables == null) {
|
||||
variables = new HashMap<>();
|
||||
taskBo.setVariables(variables);
|
||||
}
|
||||
variables.put("nextUserIds", taskBo.getNextUserIds());
|
||||
}
|
||||
|
||||
if (DelegationState.PENDING.equals(task.getDelegationState())) {
|
||||
taskService.addComment(taskBo.getTaskId(), taskBo.getProcInsId(), FlowComment.DELEGATE.getType(), taskBo.getComment());
|
||||
taskService.resolveTask(taskBo.getTaskId());
|
||||
|
||||
Reference in New Issue
Block a user