feat(workflow): 新增审批人设置功能
- 在工作流启动页面添加审批人设置功能 - 实现指定用户、角色、部门和发起人四种审批类型 - 优化表单提交逻辑,支持审批人信息的传递 - 在后端增加处理审批人信息的逻辑 - 优化流程启动服务,支持设置下一个任务的审批人
This commit is contained in:
@@ -689,11 +689,77 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
||||
variables.put(BpmnXMLConstants.ATTRIBUTE_EVENT_START_INITIATOR, userIdStr);
|
||||
// 设置流程状态为进行中
|
||||
variables.put(ProcessConstants.PROCESS_STATUS_KEY, ProcessStatus.RUNNING.getStatus());
|
||||
|
||||
// 发起流程实例
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables);
|
||||
|
||||
// 如果包含审批人信息,则设置下一个任务的审批人
|
||||
try {
|
||||
if (variables.containsKey("flowable") && variables.get("flowable") != null) {
|
||||
Object flowableObj = variables.get("flowable");
|
||||
if (flowableObj instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> flowable = (Map<String, Object>) flowableObj;
|
||||
if (flowable.containsKey("candidateUsers")) {
|
||||
Object candidateUsersObj = flowable.get("candidateUsers");
|
||||
if (candidateUsersObj != null) {
|
||||
String candidateUsers = candidateUsersObj.toString();
|
||||
if (StringUtils.isNotBlank(candidateUsers)) {
|
||||
// 获取流程模型
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
|
||||
// 设置下一个任务的审批人
|
||||
this.assignNextUsers(bpmnModel, processInstance.getProcessInstanceId(), candidateUsers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 记录异常但不影响流程启动
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 第一个用户任务为发起人,则自动完成任务
|
||||
wfTaskService.startFirstTask(processInstance, variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下一个任务的审批人
|
||||
*
|
||||
* @param bpmnModel 流程模型
|
||||
* @param processInstanceId 流程实例ID
|
||||
* @param candidateUsers 候选人字符串
|
||||
*/
|
||||
private void assignNextUsers(BpmnModel bpmnModel, String processInstanceId, String candidateUsers) {
|
||||
if (StringUtils.isBlank(candidateUsers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取当前流程实例的所有任务
|
||||
List<Task> tasks = taskService.createTaskQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.list();
|
||||
|
||||
if (CollUtil.isEmpty(tasks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 为每个任务设置候选人
|
||||
for (Task task : tasks) {
|
||||
// 解析候选人字符串,格式可能是:userId1,userId2,userId3
|
||||
String[] userIds = candidateUsers.split(",");
|
||||
for (String userId : userIds) {
|
||||
if (StringUtils.isNotBlank(userId)) {
|
||||
// 添加候选人
|
||||
taskService.addCandidateUser(task.getId(), userId.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user