Spring Boot整合Activiti6.0.0

博客介绍了工作流相关操作,包括添加依赖、修改spring boot配置文件、注入服务、启动任务流程,还提及如需指定下一步任务人员可进行相应操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

添加依赖

<!--spring boot 快速启动依赖-->
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter-basic</artifactId>
    <version>6.0.0</version>
</dependency>
<!--自动部署布局依赖-->
 <dependency>
 	<groupId>org.activiti</groupId>
 	<artifactId>activiti-bpmn-layout</artifactId>
 	<version>6.0.0.RC1</version>
 </dependency>

修改spring boot 配置文件

spring:
	activiti:
    	check-process-definitions: false # activti是否自动部署
    	db-identity-used: false #是否使用activti自带的用户体系
    	database-schema-update: true #是否每次都更新数据库
    	process-definition-location-prefix: classpath:/processes/
    	history-level: full #full最高级别

注入服务

/**
     * 任务管理
     */
    @Autowired
    private TaskService taskService;

    /**
     * 历史管理(执行完的数据)
     */
    @Autowired
    private HistoryService historyService;

    /**
     * 管理流程定义
     */
    @Autowired
    private RepositoryService repositoryService;

    /**
     * 组织机构管理
     */
    @Autowired
    private IdentityService identityService;

    @Autowired
    private RuntimeService runtimeService;

启动任务流程

 		Map<String, Object> vars = new HashMap<>();
        ProcessInstance processInstance = runtimeService
                .startProcessInstanceByKey(processDefinitionKey,vars);
        System.out.println("流程实例ID:" + processInstance.getProcessInstanceId());
        System.out.println("流程定义ID:" + processInstance.getProcessDefinitionId());

        //获得流程模型
        Task task = taskService.createTaskQuery()
                .processInstanceId(processInstance.getProcessInstanceId())
                .singleResult();
        //taskService.addComment(task.getId(),task.getProcessInstanceId(),"");
        taskService.complete(task.getId(), vars);
        //获取下一步task
        List<TaskModel> userTasks = getNextNode(processInstance.getProcessInstanceId());
public List<TaskModel> getNextNode(String processInstanceId) throws Exception {
        String processDefinitionId  = historyService.createHistoricProcessInstanceQuery()
                .processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();
        List<Task> tasks = taskService.createTaskQuery()
                .processInstanceId(processInstanceId)
                .list();
        List<TaskModel> userTasks = new ArrayList<>();
        BpmnModel model = repositoryService.getBpmnModel(processDefinitionId);
        if(model != null&&tasks!=null&&tasks.size()>0) {
            //获得流程模型的所有节点
            Collection<FlowElement> flowElements = model.getMainProcess().getFlowElements();
            for(FlowElement e : flowElements) {
                for(Task t : tasks){
                    if(e.getId().equals(t.getTaskDefinitionKey())){
                        if( e instanceof UserTask){
                            userTasks.add(new TaskModel((UserTask)e,t));
                        }else{
                            List<SequenceFlow> currentUSer = ((UserTask)e).getOutgoingFlows();
                            for(SequenceFlow s : currentUSer){
                                nextNode(flowElements,s,userTasks,t);
                            }
                        }
                    }
                }
            }
        }
        return userTasks;
    }

private void nextNode(Collection<FlowElement> flowElements,SequenceFlow currentSequenceFlow,List<TaskModel> userTasks,Task task)throws Exception{
        //获得当前线在
        String  SequenceFlowId =   currentSequenceFlow.getTargetRef();
        for(FlowElement e : flowElements){
            if(e.getId().equals(SequenceFlowId)){
                //判断类型
                //如果是排他网管
                if(e instanceof ExclusiveGateway){
                    //默认流程线
                    String defaultFlowString = ((ExclusiveGateway) e).getDefaultFlow();
                    SequenceFlow defaultFlow = null;
                    //获取该节点下一步线集合
                    List<SequenceFlow> egSequenceFlow  = ((ExclusiveGateway) e).getOutgoingFlows();
                    //标识
                    boolean boo = true;
                    for(int i=0;i<egSequenceFlow.size();i++){
                        //如果是默认路线
                        if(egSequenceFlow.get(i).getId().equals(defaultFlowString)){
                            defaultFlow = egSequenceFlow.get(i);
                        }
                        if(!StringUtils.isEmpty(egSequenceFlow.get(i).getConditionExpression())){
                            //递归获取排他网关路线
                            nextNode(flowElements,egSequenceFlow.get(i),userTasks,task);
                        }else{
                            continue;
                        }

                        //如果最后一个走完没有el为true的,则查看是否有默认流程,如果没有抛出异常
                        if(i==egSequenceFlow.size()-1&&boo){
                            if(StringUtils.isEmpty(defaultFlowString)){
                                throw new Exception("流程异常");
                            }else{
                                //如果有默认流程 递归
                                nextNode(flowElements,defaultFlow,userTasks,task);
                            }
                        }
                    }
                    //如果是user用户审批节点
                }else if(e instanceof UserTask){
                    userTasks.add(new TaskModel((UserTask) e,task));
                }
            }
        }
    }

如需指定下一步任务人员可以使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值