探索BPMN—工作流技術的理論與實踐
一、前言
- 19世紀70年代,流程管理思想萌芽階段。怎樣提高工作效率?泰勒:標準化個人操作流程亨利·福特:規定標準時間定額標準化、精簡化、通用化、專業化。
- 20世紀70年代,工作流技術起源于辦公自動化領域的研究。由于當時計算機尚未普及,網絡技術水平還很低以及理論基礎匱乏,這項新技術并未取得成功,許多公司采用紙張表單,手工傳遞的方式,一級一級審批簽字,工作效率非常低下。
- 20世紀90年代,信息技術驅動流程自動化階段。信息技術開始引入管理領域,對傳統的業務進行自動化改造。產品:Sabre訂票系統,MRP(物料需求計劃),MIS(管理信息系統),CIMS(計算機集成制造系統)。
- 21世紀初,BPM管理與治理結合。BPR/BPI:以信息技術為核心重新設計業務流程,失敗率高達50%-70%;BPM:以業務流程為主導的管理思想;BPM治理思想:對BPM實施的成功率以及ROI的高要求,強調BPM與企業戰略相結合。
二、BPMN介紹
BPMN(Business Process Modeling Notation,業務流程建模符號)是一種用于描述業務流程的標準化建模語言。它通過圖形符號及規則,幫助企業建模、分析和優化各種業務流程。BPMN有兩個主要版本:BPMN 1.0和BPMN 2.0。BPMN 1.0規范由標準組織BPMI(后并入到OMG)于2004年5月發布;BPMN 2.0標準由OMG于2011年推出。
2.0相對于1.0規范了流程引擎的語義和格式,利用標準的圖元描述真實的業務發生過程,保證相同的流程在不同的流程引擎中得到一致的執行結果。
BPMN的理論基礎
- 流程建模:BPMN使用不同的圖形符號來表示業務流程中的各項活動、任務、決策和事件等。這些符號包括任務、網關、事件等,每個符號都有特定的含義和用法。
- 流程分析:通過BPMN模型,企業可以分析業務流程的效率、資源利用率和風險等,以便進行優化和改進。
- 流程執行:BPMN不僅是一種建模語言,還可以將建模的業務流程實際執行起來,并進行監控和控制。
BPMN的優勢
圖片
傳統使用場景
- 采購流程:通過BPMN建模,企業可以規范采購流程,包括需求確認、供應商選擇、合同簽訂、物品收貨等環節,提高采購效率。
- 請假審批流程:BPMN模型可以幫助企業規范請假審批流程,包括員工請假申請、直屬主管審批、人力資源部門審批等環節,減少誤差和糾紛。
- 客戶投訴處理流程:利用BPMN,企業可以清晰地展示客戶投訴處理流程,包括客戶投訴登記、處理人員分配、處理過程跟蹤、客戶反饋等環節,提高客戶滿意度。
三、實踐舉例:XX平臺XXX商家合規治理任務優化項目(非真實場景)
背景目標
- 商家合規治理手段的單一性和對線下人工的過度依賴方面需要優化,通過整合商家合規治理策略,并實現這些策略的可在線化配置。這一舉措將打破傳統的手工操作模式,允許業務方直接在系統中配置和更新治理策略,減少人工干預,提高治理效率。同時,在線化配置也便于策略的快速部署和靈活調整,以應對不同業務場景下的合規要求。
- 各商家的合規治理進度和狀態的透明度方面需要優化,為改變這一現狀,我們需要搭建一套高效的工作流引擎。該引擎將支持商家合規治理流程的編排和自動化流轉,從任務觸發到完成審核、記錄反饋等各個環節都將實現自動化處理。同時,內置的進度跟蹤機制將確保業務團隊能夠實時查看各商家的治理進度,及時發現問題并采取相應措施。這將大大提高治理的透明度和可控性。
- 評估治理成果和手段的有效性分析方面需要優化,將合規治理成果的數據可視化,通過強大的數據分析與可視化系統,我們將關鍵指標(如治理效率、違規率、改進情況等)以圖表、報告等形式直觀展現。同時,通過持續的數據分析與改進循環,我們將逐步優化治理策略和方式,最終形成商家合規治理的閉環機制。
方案
業務流程
治理流程1
治理流程2
系統架構圖
流程編排
工作流技術選型
圖片
SmartEngine詳細介紹
E-R圖
圖片
CREATE TABLE `se_deployment_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_definition_id` varchar(255) NOT NULL COMMENT 'process definition id' ,
`process_definition_version` varchar(255) DEFAULT NULL COMMENT 'process definition version' ,
`process_definition_type` varchar(255) DEFAULT NULL COMMENT 'process definition type' ,
`process_definition_code` varchar(255) DEFAULT NULL COMMENT 'process definition code' ,
`process_definition_name` varchar(255) DEFAULT NULL COMMENT 'process definition name' ,
`process_definition_desc` varchar(255) DEFAULT NULL COMMENT 'process definition desc' ,
`process_definition_content` mediumtext NOT NULL COMMENT 'process definition content' ,
`deployment_user_id` varchar(128) NOT NULL COMMENT 'deployment user id' ,
`deployment_status` varchar(64) NOT NULL COMMENT 'deployment status' ,
`logic_status` varchar(64) NOT NULL COMMENT 'logic status' ,
PRIMARY KEY (`id`)
) COMMENT='流程定義表' ;
CREATE TABLE `se_process_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_definition_id_and_version` varchar(128) NOT NULL COMMENT 'process definition id and version' ,
`process_definition_type` varchar(255) DEFAULT NULL COMMENT 'process definition type' ,
`status` varchar(64) NOT NULL COMMENT ' 1.running 2.completed 3.aborted',
`parent_process_instance_id` bigint(20) unsigned DEFAULT NULL COMMENT 'parent process instance id' ,
`parent_execution_instance_id` bigint(20) unsigned DEFAULT NULL COMMENT 'parent execution instance id' ,
`start_user_id` varchar(128) DEFAULT NULL COMMENT 'start user id' ,
`biz_unique_id` varchar(255) DEFAULT NULL COMMENT 'biz unique id' ,
`reason` varchar(255) DEFAULT NULL COMMENT 'reason' ,
`comment` varchar(255) DEFAULT NULL COMMENT 'comment' ,
`title` varchar(255) DEFAULT NULL COMMENT 'title' ,
`tag` varchar(255) DEFAULT NULL COMMENT 'tag' ,
PRIMARY KEY (`id`)
) COMMENT='流程實例表' ;
CREATE TABLE `se_activity_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_instance_id` bigint(20) unsigned DEFAULT NULL COMMENT 'process instance id' ,
`process_definition_id_and_version` varchar(255) NOT NULL COMMENT 'process definition id and version' ,
`process_definition_activity_id` varchar(64) NOT NULL COMMENT 'process definition activity id' ,
PRIMARY KEY (`id`)
) COMMENT='活動節點實例表' ;
CREATE TABLE `se_task_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_instance_id` bigint(20) unsigned NOT NULL COMMENT 'process instance id' ,
`process_definition_id_and_version` varchar(128) DEFAULT NULL COMMENT 'process definition id and version' ,
`process_definition_type` varchar(255) DEFAULT NULL COMMENT 'process definition type' ,
`activity_instance_id` bigint(20) unsigned NOT NULL COMMENT 'activity instance id' ,
`process_definition_activity_id` varchar(255) NOT NULL COMMENT 'process definition activity id' ,
`execution_instance_id` bigint(20) unsigned NOT NULL COMMENT 'execution instance id' ,
`claim_user_id` varchar(255) DEFAULT NULL COMMENT 'claim user id' ,
`title` varchar(255) DEFAULT NULL COMMENT 'title' ,
`priority` int(11) DEFAULT 500 COMMENT 'priority' ,
`tag` varchar(255) DEFAULT NULL COMMENT 'tag' ,
`claim_time` datetime(6) DEFAULT NULL COMMENT 'claim time' ,
`complete_time` datetime(6) DEFAULT NULL COMMENT 'complete time' ,
`status` varchar(255) NOT NULL COMMENT 'status' ,
`comment` varchar(255) DEFAULT NULL COMMENT 'comment' ,
`extension` varchar(255) DEFAULT NULL COMMENT 'extension' ,
PRIMARY KEY (`id`)
) COMMENT='人工任務節點實例表' ;
CREATE TABLE `se_task_assignee_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_instance_id` bigint(20) unsigned NOT NULL COMMENT 'process instance id' ,
`task_instance_id` bigint(20) unsigned NOT NULL COMMENT 'task instance id' ,
`assignee_id` varchar(255) NOT NULL COMMENT 'assignee id' ,
`assignee_type` varchar(128) NOT NULL COMMENT 'assignee type' ,
PRIMARY KEY (`id`)
) COMMENT='人工任務節點代理人實例表' ;
CREATE TABLE `se_execution_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_instance_id` bigint(20) unsigned NOT NULL COMMENT 'process instance id' ,
`process_definition_id_and_version` varchar(255) NOT NULL COMMENT 'process definition id and version' ,
`process_definition_activity_id` varchar(255) NOT NULL COMMENT 'process definition activity id' ,
`activity_instance_id` bigint(20) unsigned NOT NULL COMMENT 'activity instance id' ,
`active` tinyint(4) NOT NULL COMMENT '1:active 0:inactive',
PRIMARY KEY (`id`)
) COMMENT='執行節點實例表-最細粒度的實例' ;
CREATE TABLE `se_variable_instance` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK' ,
`gmt_create` datetime(6) NOT NULL COMMENT 'create time' ,
`gmt_modified` datetime(6) NOT NULL COMMENT 'modification time' ,
`process_instance_id` bigint(20) unsigned NOT NULL COMMENT 'process instance id' ,
`execution_instance_id` bigint(20) unsigned DEFAULT NULL COMMENT 'execution instance id' ,
`field_key` varchar(128) NOT NULL COMMENT 'field key' ,
`field_type` varchar(128) NOT NULL COMMENT 'field type' ,
`field_double_value` decimal(65,30) DEFAULT NULL COMMENT 'field double value' ,
`field_long_value` bigint(20) DEFAULT NULL COMMENT 'field long value' ,
`field_string_value` varchar(4000) DEFAULT NULL COMMENT 'field string value' ,
PRIMARY KEY (`id`)
) COMMENT='執行節點變量量表' ;
代碼實操
第一步,要選擇正確的SmartEngine版本,將其添加到pom依賴中。
<dependency>
<groupld>com.alibaba.smart.framework</groupld>
<artifactld>smart-engine-extension-storage-custom</artifactld>
<version>3.0.0</version>
</dependency>
第二步,完成SmartEngine初始化。在初始化時,一般要加載流程定義到應用中。集群情況下,要注意流程定義的一致性(如果純靜態記載則無此類問題)。在初始化時,可以根據需要定義Bean的加載優先級。
import com.alibaba.smart.framework.engine.SmartEngine;
import com.alibaba.smart.framework.engine.configuration.InstanceAccessor;
import com.alibaba.smart.framework.engine.configuration.ProcessEngineConfiguration;
import com.alibaba.smart.framework.engine.configuration.impl.DefaultProcessEngineConfiguration;
import com.alibaba.smart.framework.engine.configuration.impl.DefaultSmartEngine;
import com.alibaba.smart.framework.engine.exception.EngineException;
import com.alibaba.smart.framework.engine.service.command.RepositoryCommandService;
import com.alibaba.smart.framework.engine.util.IOUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import java.io.InputStream;
import static org.springframework.core.Ordered.LOWEST_PRECEDENCE;
@Order(LOWEST_PRECEDENCE)
@Configuration
@ConditionalOnClass(SmartEngine.class)
public class SmartEngineAutoConfiguration implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean
public SmartEngine constructSmartEngine() {
ProcessEngineConfiguration processEngineConfiguration = new DefaultProcessEngineConfiguration();
// 實現InstanceAccessor接口
processEngineConfiguration.setInstanceAccessor(new CustomInstanceAccessService());
SmartEngine smartEngine = new DefaultSmartEngine();
smartEngine.init(processEngineConfiguration);
// 加載流程定義
deployProcessDefinition(smartEngine);
return smartEngine;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
private class CustomInstanceAccessService implements InstanceAccessor {
@Override
public Object access(String name) {
return applicationContext.getBean(name);
}
}
private void deployProcessDefinition(SmartEngine smartEngine) {
RepositoryCommandService repositoryCommandService = smartEngine
.getRepositoryCommandService();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
Resource[] resources = resolver.getResources("classpath*:/smart-engine/*.xml");
for (Resource resource : resources) {
InputStream inputStream = resource.getInputStream();
repositoryCommandService.deploy(inputStream);
IOUtil.closeQuietly(inputStream);
}
} catch (Exception e) {
throw new EngineException(e);
}
}
}
BMPN2.0 xml舉例
附言:排他網關的條件表達式是跟著線條綁定的,要自己確保條件的是和否加在一起的總概率是100%,如果不是100%,小概率執行節點會卡在排他網關走不下去。例如:線條“否”的條件表達式為:條件1為假且條件2為假,線條“是”的條件表達式為條件1為真且條件2為真,則其他條件會卡死在排他網關流程走不下去。
test1.bpmn
<?xml versinotallow="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Web Modeler" exporterVersion="b1a091a" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0" camunda:diagramRelationId="2a2c997b-ff2f-49b0-9ba8-3c4860d223e7">
<bpmn:process id="Process_1qijgvk" name="test1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0soou9n</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0soou9n" sourceRef="StartEvent_1" targetRef="Activity_02gdgyk" />
<bpmn:endEvent id="Event_1i2y4ym">
<bpmn:incoming>Flow_07mf0sc</bpmn:incoming>
<bpmn:incoming>Flow_1nd3369</bpmn:incoming>
<bpmn:incoming>Flow_160ji3a</bpmn:incoming>
</bpmn:endEvent>
<bpmn:exclusiveGateway id="Gateway_1kykneu" name="檢查是否5天內完成治理">
<bpmn:extensionElements />
<bpmn:incoming>Flow_0exjsc9</bpmn:incoming>
<bpmn:outgoing>Flow_0hj860q</bpmn:outgoing>
<bpmn:outgoing>Flow_1oqjt08</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_0hj860q" name="否" sourceRef="Gateway_1kykneu" targetRef="Activity_1ms8vu6" />
<bpmn:serviceTask id="Activity_02gdgyk" name="站內通知商戶去治理">
<bpmn:extensionElements />
<bpmn:incoming>Flow_0soou9n</bpmn:incoming>
<bpmn:outgoing>Flow_0exjsc9</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_0exjsc9" sourceRef="Activity_02gdgyk" targetRef="Gateway_1kykneu" />
<bpmn:serviceTask id="Activity_1ms8vu6" name="發送sms通知商戶">
<bpmn:incoming>Flow_0hj860q</bpmn:incoming>
<bpmn:outgoing>Flow_0bemgki</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_0bemgki" sourceRef="Activity_1ms8vu6" targetRef="Gateway_1dyp6hh" />
<bpmn:sequenceFlow id="Flow_1oqjt08" name="是" sourceRef="Gateway_1kykneu" targetRef="Activity_1c9i1el" />
<bpmn:exclusiveGateway id="Gateway_1dyp6hh" name="是否10天內完成治理">
<bpmn:incoming>Flow_0bemgki</bpmn:incoming>
<bpmn:outgoing>Flow_07xq405</bpmn:outgoing>
<bpmn:outgoing>Flow_1w4qeti</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_07xq405" name="是" sourceRef="Gateway_1dyp6hh" targetRef="Activity_0m5dsna" />
<bpmn:serviceTask id="Activity_1c9i1el" name="發放獎勵給到商戶">
<bpmn:incoming>Flow_1oqjt08</bpmn:incoming>
<bpmn:outgoing>Flow_1t7ectj</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1t7ectj" sourceRef="Activity_1c9i1el" targetRef="Activity_1p6mkdy" />
<bpmn:task id="Activity_0m5dsna" name="任務完成">
<bpmn:incoming>Flow_07xq405</bpmn:incoming>
<bpmn:outgoing>Flow_07mf0sc</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_07mf0sc" sourceRef="Activity_0m5dsna" targetRef="Event_1i2y4ym" />
<bpmn:sequenceFlow id="Flow_1w4qeti" name="否" sourceRef="Gateway_1dyp6hh" targetRef="Activity_1gud1rw" />
<bpmn:task id="Activity_1p6mkdy" name="任務完成">
<bpmn:incoming>Flow_1t7ectj</bpmn:incoming>
<bpmn:outgoing>Flow_1nd3369</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1nd3369" sourceRef="Activity_1p6mkdy" targetRef="Event_1i2y4ym" />
<bpmn:serviceTask id="Activity_1gud1rw" name="通知運營下線商戶店鋪">
<bpmn:incoming>Flow_1w4qeti</bpmn:incoming>
<bpmn:outgoing>Flow_0vr5zs3</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_0vr5zs3" sourceRef="Activity_1gud1rw" targetRef="Activity_1pfbnmo" />
<bpmn:task id="Activity_1pfbnmo" name="任務結束">
<bpmn:incoming>Flow_0vr5zs3</bpmn:incoming>
<bpmn:outgoing>Flow_160ji3a</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_160ji3a" sourceRef="Activity_1pfbnmo" targetRef="Event_1i2y4ym" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1qijgvk">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="152" y="232" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1kykneu_di" bpmnElement="Gateway_1kykneu" isMarkerVisible="true">
<dc:Bounds x="465" y="225" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="448" y="188" width="84" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_02gdgyk_di" bpmnElement="Activity_02gdgyk">
<dc:Bounds x="270" y="210" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1ms8vu6_di" bpmnElement="Activity_1ms8vu6">
<dc:Bounds x="630" y="210" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1i2y4ym_di" bpmnElement="Event_1i2y4ym">
<dc:Bounds x="1182" y="232" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1dyp6hh_di" bpmnElement="Gateway_1dyp6hh" isMarkerVisible="true">
<dc:Bounds x="825" y="225" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="810" y="285" width="79" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1c9i1el_di" bpmnElement="Activity_1c9i1el">
<dc:Bounds x="630" y="320" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0m5dsna_di" bpmnElement="Activity_0m5dsna">
<dc:Bounds x="950" y="210" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0ab1d2g" bpmnElement="Activity_1p6mkdy">
<dc:Bounds x="840" y="320" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1gud1rw_di" bpmnElement="Activity_1gud1rw">
<dc:Bounds x="800" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_02s3tua" bpmnElement="Activity_1pfbnmo">
<dc:Bounds x="950" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0soou9n_di" bpmnElement="Flow_0soou9n">
<di:waypoint x="188" y="250" />
<di:waypoint x="270" y="250" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0exjsc9_di" bpmnElement="Flow_0exjsc9">
<di:waypoint x="370" y="250" />
<di:waypoint x="465" y="250" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0hj860q_di" bpmnElement="Flow_0hj860q">
<di:waypoint x="515" y="250" />
<di:waypoint x="630" y="250" />
<bpmndi:BPMNLabel>
<dc:Bounds x="567" y="232" width="11" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1oqjt08_di" bpmnElement="Flow_1oqjt08">
<di:waypoint x="490" y="275" />
<di:waypoint x="490" y="360" />
<di:waypoint x="630" y="360" />
<bpmndi:BPMNLabel>
<dc:Bounds x="544" y="373" width="11" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0bemgki_di" bpmnElement="Flow_0bemgki">
<di:waypoint x="730" y="250" />
<di:waypoint x="825" y="250" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1t7ectj_di" bpmnElement="Flow_1t7ectj">
<di:waypoint x="730" y="360" />
<di:waypoint x="840" y="360" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_07mf0sc_di" bpmnElement="Flow_07mf0sc">
<di:waypoint x="1050" y="250" />
<di:waypoint x="1182" y="250" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_07xq405_di" bpmnElement="Flow_07xq405">
<di:waypoint x="875" y="250" />
<di:waypoint x="950" y="250" />
<bpmndi:BPMNLabel>
<dc:Bounds x="899" y="232" width="11" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1w4qeti_di" bpmnElement="Flow_1w4qeti">
<di:waypoint x="850" y="225" />
<di:waypoint x="850" y="160" />
<bpmndi:BPMNLabel>
<dc:Bounds x="853" y="186" width="11" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1nd3369_di" bpmnElement="Flow_1nd3369">
<di:waypoint x="940" y="360" />
<di:waypoint x="1120" y="360" />
<di:waypoint x="1120" y="250" />
<di:waypoint x="1182" y="250" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0vr5zs3_di" bpmnElement="Flow_0vr5zs3">
<di:waypoint x="900" y="120" />
<di:waypoint x="950" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_160ji3a_di" bpmnElement="Flow_160ji3a">
<di:waypoint x="1050" y="120" />
<di:waypoint x="1120" y="120" />
<di:waypoint x="1120" y="250" />
<di:waypoint x="1182" y="250" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
- process,表示一個流程。
- id="exclusiveTest" versinotallow="1.0.0",分別表示流程定義的id和版本。這兩個字段唯一區分一個流程定義。
- startEvent,表示流程開始節點。只允許有一個開始節點。
- endEvent,表示流程結束節點。可以有多個結束節點。
- sequenceFlow,表示環節流轉關系。sourceRef="theStart" targetRef="submitTask" 分別表示起始節點和目標節點。該節點有個子節點, approve == 'agree',這個片段很重要,用來描述流程流轉的條件。approve == 'upgrade'使用的是MVEL表達式語法。另外,還值得注意的是,在驅動流程運轉時,需要傳入正確的參數。比如說,在后面介紹的api中,通常會需要在Map中傳遞業務請求參數。那么需要將Map中的key和Mvel的運算因子關聯起來。以這個例子來說,request.put("approve", "agree");里面的approve和approve == 'agree'命名要一致。
- exclusiveGateway,表示互斥網關。該節點非常重要。用來區分流程節點的不同轉向。互斥網關在引擎執行conditionExpression后,有且只能選擇一條匹配的sequenceFlow繼續執行。
- serviceTask,服務任務,用來表示執行一個服務,所以他會有引擎默認的擴展:smart:class="com.alibaba.smart.framework.example.AuditProcessServiceTaskDelegation". Client Developer使用時,需要自定義對應的業務實現類。在該節點執行時,它會自動執行服務調用,執行smart:class 這個 delegation。該節點不暫停,會自動往下一個流轉。
- receiveTask,接收任務。在引擎遇到此類型的節點時,引擎執行會自動暫停,等待外部調用signal方法。當調用signal方法時,會驅動流程當前節點離開。在離開該節點時,引擎會自動執行smart:class 這個delegation。在一般業務場景中,我們通常使用receiveTask來表示等需要等待外部回調的節點。
- userTask,表示用戶任務節點,僅用于DataBase模式。該節點需要人工參與處理,并且通常需要在待辦列表中展示。在Custom模式下,建議使用receiveTask來代替。
- parallelGateway,這個節點并未在上述流程定義中體現,這里詳細說一下。parallelGateway 首先必須成對出現,分別承擔fork和join職責。其次,在join時需要實現分布式鎖接口:LockStrategy。第三,fork默認是順序遍歷多個sequeceFlow,但是你如果需要使用并發fork功能的話,則需要實現該接口:ExecutorService。
重要領域對象
- 部署實例: DeploymentInstance,描述這個流程定義是誰發布的,當前處于什么狀態。
- 流程定義: ProcessDefinition,描述一個流程有幾個環節,之間的流轉關系是什么樣子的。
- 流程實例: ProcessInstance,可以簡單理解為我們常見的一個工單。
- 活動實例: ActivityInstance,主要是描述流程實例(工單)的流轉軌跡。
- 執行實例: ExecutionInstance,主要根據該實例的狀態,來判斷當前流程處在哪個節點上。
- 任務實例: TaskInstance,用來表示人工任務處理的,可以理解為一個需要人工參與處理的環節。
- 任務處理:TaskAssigneeInstance,用來表示當前任務共有幾個處理者。通常在代辦列表中用到此實體。
- 變量實例:VariableInstance,用來存儲流程實例上下文。
SmartEngine引擎源碼地址:https://github.com/alibaba/SmartEngine/tree/master
SmartEngine UserGuide: https://github.com/alibaba/SmartEngine/wiki/SmartEngine-UserGuide--Chinese-Version-%28%E4%B8%AD%E6%96%87%E7%89%88%29
Camunda開源流程設計器(支持在線和本地node.js部署兩種方式):https://camunda.com/download/modeler/
Camunda設計器學習文檔:https://docs.camunda.io/docs/components/modeler/bpmn/bpmn-primer/
四、總結與建議
優點
- 業務流程可視化與實際系統流程可視化高度一致,所見即所得。
- 調整效率高(業務平均每個月會升級一次治理流程),如果業務流程1.0要升級到1.1,只需要重新復制一份bpmn.xml流程模板重新編排為1.1,并下發流程實例即可,不影響原有的流程模板和流程實例執行(調整效率由原來的一周縮短到1小時)。
- 流程實例和流程節點實例可視,方便監控各個節點的執行和數據報表的產出。
缺點
- 異常處理的支持度不夠友好(SmartEngine是異常丟棄),如果在某一個節點上執行失敗(一般情況是業務接口執行失敗導致),默認當前流程進度是卡在該節點的,需要設計張異常表,把當前流程實例,節點實例以及變量都保存下載,通過job重新拉起重試去驅動流程繼續執行,并需要做好告警監控,以及任務實例和流程實例的核對。
- 高并發場景的支持度并不是太友好,要通過異步消息的方式來控制創建流程實例的速度,目前得到的創建流程實例的TPS是100/s單臺,只是相對于activiti來說并發支持度要高,超過這個上限的場景建議謹慎使用。
- 可擴展性不足,例如:ProcessQueryService只支持findById,findList,count;ExecutionQueryService只支持findActiveExecutionList,findAll這些基本查詢 ,復雜查詢需要新寫SmartEngine核心包,升級jar包版本后才可使用。
- 無歷史記錄表,每隔一段時間要清理表中流程實例已經完結的相關數據,否則歷史數據堆積影響查詢效率。
建議
如果業務流程的復雜度一般,且經常會調整,并發量并不高的情況下,建議使用;如果業務復雜度過高,或并發量TPS超過單臺100/s,不建議使用。