天天看點

Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權

15 Flowable-BPMN操作流程之排他網關

  • 背景
  • 定義
  • 流程準備
  • 流程檔案
  • 控制器
  • 流程驗證
  • 代碼下載下傳
  • 打賞
  • 版權

背景

流程在審批的過程中需要進行一些判斷然後再看下一步怎麼走,完成判斷邏輯的是網關,排他網關就是其中的一種。

定義

排他網關(也叫異或(XOR)網關,或更技術性的叫法 基于資料的排他網關), 用來在流程中實作決策。 當流程執行到這個網關,所有外出順序流都會被處理一遍。 其中條件解析為true的順序流(或者沒有設定條件,概念上在順序流上定義了一個’true’) 會被選中,讓流程繼續運作。簡單了解條件為True繼續執行,False将不執行。

流程準備

我們在Modeler中給我們的流程配置一個排他網關,添加後流程如下:

Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權

在排他網關的到結束的連接配接線上配置好網關是否通過的條件,比如稽核通過我們設定為${outcome==‘通過’},當走到這裡流程變量outcome為通過的時候将會走稽核通過這個流程,等于拒絕的時候走下面的流程,參數配置如下圖所示:

Flowable深入淺出-15 Flowable-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: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="test_bpmn" name="測試BPMN模型" isExecutable="true">
    <documentation>測試BPMN模型</documentation>
    <startEvent id="start" name="開始"></startEvent>
    <endEvent id="end" name="通過結束"></endEvent>
    <userTask id="testUser" name="使用者任務測試" flowable:assignee="admin">
      <extensionElements>
        <flowable:taskListener event="create" class="com.hyj.flowlistener.CommonUserStartListener"></flowable:taskListener>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002" sourceRef="start" targetRef="testUser"></sequenceFlow>
    <exclusiveGateway id="ex_gateway_check" name="稽核結果"></exclusiveGateway>
    <sequenceFlow id="sid-50731902-EF37-4E07-9DED-2E83F7EB54B7" sourceRef="testUser" targetRef="ex_gateway_check"></sequenceFlow>
    <endEvent id="end_fail" name="失敗結束"></endEvent>
    <sequenceFlow id="check_fail" name="稽核拒絕" sourceRef="ex_gateway_check" targetRef="end_fail">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='拒絕'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="check_ok" name="稽核通過" sourceRef="ex_gateway_check" targetRef="end">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='通過'}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_test_bpmn">
    <bpmndi:BPMNPlane bpmnElement="test_bpmn" id="BPMNPlane_test_bpmn">
      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
        <omgdc:Bounds height="30.0" width="30.0" x="210.0" y="120.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
        <omgdc:Bounds height="28.0" width="28.0" x="630.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="testUser" id="BPMNShape_testUser">
        <omgdc:Bounds height="80.0" width="100.0" x="315.0" y="95.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="ex_gateway_check" id="BPMNShape_ex_gateway_check">
        <omgdc:Bounds height="40.0" width="40.0" x="480.0" y="115.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end_fail" id="BPMNShape_end_fail">
        <omgdc:Bounds height="28.0" width="28.0" x="630.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="check_fail" id="BPMNEdge_check_fail">
        <omgdi:waypoint x="500.5" y="154.4338310580205"></omgdi:waypoint>
        <omgdi:waypoint x="500.5" y="194.0"></omgdi:waypoint>
        <omgdi:waypoint x="630.0" y="194.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002" id="BPMNEdge_sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002">
        <omgdi:waypoint x="239.94999779398907" y="135.0"></omgdi:waypoint>
        <omgdi:waypoint x="315.0" y="135.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-50731902-EF37-4E07-9DED-2E83F7EB54B7" id="BPMNEdge_sid-50731902-EF37-4E07-9DED-2E83F7EB54B7">
        <omgdi:waypoint x="414.95000000000005" y="135.0"></omgdi:waypoint>
        <omgdi:waypoint x="480.0" y="135.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="check_ok" id="BPMNEdge_check_ok">
        <omgdi:waypoint x="500.5" y="115.5"></omgdi:waypoint>
        <omgdi:waypoint x="500.5" y="74.0"></omgdi:waypoint>
        <omgdi:waypoint x="630.0" y="74.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
           

控制器

控制器原來直接是個完成任務現在,我們友善起見拆分為2個一個是通過任務,一個是拒絕任務,如果你的排他網關使用的都是該參數那麼就可以通用。

@RequestMapping("/accept")
    @ResponseBody
    public Map<String,Object> acceptTask(@RequestBody @RequestParam(required = false) Map<String,String> paras){
        Map<String,Object> res =new HashMap<>();
        Map<String,String> data = new HashMap<>();

        if (MapUtils.isEmpty(paras)){
            res.put("msg","請輸入任務參數");
            res.put("res","0");
            res.put("data",data);
            return res;
        }

        String taskId = paras.get("taskId");
        if (StringUtils.isEmpty(taskId)){
            res.put("msg","請輸入任務ID");
            res.put("res","0");
            res.put("data",data);
            return res;
        }

        Map<String,Object> flowParas=new HashMap<>();
        flowParas.putAll(paras);
        flowParas.put("outcome","通過");
        boolean bok = flowService.completeTask(taskId,flowParas);

        if (bok){
            data.put("taskId",taskId);
            res.put("msg","通過任務成功");
            res.put("res","1");
        }
        else {
            data.put("taskId",taskId);
            res.put("msg","通過任務失敗");
            res.put("res","0");
        }

        res.put("data",data);
        return res;
    }


    @RequestMapping("/reject")
    @ResponseBody
    public Map<String,Object> rejectTask(@RequestBody @RequestParam(required = false) Map<String,String> paras){
        Map<String,Object> res =new HashMap<>();
        Map<String,String> data = new HashMap<>();

        if (MapUtils.isEmpty(paras)){
            res.put("msg","請輸入任務參數");
            res.put("res","0");
            res.put("data",data);
            return res;
        }

        String taskId = paras.get("taskId");
        if (StringUtils.isEmpty(taskId)){
            res.put("msg","請輸入任務ID");
            res.put("res","0");
            res.put("data",data);
            return res;
        }

        Map<String,Object> flowParas=new HashMap<>();
        flowParas.putAll(paras);
        flowParas.put("outcome","拒絕");
        boolean bok = flowService.completeTask(taskId,flowParas);

        if (bok){
            data.put("taskId",taskId);
            res.put("msg","拒絕任務成功");
            res.put("res","1");
        }
        else {
            data.put("taskId",taskId);
            res.put("msg","拒絕任務失敗");
            res.put("res","0");
        }

        res.put("data",data);
        return res;
    }
           

流程驗證

  1. 建立新流程

    替換罪行的流程配置檔案,輸入建立位址完成建立。

    http://localhost:8989/flow/create

    Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權
  2. 啟動流程

    http://localhost:8989/flow/start?processKey=test_bpmn,輸入改位址完成流程啟動

    Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權
    此時檢視流程背景,會列印目前的任務ID
    Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權
  3. 通過流程

    輸入新增的通過位址完成流程審批

    http://localhost:8989/flow/accept?taskId=e7b04115-23c8-11e9-929f-00155d030a00

    Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權
  4. 檢視流程圖

    進入流程檢視位址:http://localhost:8989/flow/processDiagram?processId=e7a71950-23c8-11e9-929f-00155d030a00,檢視我們的審批流程走到了最後,而拒絕沒有發生變化,說明排他網關成功的區分了兩個流程,流程進展如下圖所示:

    Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權

代碼下載下傳

下載下傳内容已經放到我的CSDN的資源頁面,https://download.csdn.net/download/houyj1986/10943791

打賞

如果您覺得該文章對您有幫助,歡迎打賞作者,謝謝。

Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權
Flowable深入淺出-15 Flowable-BPMN操作流程之排他網關背景定義流程準備流程檔案控制器流程驗證代碼下載下傳打賞版權

版權

版權所有,侵權必究,代碼與文章,使用、copy、轉載請聯系作者。由書山登峰人創作。

繼續閱讀