精仿虎嗅网织梦网站模板,一般网站的服务器,微信审批小程序,企业建立网站的必要性在于背景 使用flowable自带的flowable-ui制作流程图 使用springboot开发流程使用的接口完成流程的业务功能
文章来源#xff1a;https://blog.csdn.net/zhan107876/article/details/120815560 一、flowable-ui部署运行 flowable-6.6.0 运行 官方demo
参考文档#xff1a; htt…
背景 使用flowable自带的flowable-ui制作流程图 使用springboot开发流程使用的接口完成流程的业务功能
文章来源https://blog.csdn.net/zhan107876/article/details/120815560 一、flowable-ui部署运行 flowable-6.6.0 运行 官方demo
参考文档 https://flowable.com/open-source/docs/bpmn/ch14-Applications/ 1、从官网下载flowable-6.6.0 :https://github.com/flowable/flowable-engine/releases/download/flowable-6.6.0/flowable-6.6.0.zip
2、将压缩包中的flowable-6.6.0\wars\flowable-ui.war丢到Tomcat中跑起来
3、打开http://localhost:8080/flowable-ui用账户admin/test 登录 4、进入APP.MODELER创建流程之后可以导出流程到项目中使用或者配置apache-tomcat-9.0.37\webapps\flowable-ui\WEB-INF\classes\flowable-default.properties连接本地数据库 注意需要将java驱动jarmysql-connector-java-5.1.45.jar复制到apache-tomcat-9.0.37\webapps\flowable-rest\WEB-INF\lib 这样创建的流程后端程序就能直接使用 二、绘制流程图 根据业务需要在 flowable-uiAPP.MODELER里面绘制流程图示例如上图。先解释一些概念。 **事件event**通常用于为流程生命周期中发生的事情建模图里是【开始、结束】两个圈。 **顺序流sequence flow**是流程中两个元素间的连接器。图里是【箭头线段】。 **网关gateway**用于控制执行的流向。图里是【菱形中间有X】 **用户任务user task**用于对需要人工执行的任务进行建模。图里是【矩形】。
简单的工作流大概就这些元素(还有很多这里就不扩展了)。下面描述一下工作流是如何流动的。
首先启动了工作流后由【开始】节点自动流向【学生】节点等待该任务执行。任务被分配的学生用户执行后流向 【老师】节点再次等待该任务执行。被分配的老师用户执行后流向 【网关】网关以此检查每个出口流向符合条件的任务比如这里老师执行任务时是同意就流向【校长】节点等待该任务执行。执行后跟老师类似同意后就流向【结束】节点整个流程到此结束。
绘图细节
1、保留流程模型 2、顺序流可以设置流条件来限制流动比如上面的网关出口就设置了条件 3、任务需要分配任务的执行用户可以分配到候选组也可以直接分配到候选人 最后导出工作流文件 文件内容
?xml version1.0 encodingUTF-8?definitions xmlnshttp://www.omg.org/spec/BPMN/20100524/MODEL xmlns:xsihttp://www.w3.org/2001/XMLSchema-insmtece xmlns:xsdhttp://www.w3.org/2001/XMLSchema xmlns:flowablehttp://flowable.org/bpmn xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI xmlns:omgdchttp://www.omg.org/spec/DD/20100524/DC xmlns:omgdihttp://www.omg.org/spec/DD/20100524/DI typeLanguagehttp://www.w3.org/2001/XMLSchema expressionLanguagehttp://www.w3.org/1999/XPath targetNamespacehttp://www.flowable.org/processdef process idleave_approval name请假审批 isExecutabletrue startEvent idstart name开始 flowable:initiatorstartuser flowable:formFieldValidationtrue/startEvent userTask idstu_task name学生 flowable:candidateGroupsstu_group flowable:formFieldValidationtrue/userTask sequenceFlow idflow1 sourceRefstart targetRefstu_task/sequenceFlow userTask idte_task name老师 flowable:candidateGroupste_group flowable:formFieldValidationtrue/userTask exclusiveGateway idgetway1 name网关1/exclusiveGateway userTask idmte_task name校长 flowable:candidateGroupsmte_group flowable:formFieldValidationtrue/userTask exclusiveGateway idgetway2 name网关2/exclusiveGateway endEvent idend name结束/endEvent sequenceFlow idflow1 name请假 sourceRefstu_task targetRefte_task skipExpression${commandagree}/sequenceFlow sequenceFlow idflow3_1 name同意 sourceRefgetway1 targetRefmte_task conditionExpression xsi:typetFormalExpression![CDATA[${commandagree}]]/conditionExpression /sequenceFlow sequenceFlow idflow2 name审批 sourceRefte_task targetRefgetway1/sequenceFlow sequenceFlow idflow3_2 name拒绝 sourceRefgetway1 targetRefstu_task conditionExpression xsi:typetFormalExpression![CDATA[${commandrefuse}]]/conditionExpression /sequenceFlow sequenceFlow idflow4 name审批 sourceRefmte_task targetRefgetway2/sequenceFlow sequenceFlow idflow4_1 name同意 sourceRefgetway2 targetRefend skipExpression${commandfree} conditionExpression xsi:typetFormalExpression![CDATA[${commandagree}]]/conditionExpression /sequenceFlow sequenceFlow idflow4_2 name拒绝 sourceRefgetway2 targetRefstu_task conditionExpression xsi:typetFormalExpression![CDATA[${commandrefuse}]]/conditionExpression /sequenceFlow /process bpmndi:BPMNDiagram idBPMNDiagram_leave_approval 这里先省略 /bpmndi:BPMNDiagram/definitions4、bpmn文件导入
如果需要可以把这个流程文件下载下来直接导入使用 三、后台项目搭建 后台项目基于jdk8使用springboot框架
spring 版本
parent groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version2.3.0.RELEASE/version relativePath/ !-- lookup parent from repository --/parent项目依赖pom.xml
dependency groupIdorg.flowable/groupId artifactIdflowable-spring-boot-starter/artifactId version6.6.0/version/dependencydependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactId version5.1.45/version/dependency项目配置application.yml
spring: datasource: url: jdbc:mysql://localhost:3306/flowable?useSSLfalsecharacterEncodingUTF-8serverTimezoneGMT%2B8 driver-class-name: com.mysql.jdbc.Driver username: root password: 123456四、数据库 1、Flowable的所有数据库表都以ACT_开头。第二部分是说明表用途的两字符标示符。服务API的命名也大略符合这个规则。
2、ACT_RE_: RE’代表repository。带有这个前缀的表包含“静态”信息例如流程定义与流程资源图片、规则等。
3、ACT_RU_: RU’代表runtime。这些表存储运行时信息例如流程实例process instance、用户任务user task、变量variable、作业job等。Flowable只在流程实例运行中保存运行时数据并在流程实例结束时删除记录。这样保证运行时表小和快。
4、ACT_HI_: HI’代表history。这些表存储历史数据例如已完成的流程实例、变量、任务等。
5、ACT_GE_: 通用数据。在多处使用。
1通用数据表2个 act_ge_bytearray二进制数据表如流程定义、流程模板、流程图的字节流文件 act_ge_property属性数据表不常用
2历史表8个HistoryService接口操作的表 act_hi_actinst历史节点表存放流程实例运转的各个节点信息包含开始、结束等非任务节点 act_hi_attachment历史附件表存放历史节点上传的附件信息不常用 act_hi_comment历史意见表 act_hi_detail历史详情表存储节点运转的一些信息不常用 act_hi_identitylink历史流程人员表存储流程各节点候选、办理人员信息常用于查询某人或部门的已办任务 act_hi_procinst历史流程实例表存储流程实例历史数据包含正在运行的流程实例 act_hi_taskinst历史流程任务表存储历史任务节点 act_hi_varinst流程历史变量表存储流程历史节点的变量信息
3用户相关表4个IdentityService接口操作的表 act_id_group用户组信息表对应节点选定候选组信息 act_id_info用户扩展信息表存储用户扩展信息 act_id_membership用户与用户组关系表 act_id_user用户信息表对应节点选定办理人或候选人信息
4流程定义、流程模板相关表3个RepositoryService接口操作的表 act_re_deployment部属信息表存储流程定义、模板部署信息 act_re_procdef流程定义信息表存储流程定义相关描述信息但其真正内容存储在act_ge_bytearray表中以字节形式存储 act_re_model流程模板信息表存储流程模板相关描述信息但其真正内容存储在act_ge_bytearray表中以字节形式存储
5流程运行时表6个RuntimeService接口操作的表 act_ru_task运行时流程任务节点表存储运行中流程的任务节点信息重要常用于查询人员或部门的待办任务时使用 act_ru_event_subscr监听信息表不常用 act_ru_execution运行时流程执行实例表记录运行中流程运行的各个分支信息当没有子流程时其数据与act_ru_task表数据是一一对应的 act_ru_identitylink运行时流程人员表重要常用于查询人员或部门的待办任务时使用 act_ru_job运行时定时任务数据表存储流程的定时任务信息 act_ru_variable运行时流程变量数据表存储运行中的流程各节点的变量信息 五、流程引擎API与服务 引擎API是与Flowable交互的最常用手段。总入口点是ProcessEngine。 1、RepositoryService很可能是使用Flowable引擎要用的第一个服务。这个服务提供了管理与控制部署(deployments)与流程定义(process definitions)的操作。管理静态信息
2、RuntimeService用于启动流程定义的新流程实例。
3、IdentityService很简单。它用于管理创建更新删除查询……组与用户。
4、FormService是可选服务。也就是说Flowable没有它也能很好地运行而不必牺牲任何功能。
5、HistoryService暴露Flowable引擎收集的所有历史数据。要提供查询历史数据的能力。
6、ManagementService通常在用Flowable编写用户应用时不需要使用。它可以读取数据库表与表原始数据的信息也提供了对作业(job)的查询与管理操作。
7、DynamicBpmnService可用于修改流程定义中的部分内容而不需要重新部署它。例如可以修改流程定义中一个用户任务的办理人设置或者修改一个服务任务中的类名。
接下来使用之前的请假流程图上代码
代码
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;/** * TestFlowable * * Author * Date: 2021/10/17 23:35 * Version 1.0 /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() { / * Date: 2021/10/17 23:38 * Step 1: 部署xml压缩到zip形式直接xml需要配置相对路径麻烦暂不用 / try { 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()); } catch (FileNotFoundException e) { e.printStackTrace(); } / * Date: 2021/10/17 23:40 * Step 2: 查询部署的流程定义 / List list repositoryService.createProcessDefinitionQuery().processDefinitionKey(“leave_approval”).list(); List pages repositoryService.createProcessDefinitionQuery().processDefinitionKey(“leave_approval”).listPage(1, 30); / * Date: 2021/10/17 23:40 * Step 3: 启动流程创建实例 / String processDefinitionKey “leave_approval”;//流程定义的key,对应请假的流程图 String businessKey “schoolleave”;//业务代码根据自己的业务用 MapString, Object variablesDefinition new HashMap();//流程变量可以自定义扩充 ProcessInstance processInstance runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variablesDefinition); log.info(“启动成功:{}”, processInstance.getId()); / * Date: 2021/10/17 23:40 * Step 4: 查询指定流程所有启动的实例列表 * 列表或 分页 删除 / List executions runtimeService.createExecutionQuery().processDefinitionKey(“leave_approval”).list(); List executionPages runtimeService.createExecutionQuery().processDefinitionKey(“leave_approval”).listPage(1, 30);// runtimeService.deleteProcessInstance(processInstanceId, deleteReason); //删除实例 / * Date: 2021/10/17 23:40 * Step 5: 学生查询可以操作的任务,并完成任务 / String candidateGroup “stu_group”; //候选组 xml文件里面的 flowable:candidateGroups“stu_group” List taskList taskService.createTaskQuery().taskCandidateGroup(candidateGroup).orderByTaskCreateTime().desc().list(); for (Task task : taskList) { // 申领任务 taskService.claim(task.getId(), “my”); // 完成 taskService.complete(task.getId()); } / * Date: 2021/10/17 23:40 * Step 6: 老师查询可以操作的任务,并完成任务 / String candidateGroupTe “te_group”; //候选组 xml文件里面的 flowable:candidateGroups“te_group” List taskListTe taskService.createTaskQuery().taskCandidateGroup(candidateGroupTe).orderByTaskCreateTime().desc().list(); for (Task task : taskListTe) { // 申领任务 taskService.claim(task.getId(), “myte”); // 完成 MapString, Object variables new HashMap(); variables.put(“command”,“agree”); //携带变量用于网关流程的条件判定这里的条件是同意 taskService.complete(task.getId(), variables); } / * Date: 2021/10/18 0:17 * Step 7: 历史查询因为一旦流程执行完毕活动的数据都会被清空上面查询的接口都查不到数据但是提供历史查询接口 / // 历史流程实例 List historicProcessList historyService.createHistoricProcessInstanceQuery().processDefinitionKey(“leave_approval”).list(); // 历史任务 List historicTaskList historyService.createHistoricTaskInstanceQuery().processDefinitionKey(“leave_approval”).list(); // 实例历史变量 , 任务历史变量 // historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId); // historyService.createHistoricVariableInstanceQuery().taskId(taskId); // 分隔符************** // 分隔符*************** // 可能还需要的API // 移动任务人为跳转任务 // runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId) // .moveActivityIdTo(currentActivityTaskId, newActivityTaskId).changeState(); // 如果在数据库配置了分组和用户还会用到 List users identityService.createUserQuery().list(); //用户查询用户id对应xml 里面配置的用户 List groups identityService.createGroupQuery().list(); //分组查询分组id对应xml 里面配置的分组 如 stu_groupte_group 在表里是id的值 // 另外每个查询后面都可以拼条件内置恁多查询包括模糊查询大小比较都有 }} 六、参考资料 分享牛Flowable文档汉化https://github.com/qiudaoke/flowable-userguide 猫七姑娘 flowable-6.6.0 运行官方 demo 华格瑞沙 https://www.cnblogs.com/yangjiming/p/10938515.html