真是没想到Springboot+Flowable⼯作流开发会这么简单本⽂收录在个⼈博客:,技术资料共享,同进步
程序员是块砖,哪⾥需要哪⾥搬
公司内部的OA系统最近要升级改造,由于⼈⼿不够就把我借调过去了,但说真的我还没做过这⽅⾯的功能,第⼀次接触⼯作流的开发,还是有点好奇是个怎样的流程。
项⽬主要⽤Springboot+ Flowable重构原有的⼯作流程,Flowable是个⽤Java语⾔写的轻量级⼯作流引擎,上⼿⽐较简单开发效率也挺⾼的,⼀起学习下这个框架。
官⽅地址:/docs/userguide/index.html,分享的只是简单应⽤,深⼊研究还得看官⽅⽂档。
Flowable 核⼼依赖
<!--flowable⼯作流依赖-->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
流程设计
⼯作流开发的核⼼是任务流程的设计,Flowable官⽅建议采⽤业界标准BPMN2.0的XML来描述需要定义的⼯作流。
我们需要在resource⽬录下创建processes路径,存放相关的XML流程配置⽂件。Flowable框架会默认加载此⽬录下的⼯作流⽂件并解析XML,并将解析后的流程配置信息持久化到数据库。
Flowable是依赖于数据库的,但它并不需要我们⼿动的创建表,⽽是在程序第⼀次启动时,⾃动的向MySQL中创建它所需要的⼀系列表。
spring:
datasource:
url: jdbc:mysql://47.93.6.5:3306/order?serverTimezone=UTC
username: root
password: 123455
看到项⽬启动成功⼀共⽣成了60个表,数量还是⽐较多的,建议使⽤专门的数据库存在这些⼯作流表。
举个栗⼦:假如⼀个请假流程,需要经理审核通过,请假才能⽣效,如果他驳回流程结束。
接下来我们⽤XML翻译下上边的请假流程图,整体⾮常简单只要够细⼼就⾏了,⼀起看看每个标签都是什么含义。
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="/spec/BPMN/20100524/MODEL" xmlns:xsi="/2001/XMLSchema-instance" xmlns:flowable="/bpmn" xmlns:bpmndi="/spec/BPMN/20100524/DI"
xmlns:omgdc="/spec/DD/20100524/DC" xmlns:omgdi="/spec/DD/20100524/DI"
typeLanguage="/2001/XMLSchema" expressionLanguage="/1999/XPath"
targetNamespace="/processdef">
<process id="Leave" name="LeaveProcess" isExecutable="true">
<userTask id="leaveTask" name="请假" flowable:assignee="${leaveTask}"/>
<userTask id="managerTask" name="经理审核"/>
<exclusiveGateway id="managerJudgeTask"/>
<endEvent id="endLeave" name="结束"/>
<startEvent id="startLeave" name="开始"/>
<sequenceFlow id="modeFlow" sourceRef="leaveTask" targetRef="managerTask"/>
<sequenceFlow id="flowStart" sourceRef="startLeave" targetRef="leaveTask"/>
<sequenceFlow id="jugdeFlow" sourceRef="managerTask" targetRef="managerJudgeTask"/>
<endEvent id="endLeave2"/>
<sequenceFlow id="flowEnd" name="通过" sourceRef="managerJudgeTask" targetRef="endLeave">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${checkResult=='通过'}]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="rejectFlow" name="驳回" sourceRef="managerJudgeTask"
targetRef="endLeave2">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${checkResult=='驳回'}]]>
</conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_process">
<bpmndi:BPMNPlane bpmnElement="Leave" id="BPMNPlane_process">
<bpmndi:BPMNShape bpmnElement="leaveTask" id="BPMNShape_leaveTask">
<omgdc:Bounds height="79.99999999999999" width="100.0" x="304.60807973558974" y="122.00000000000001"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="managerTask" id="BPMNShape_managerTask">
<omgdc:Bounds height="80.0" width="100.0" x="465.0" y="122.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="managerJudgeTask" id="BPMNShape_managerJudgeTask">
<omgdc:Bounds height="40.0" width="40.0" x="611.5" y="142.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endLeave" id="BPMNShape_endLeave">
<omgdc:Bounds height="28.0" width="28.0" x="696.5" y="148.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startLeave" id="BPMNShape_startLeave">
<omgdc:Bounds height="30.0" width="30.0" x="213.2256558149128" y="147.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endLeave2"
id="BPMNShape_endLeave2">
<omgdc:Bounds height="28.0" width="28.0" x="617.5" y="73.32098285753572"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flowEnd" id="BPMNEdge_flowEnd">
<omgdi:waypoint x="651.1217948717949" y="162.37820512820514"/>
<omgdi:waypoint x="696.5002839785394" y="162.0891701657418"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="rejectFlow" id="BPMNEdge_rejectFlow">
<omgdi:waypoint x="631.866093577786" y="142.36609357778607" />
<omgdi:waypoint x="631.5931090276993" y="101.32067323657485" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="modeFlow" id="BPMNEdge_modeFlow">
<omgdi:waypoint x="404.60807973558974" y="162.0" />
<omgdi:waypoint x="465.0" y="162.0" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flowStart" id="BPMNEdge_flowStart">
<omgdi:waypoint x="243.2256558149128" y="162.0" />
<omgdi:waypoint x="304.60807973558974" y="162.0" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="jugdeFlow" id="BPMNEdge_jugdeFlow">
<omgdi:waypoint x="565.0" y="162.21367521367523" />
<omgdi:waypoint x="611.9141630901288" y="162.41416309012877" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
其实就是把流程图的各种线条逻辑,⽤不同的XML标签描绘出来了。
<process>:表⽰⼀个完整的⼯作流
<documentation>:对⼯作流的描述
<startEvent>:⼯作流中起点位置(开始)
<endEvent >:⼯作流中结束位置(结束)
<userTask>:代表⼀个任务审核节点(组长、经理等⾓⾊)
<exclusiveGateway>:逻辑判断节点,相当于流程图中的菱形框
<sequenceFlow>:链接各个节点的线条,sourceRef属性表⽰线的起始节点,targetRef属性表⽰线指向的节点。
上边这⼀⼤坨XML是不是看着超级⿇烦,要是有⾃动⽣成⼯具就好了,我发现IDEA⾃带设计⼯具,但实在是太难⽤了。
作为⼀个⾯向百度编程的程序员,别的不⾏上⽹答案的能⼒还是可以的,既然我都觉得写XML⿇烦,那么想来官⽅肯定也想到了,说不定有现成的⼯具,逛了⼀圈官⽹/downl
oads.html,居然真的到了。
springboot是啥github下载地址:.......
⼜了个在线编辑的⼯具:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论