在沒有專門的工做流引擎以前,咱們以前爲了實現流程控制,一般的作法就是採用狀態字段的值來跟蹤流程的變化狀況。這樣不用角色的用戶,經過狀態字段的取值來決定記錄是否顯示。好比說員工請假申請流程:員工申請---部門經理---總經理---人事存檔
express
針對有權限能夠查看的記錄,當前用戶根據本身的角色來決定審批是否合格的操做。若是合格將狀態字段設置一個值,來表明合格;固然若是不合格也須要設置一個值來表明不合格的狀況。編輯器
這是一種最爲原始的方式。經過狀態字段雖然作到了流程控制,可是當咱們的流程發生變動的時候,這種方式所編寫的代碼也要進行調整。那麼有沒有專業的方式來實現工做流的管理呢?而且能夠作到業務流程變化以後,咱們的程序能夠不用改變,若是能夠實現這樣的效果,那麼咱們的業務系統的適應能力就獲得了極大提高。網站
爲何Activiti就能夠解決業務需求變動時,源代碼不須要更新,更新的是業務流程圖,原理是什麼?spa
如何能夠作到咱們在業務流程發生變動後,咱們的業務系統代碼能夠不發生改變?此時咱們就來分析一下原理。code
具體分析過程以下圖所示:xml
Activiti 內部核心機制及實現原理圖blog
原理:節點和表之間的信息轉換,關鍵點就在這裏。把節點的信息讀取出來而後存入到表裏邊,未來在處理的時候,從表中讀取記錄,處理完以後將記錄刪掉,意味着這個環節就處理完了,而後再處理下一個節點。開發
Activiti 是一個工做流引擎, activiti 能夠將業務系統中複雜的業務流程抽取出來,使用專門的建模語言(BPMN2.0)進行定義,業務系統按照預先定義的流程進行執行,實現了業務系統的業務流程由 activiti 進行管理,減小業務系統因爲流程變動進行系統升級改造的工做量,從而提升系統的健壯性,同時也減小了系統開發維護成本。get
官方網站:https://www.activiti.org/工作流
Activiti7默認 25 張表,公司開發的軟件是否適合使用activiti。
BPMN(Business Process Model And Notation)
- 業務流程模型和符號 是由 BPMI(Business Process Management Initiative)開發的一套標準的業務流程建模符號,使用 BPMN 提供的符號能夠建立業務流程。
BPMN 主要用來規範化業務流程及統一建模。
Event 用一個圓圈表示,它是流程中運行過程當中發生的事情。
活動用圓角矩形表示,一個流程由一個活動或多個活動組成:
一個 bpmn 圖形的例子:
Bpmn 圖形實際上是經過 xml 表示業務流程,上邊的.bpmn 文件使用文本編輯器打開:
<?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:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.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.activiti.org/test"> <process id="myProcess" name="My process" isExecutable="true"> <startEvent id="startevent1" name="Start"></startEvent> <userTask id="usertask1" name="建立請假單"></userTask> <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow> <userTask id="usertask2" name="部門經理審覈"></userTask> <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow> <userTask id="usertask3" name="人事複覈"></userTask> <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow4" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess"> <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="130.0" y="160.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"> <omgdc:Bounds height="55.0" width="105.0" x="210.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"> <omgdc:Bounds height="55.0" width="105.0" x="360.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"> <omgdc:Bounds height="55.0" width="105.0" x="510.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="660.0" y="160.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="165.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="210.0" y="177.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="315.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="360.0" y="177.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> <omgdi:waypoint x="465.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="510.0" y="177.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"> <omgdi:waypoint x="615.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="660.0" y="177.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>