術語
Workflow:工作流,即在計算機中自動化運行的業務流程
WfMS:Workflow Management System,工作流管理系統
BPM:Business Process Management,業務流程管理
PVM:Process Virtual Machine,流程虛擬機
OMG:Object Management Group(對象管理組織),一個致力于建立( 程序、系統、業務流程)建模標準的國際協會
OASIS:Organizationfor the Advancement of Structured Information Standards,結構化信息標準促進組織
WfMC:Workflow Management Coalition,工作流程管理聯盟
XPDL:XML Process Definition Language,WfMC提出的業務流程描述規范
JPDL:JBoss jBPM Process Definition Language,jBPM的業務流程描述標準
BPEL:Business Process Execution Language,業務過程執行語言,用來描述業務過程的XML規范
WSBPEL(BPEL-WS):Web Services Business Process Execution Language,OASIS發布的Web服務形式的BPEL
BPDM:Business Process Definition Metamodel,業務流程定義元模型,OMG組織提出的用來解決BPMN存儲和交換問題的規范
BPMN:Business Process Model and Notation,OMG推出的業務流程圖標準
CMMN:Case Management Model and Notation,OMG發布的案例管理圖標準,是對BPMN的擴展;它用聲明式表示法來描述流程
DMN:Decision Modeling Notation,OMG發布的決策建模圖標準,用于封裝BPMN中的業務決策邏輯(業務規則)
OA:Office Automation,辦公自動化系統
ERP:Enterprise Resource Planning,企業資源管理系統
CRM:Customer Relationship Management,客戶關系管理系統
各種工作流引擎
jBPM(java Business Process Management):Tom Baeyens(湯姆 貝恩斯)于2003年發布,于2004 年加入JBoss,jBPM4引入了PVM;而后Tom Baeyens離開了JBoss,jBPM5 放棄了 jBPM 4,基于Drools Flow重頭來過
Activiti:Tom Baeyens離開了JBoss后加入了Alfresco,于2010年推出了Activiti 5,Activiti 6移除了PVM
Camunda BPM:2012年Activiti的貢獻者之一Camunda(卡蒙達),從Activiti 5項目fork出一個新項目,即Camunda BPM
Flowable:2016年Activiti的開發者之一Tijs Rademakers,從Activiti 6項目fork出一個新項目,即Flowable 6
Osworkflow:OpenSymphony組織開發的工作流引擎
馳騁BPM(ccbpm、JFlow):濟南馳騁信息技術有限公司開發的工作流引擎
其他:Bonitasoft、Enhydra Shark、ProcessMaker、Apache ODE等
相關資源
Drools:JBoss出品規則引擎
Drools Flow:Drools 的工作流組件
選型
Camunda功能較多,Flowable更活躍
Flowable 知識
五個官方應用(包含于Flowable下載包里的wars目錄)
flowable-modeler.war:流程定義管理
flowable-task.war:用戶任務管理
flowable-idm.war:用戶組權限管理
flowable-rest.war:流程引擎對外提供的API接口
flowable-admin.war:后臺管理
流程設計器:將 flowable-modeler.war 和 flowable-idm.war部署到tomcat,即可得到網頁版流程設計器(訪問路徑為 /flowable-modeler,默認賬號為 admin/test )
Flowable五大引擎(包含于Flowable下載包里的libs目錄)
ProcessEngine(流程引擎)、DmnEngine(決策引擎)、IdmEngine(身份識別引擎)、ContentEngine(內容引擎)、FormEngine(表單引擎)
應用首次啟動時,Flowable會往數據庫里添加一些表
ACT_RE_ *:RE代表repository。具有此前綴的表包含靜態信息,例如流程定義和流程資源(圖像,規則等)。
ACT_RU_ *:RU代表runtime。這些是包含運行時的流程實例,用戶任務,變量,作業等的運行時數據的運行時表。Flowable僅在流程實例執行期間存儲運行時數據,并在流程實例結束時刪除記錄。這使運行時表保持小而快。
ACT_HI_ *:HI代表history。這些是包含歷史數據的表,例如過去的流程實例,變量,任務等
ACT_GE_ :general數據,用于各種用例
ACT_ID_:Idm的用戶、組
Flowable應用組成
1、創建 SpringBoot + Mybatis 項目
2、pom.xml
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.5.0</version>
</dependency>
3、流程配置xml(放在/resources/processes下,以 .bpmn2.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: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">
<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>
4、Controller
@RestController
@RequestMapping(value = "/flow")
public class FlowController {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@ApiOperation(value = "實例化一個流程")
@RequestMapping(value = "/start", method = RequestMethod.POST)
public String startLeaveProcess(@RequestParam String staffId) {
HashMap<String, Object> map = new HashMap<>();
map.put("leaveTask", staffId);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Leave", map);
List<Task> tasks = taskService.createTaskQuery().taskAssignee(staffId).orderByTaskCreateTime().desc().list();
return "processId:" + processInstance.getId() + ";首個task的id:" + tasks.get(0).getId();
}
@ApiOperation(value = "結束一個task")
@RequestMapping(value = "/reject", method = RequestMethod.PUT)
public String rejectTask(@RequestParam String taskId) {
HashMap<String, Object> map = new HashMap<>();
map.put("checkResult", "駁回");
taskService.complete(taskId, map);
return "申請審核駁回";
}
}
已有系統整合 IdmEngine
方案一:將已有系統中的用戶權限數據 同步到 ACT_ID_*表中
方案二:保留一方的表,另一方通過數據庫視圖來訪問數據
阿里云
Serverless 工作流