Camunda获取下一个用户审批节点

这块代码主要功能是获取下一个节点的办理用户,使用条件有限制,目前只适用于当前节点下,只有一个出路,下一个节点是用户任务的情况;
复杂的可以参考:Camunda如何获取(预取)下一审批节点 根据实际情况进行改造


@Slf4j
public class TaskListener implements ExecutionListener {
    
    
    private static RepositoryService repositoryService;

    static {
    
    
    SpringContextUtils.getBean(RepositoryService.class);
    }

    @Override
    public void notify(DelegateExecution execution) throws Exception {
    
    
        try {
    
    
            String bpmDataId = (String) execution.getVariable(WorkFlowGlobals.BPM_DATA_ID);
            // 获取当前流程下一个流向节点
            String flowCode = ((ExecutionEntity) execution).getActivity().getOutgoingTransitions().get(0).getDestination().getId();
            // 获取流程定义
            BpmnModelInstance modelInstance = repositoryService.getBpmnModelInstance(execution.getProcessDefinitionId());
            // 获取所有用户任务节点
            Collection<UserTask> userTaskList = modelInstance.getModelElementsByType(UserTask.class);
            UserTask task = userTaskList.stream().filter(e -> e.getId().equals(flowCode)).collect(Collectors.toList()).get(0); // 获取当前节点
            if (task != null) {
    
    
                StrSubstitutor strSubstitutor = new StrSubstitutor(execution.getVariables());
                String assignee = strSubstitutor.replace(task.getCamundaAssignee());
        
            }
        } catch (Exception e) {
    
    
            e.printStackTrace();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_39517116/article/details/124213149
今日推荐