flowable使用

1.先导入依赖

复制代码
 <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>6.7.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-io</artifactId>
                    <groupId>commons-io</groupId>
                </exclusion>
            </exclusions>
        </dependency>
复制代码

 

2.提交流程

@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;

 

                           启动流程      流程的id         流程中携带的数据
 runtimeService.startProcessInstanceByKey("流程id", params);

 

          查询groups组下  在"流程id"     这个流程下的所有任务 

List<Task> tasks = taskService.createTaskQuery().processDefinitionKey("流程id").taskCandidateGroupIn(groups).list();

获取这个任务中所携带的数据
Map<String, Object> params = taskService.getVariables(task.getId());

//根据任务id查询任务信息
Task task = taskService.createTaskQuery().processDefinitionKey("流程id").taskId(dto.getTaskId()).singleResult();

//提交任务 params 是任务中需要的参数.
taskService.complete(dto.getTaskId(), params);







列子:
1.bpmn20.xml
复制代码
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             xmlns:flowable="http://flowable.org/bpmn"
             typeLanguage="http://www.w3.org/2001/XMLSchema"
             expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://www.flowable.org/processdef">


    <process id="holidayRequest" name="Holiday Request"       
             isExecutable="true">                                                   //holidayRequest 这个是流程的id

        <startEvent id="startEvent"/>                                                //流程开始
        <sequenceFlow sourceRef="startEvent" targetRef="approveTask"/>              //从startEvent到approveTask任务

        <userTask id="approveTask" name="Approve or reject request"        
                  flowable:candidateGroups="managers"/>                             // candidateGroups   这个任务属于managers这个组            
        <sequenceFlow sourceRef="approveTask" targetRef="decision"/>

        <exclusiveGateway id="decision"/>
        <sequenceFlow sourceRef="decision" targetRef="externalSystemCall">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[${approved}]]>                                             //如果approved为true 则去externalSystemCall      否则走sendRejectionMail
</conditionExpression> </sequenceFlow> <sequenceFlow sourceRef="decision" targetRef="sendRejectionMail"> <conditionExpression xsi:type="tFormalExpression"> <![CDATA[${!approved}]]> </conditionExpression> </sequenceFlow> <serviceTask id="externalSystemCall" name="Enter holidays inexternal system" flowable:class="org.flowable.CallExternalSystemDelegate"/> //flowable:class="org.flowable.CallExternalSystemDelegate 走这个类 <sequenceFlow sourceRef="externalSystemCall" targetRef="holidayApprovedTask"/> <userTask id="holidayApprovedTask" name="Holiday approved" flowable:assignee="${employee}"/> //这个需要  flowable:assignee="${employee} 审批人名字和他提交流程时候存入的employee信息一样的人审批 <sequenceFlow sourceRef="holidayApprovedTask" targetRef="approveEnd"/> <serviceTask id="sendRejectionMail" name="Send out rejection email" flowable:class="org.flowable.SendRejectionMail"/>    //flowable:class="org.flowable.SendRejectionMail走这个类 <sequenceFlow sourceRef="sendRejectionMail" targetRef="rejectEnd"/> <endEvent id="approveEnd"/> <endEvent id="rejectEnd"/> </process> </definitions>
复制代码








 

posted @   不想当将军的好士兵  阅读(244)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示