首页 > 其他分享 >flowable使用

flowable使用

时间:2022-11-16 17:12:23浏览次数:51  
标签:flowable 流程 使用 任务 params taskService id

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>








 

标签:flowable,流程,使用,任务,params,taskService,id
From: https://www.cnblogs.com/hj98/p/16895915.html

相关文章