举个栗子:假如一个请假流程,需要经理审核通过,请假才能生效,如果他驳回流程结束。
接下来我们用 XML
翻译下上边的请假流程图,整体非常简单只要够细心就行了,一起看看每个标签都是什么含义。
<definitions xmlns=“http://www.omg.org/spec/BPMN/20100524/MODEL” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:flowable=“http://flowable.org/bpmn” 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”
typeLanguage=“http://www.w3.org/2001/XMLSchema” expressionLanguage=“http://www.w3.org/1999/XPath”
targetNamespace=“http://www.flowable.org/processdef”>
<![CDATA[${checkResult=='通过'}]]><sequenceFlow id=“rejectFlow” name=“驳回” sourceRef=“managerJudgeTask”
targetRef=“endLeave2”>
<![CDATA[${checkResult=='驳回'}]]><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>
复制代码
其实就是把流程图的各种线条逻辑,用不同的XML
标签描绘出来了。
<process>
: 表示一个完整的工作流
<documentation>
: 对工作流的描述
<startEvent>
: 工作流中起点位置(开始)
<endEvent >
: 工作流中结束位置(结束)
<userTask>
: 代表一个任务审核节点(组长、经理等角色)
<exclusiveGateway>
: 逻辑判断节点,相当于流程图中的菱形框
<sequenceFlow>
:链接各个节点的线条,sourceRef
属性表示线的起始节点,targetRef
属性表示线指向的节点。
上边这一大坨XML
是不是看着超级麻烦,要是有自动生成工具就好了,我发现IDEA
自带设计工具,但实在是太难用了。
作为一个面向百度编程的程序员,别的不行上网找答案的能力还是可以的,既然我都觉得写XML
麻烦,那么想来官方肯定也想到了,说不定有现成的工具,逛了一圈官网https://www.flowable.org/downloads.html
,居然真的找到了。
github
下载地址:github.com/flowable/fl……
又找了个在线编辑的工具: www.learun.cn:8090/home_online…
流程审批
流程设计完后剩下的就是对工作流的审批和生成流程图。
首先启动一个请假的流程,以员工ID staffId
作为唯一标识,XML
文件中会接收变量 leaveTask
,Flowable
内部会进行数据库持久化,并返回一个流程Id processId
,用它可以查询工作流的整体情况,任务Id task
为员工具体的请假任务。
注意:一个请假流程 processId
中可以包含多个请假任务 taskId
。
/**
-
@author xiaofu
-
@description 启动流程
-
@date 2020/8/26 17:36
*/
@RequestMapping(value = “startLeaveProcess”)
@ResponseBody
public String startLeaveProcess(String staffId) {
HashMap<String, Object> map = new HashMap<>();
map.put(“leaveTask”, staffId);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(“Leave”, map);
StringBuilder sb = new StringBuilder();
sb.append(“创建请假流程 processId:” + processInstance.getId());
List tasks = taskService.createTaskQuery().taskAssignee(staffId).orderByTaskCreateTime().desc().list();
for (Task task : tasks) {
sb.append(“任务taskId:” + task.getId());
}
return sb.toString();
}
复制代码
用启动流程时返回的 processId
看一下一下当前的流程图
http://localhost:4000/leave/createProcessDiagramPic?processId=37513
复制代码
最近我根据上述的技术体系图搜集了几十套腾讯、头条、阿里、美团等公司21年的面试题,把技术点整理成了视频(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分
ssDiagramPic?processId=37513
复制代码
[外链图片转存中…(img-vGUlSFM4-1714735416619)]
最近我根据上述的技术体系图搜集了几十套腾讯、头条、阿里、美团等公司21年的面试题,把技术点整理成了视频(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分
[外链图片转存中…(img-QUxXhBrC-1714735416619)]