flowable 监听获取流程下一节点

//任务启动时监听
@Component
@Transactional
public class StartListener implements ExecutionListener {

    @Autowired
    private RepositoryService repositoryService;


    @Override
    public void notify(DelegateExecution execution) {

        List userList = Lists.newArrayList();

        String crruentActivityId = execution.getCurrentActivityId();
        BpmnModel bpmnModel = repositoryService.getBpmnModel(execution.getProcessDefinitionId());
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionId(execution.getProcessDefinitionId()).singleResult();
        FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(crruentActivityId);
        // 输出连线
        List outFlows = flowNode.getOutgoingFlows();


        for (SequenceFlow sequenceFlow : outFlows)
        {
            // 下一个审批节点
            FlowElement targetFlow = sequenceFlow.getTargetFlowElement();
            //如果是用户任务则获取待办人或组
            if (targetFlow instanceof UserTask)
            {
                // 如果下个审批节点为userTask
                UserTask userTask = (UserTask) targetFlow;
                //获取用户
                List users = userTask.getCandidateUsers();
                //获取组
                List group = userTask.getCandidateGroups();
                for (String str : users) {
                    userList.add(UserUtils.getByLoginName(str));
                }
                for (String str : group) {
                    userList.addAll(UserUtils.getUserListByRoleName(str));
                }
            }
        }

        //发送消息...


    }
}

《心脏病学》

你可能感兴趣的:(flowable,java)