feat(workflow): 实现自定义选择下一个处理人功能

- 在前端增加提示信息,指导用户指定下一个任务的处理人
- 在后端增加逻辑,处理用户选择的下一个处理人
- 修改数据库,增加采购计划详情编号字段- 优化采购计划详情查询条件,支持按详情编号查询
This commit is contained in:
2025-08-22 10:31:24 +08:00
parent 0368ed504b
commit e91b981923
10 changed files with 139 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* 用户任务监听器
*
@@ -20,8 +22,24 @@ public class UserTaskListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
//TODO 实现你的任务监听器逻辑
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]);
}
}
}
}
}

View File

@@ -0,0 +1,68 @@
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;
}
}