本文共 5639 字,大约阅读时间需要 18 分钟。
流able工作流引擎是流程自动化领域的重要工具,帮助开发者构建高效的业务流程。以下是流able-6.6.0的官方示例应用程序的部署与使用指南。
首先,从流able的官方GitHub仓库下载流able-6.6.0的压缩包:
https://github.com/flowable/flowable-engine/releases/download/flowable-6.6.0/flowable-6.6.0.zip
解压后,将flowable-6.6.0\wars\flowable-ui.war文件部署到Apache Tomcat 9.0.37的webapps\flowable-ui目录下。
访问http://localhost:8080/flowable-ui,使用默认账户admin和密码test登录。
进入APP.MODELER,设计并创建所需的流程定义。流able默认连接到本地数据库,因此需要将MySQL驱动mysql-connector-java-5.1.45.jar拷贝至apache-tomcat-9.0.37\webapps\flowable-rest\WEB-INF\lib。
流able的流程定义文件采用BPMN格式,文件命名为leave_approval.bpmn20.xml。文件内容如下:
将上述文件保存为leave_approval.bpmn20.xml,可以通过流able UI导入至工作区,或者配置数据库连接后直接使用。
在Spring Boot项目中,添加必要的依赖项:
org.flowable flowable-spring-boot-starter 6.6.0 mysql mysql-connector-java 5.1.45
配置application.yml,设置数据库连接信息:
spring: datasource: url: jdbc:mysql://localhost:3306/flowable?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT+8 driver-class-name: com.mysql.jdbc.Driver username: root password: 123456
Flowable引擎提供多个核心服务:
以下是启动流程实例的示例代码:
import org.flowable.engine.RuntimeService;import org.flowable.engine.ProcessInstance;public class TestFlowable { @Autowired private RuntimeService runtimeService; public void startLeaveApprovalProcess() { Map variables = new HashMap<>(); variables.put("command", "agree"); String processDefinitionKey = "leave_approval"; String businessKey = "schoolleave"; ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( processDefinitionKey, businessKey, variables ); System.out.println("流程启动成功:" + processInstance.getId()); }} Flowable引擎的数据库表主要分为运行时表和历史表:
运行时表:
ACT_RU_EXECUTION:运行流程执行实例ACT_RU_TASK:运行流程任务节点ACT_RU_VARIABLE:流程变量历史表:
ACT_HI_PROCESSION:历史流程实例ACT_HI_TASK:历史流程任务以下是完整的Spring Boot项目代码示例:
import lombok.extern.slf4j.Slf4j;import org.flowable.engine.HistoryService;import org.flowable.engine.RepositoryService;import org.flowable.engine.RuntimeService;import org.flowable.engine.history.HistoricProcessInstance;import org.flowable.engine.repository.Deployment;import org.flowable.engine.repository.ProcessDefinition;import org.flowable.engine.runtime.Execution;import org.flowable.engine.runtime.ProcessInstance;import org.flowable.idm.api.Group;import org.flowable.idm.api.User;import org.flowable.task.api.Task;import org.flowable.task.api.history.HistoricTaskInstance;import org.springframework.beans.factory.annotation.Autowired;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.zip.ZipInputStream;@Slf4jpublic class TestFlowable { @Autowired private RepositoryService repositoryService; @Autowired private RuntimeService runtimeService; @Autowired private HistoryService historyService; @Autowired private org.flowable.engine.TaskService taskService; @Autowired private org.flowable.engine.IdentityService identityService; public void createDeploymentZip() throws FileNotFoundException { File zipTemp = new File("f:/leave_approval.bpmn20.zip"); ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipTemp)); Deployment deployment = repositoryService.createDeployment() .addZipInputStream(zipInputStream) .deploy(); log.info("部署成功:{}", deployment.getId()); } public void testProcessDefinition() { List list = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave_approval").list(); List pages = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave_approval").listPage(1, 30); } public void startLeaveApproval() { String processDefinitionKey = "leave_approval"; String businessKey = "schoolleave"; Map variables = new HashMap<>(); variables.put("command", "agree"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables); log.info("流程启动成功:{}", processInstance.getId()); } public void queryHistoricProcess() { List historicProcessList = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("leave_approval").list(); List historicTaskList = historyService.createHistoricTaskInstanceQuery().processDefinitionKey("leave_approval").list(); }} runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);runtimeService.createExecutionQuery().processDefinitionKey("leave_approval").list();historyService.createHistoricProcessInstanceQuery().processDefinitionKey("leave_approval").list();taskService.createTaskQuery().taskCandidateGroup(candidateGroup).orderByTaskCreateTime().desc().list();通过以上方法,可以方便地开发和管理基于Flowable的工作流系统。
转载地址:http://lsqfk.baihongyu.com/