flowable多實例任務Demo

flowable多實例任務的一個Demo:
流程描述: 由用戶輸入收件人列表(多個用;分隔), 郵件內容等, 然後提交任務, 就可以給多個人發送郵件.

首先看流程圖:
在這裏插入圖片描述
其bmpn文件:

<?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_mail_assignee" name="test_mail_assignee" isExecutable="true">
    <documentation>測試發送郵件, 手動指定候選人</documentation>
    <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
    <userTask id="sid-62033516-24F1-4E4E-BF24-4658BC754590" name="填寫發郵件表單" flowable:candidateUsers="${var_candidate_users}" flowable:formKey="mail_form" flowable:formFieldValidation="true"></userTask>
    <sequenceFlow id="sid-4BB20B0C-F7CA-4DE8-9DBC-CDAF6B344CE0" sourceRef="startEvent1" targetRef="sid-62033516-24F1-4E4E-BF24-4658BC754590"></sequenceFlow>
    <serviceTask id="sid-2183A3C0-3CB8-44A4-AC7A-01588667E2C6" name="send mail to multi people" flowable:type="mail">
      <extensionElements>
        <flowable:field name="to">
          <flowable:expression><![CDATA[${to2}]]></flowable:expression>
        </flowable:field>
        <flowable:field name="from">
          <flowable:string><![CDATA[${from}]></flowable:string>
        </flowable:field>
        <flowable:field name="subject">
          <flowable:expression><![CDATA[${subject}]]></flowable:expression>
        </flowable:field>
        <flowable:field name="text">
          <flowable:expression><![CDATA[${content}]]></flowable:expression>
        </flowable:field>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="toList" flowable:elementVariable="to2"></multiInstanceLoopCharacteristics>
    </serviceTask>
    <endEvent id="sid-FEE51C53-D5F5-484A-9FEC-9CFA8AB83487"></endEvent>
    <sequenceFlow id="sid-08691188-CAA4-4638-9CCD-9E0163E5EBBC" sourceRef="sid-2183A3C0-3CB8-44A4-AC7A-01588667E2C6" targetRef="sid-FEE51C53-D5F5-484A-9FEC-9CFA8AB83487"></sequenceFlow>
    <scriptTask id="sid-26DCE8D1-4387-4134-B265-0391641426EB" name="split收件人" flowable:async="true" flowable:exclusive="false" scriptFormat="groovy" flowable:autoStoreVariables="false">
      <script><![CDATA[def m = to.tokenize(';');
execution.setVariable("toList", m);]]></script>
    </scriptTask>
    <sequenceFlow id="sid-5B283531-0C02-4661-9F53-4AC60EED90D4" sourceRef="sid-26DCE8D1-4387-4134-B265-0391641426EB" targetRef="sid-2183A3C0-3CB8-44A4-AC7A-01588667E2C6"></sequenceFlow>
    <sequenceFlow id="sid-42232B5F-E183-41F1-BF67-45D958706435" sourceRef="sid-62033516-24F1-4E4E-BF24-4658BC754590" targetRef="sid-26DCE8D1-4387-4134-B265-0391641426EB"></sequenceFlow>
  </process>

</definitions>

郵件相關變量輸入由表單完成(flowable:formKey="mail_form"), 其中的表單元素id就是以後的變量名(subject, to等).
在這裏插入圖片描述

{
  "id": "492d9eaa-8f7a-11ea-a32a-a64a22da418e",
  "name": "發郵件表單",
  "key": "mail_form",
  "description": "mail_form",
  "editorJson": {
    "name": "發郵件表單",
    "key": "mail_form",
    "version": 0,
    "fields": [
      {
        "fieldType": "FormField",
        "id": "subject",
        "name": "郵件主題",
        "type": "text",
        "value": null,
        "required": true,
        "readOnly": false,
        "overrideId": true,
        "placeholder": null,
        "layout": null
      },
      {
        "fieldType": "FormField",
        "id": "to",
        "name": "收件人",
        "type": "text",
        "value": null,
        "required": true,
        "readOnly": false,
        "overrideId": true,
        "placeholder": "收件人(多個用;分隔)",
        "layout": null
      },
      {
        "fieldType": "FormField",
        "id": "content",
        "name": "郵件內容",
        "type": "multi-line-text",
        "value": null,
        "required": true,
        "readOnly": false,
        "overrideId": true,
        "placeholder": null,
        "layout": null
      }
    ],
    "outcomes": []
  }
}

收件人列表由用戶輸入(變量to), 然後由groovy腳本切割爲List, 並設置爲變量toList

def m = to.tokenize(';');
execution.setVariable("toList", m);

所以在"發送郵件"那一步可以設置CollectiontoList, 然後設置Element Variableto2(不和to重複就行).

完.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章