0.0.9 • Published 2 years ago

@l1go/bpmn-engine v0.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

修改configuration.ts

import * as consoleCore from '@l1go/bpmn-engine'

@Configuration({
  imports: [
    consoleCore,
  ],
  importConfigs: ["./config"],
})

this.app.use(await this.app.generateMiddleware('consoleMiddleware'));

流程执行

<?xml version="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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="two_UserTaskExample" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.11.2">
  <bpmn:process id="process" name="请假流程" isExecutable="true">
    <bpmn:startEvent id="start" name="开始">
      <bpmn:outgoing>SequenceFlow_1fjfu37</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="SequenceFlow_1fjfu37" sourceRef="start" targetRef="ask" />
    <bpmn:userTask id="ask" name="申请" camunda:candidateGroups="everyone">
      <bpmn:extensionElements>
        <camunda:properties>
          <camunda:property name="service" value="userTaskService" />
        </camunda:properties>
      </bpmn:extensionElements>
      <bpmn:incoming>reject</bpmn:incoming>
      <bpmn:incoming>SequenceFlow_1fjfu37</bpmn:incoming>
      <bpmn:outgoing>Flow_055waog</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_055waog" sourceRef="ask" targetRef="serviceTask" />
    <bpmn:serviceTask id="serviceTask" name="服务任务" implementation="${environment.services.serviceTaskService}" icon="rules">
      <bpmn:incoming>Flow_055waog</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_18lxtv3</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="SequenceFlow_18lxtv3" sourceRef="serviceTask" targetRef="agree" />
    <bpmn:userTask id="agree" name="审批" camunda:candidateGroups="manager">
      <bpmn:extensionElements>
        <camunda:properties>
          <camunda:property name="service" value="managerTaskService" />
        </camunda:properties>
      </bpmn:extensionElements>
      <bpmn:incoming>SequenceFlow_18lxtv3</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_0gnbudv</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="SequenceFlow_0gnbudv" sourceRef="agree" targetRef="decision" />
    <bpmn:exclusiveGateway id="decision" name="判断" icon="decision">
      <bpmn:incoming>SequenceFlow_0gnbudv</bpmn:incoming>
      <bpmn:outgoing>reject</bpmn:outgoing>
      <bpmn:outgoing>receive</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="reject" name="拒绝" sourceRef="decision" targetRef="ask">
      <bpmn:conditionExpression xsi:type="tFormalExpression">${environment.variables.reject}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="receive" name="同意" sourceRef="decision" targetRef="end">
      <bpmn:conditionExpression xsi:type="tFormalExpression">${environment.variables.receive}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:endEvent id="end" name="结束">
      <bpmn:incoming>receive</bpmn:incoming>
    </bpmn:endEvent>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="process">
      <bpmndi:BPMNEdge id="Flow_055waog_di" bpmnElement="Flow_055waog">
        <di:waypoint x="419" y="120" />
        <di:waypoint x="510" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1fuhgue_di" bpmnElement="receive">
        <di:waypoint x="768" y="120" />
        <di:waypoint x="822" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="784" y="102" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0whhbow_di" bpmnElement="reject">
        <di:waypoint x="743" y="95" />
        <di:waypoint x="743" y="10" />
        <di:waypoint x="369" y="10" />
        <di:waypoint x="369" y="80" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="546" y="-8" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_0gnbudv_di" bpmnElement="SequenceFlow_0gnbudv">
        <di:waypoint x="610" y="260" />
        <di:waypoint x="743" y="260" />
        <di:waypoint x="743" y="145" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="673.5" y="99" width="0" height="12" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_18lxtv3_di" bpmnElement="SequenceFlow_18lxtv3">
        <di:waypoint x="560" y="160" />
        <di:waypoint x="560" y="220" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="470.5" y="99" width="0" height="12" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_1fjfu37_di" bpmnElement="SequenceFlow_1fjfu37">
        <di:waypoint x="209" y="120" />
        <di:waypoint x="319" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="264" y="99" width="0" height="12" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="start">
        <dc:Bounds x="173" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="180" y="145" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="UserTask_0kzxz5g_di" bpmnElement="ask">
        <dc:Bounds x="319" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="UserTask_0u58eus_di" bpmnElement="agree">
        <dc:Bounds x="510" y="220" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="EndEvent_09wk9ed_di" bpmnElement="end">
        <dc:Bounds x="822" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="829" y="145" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0ygtiqu_di" bpmnElement="serviceTask">
        <dc:Bounds x="510" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_0um5w19_di" bpmnElement="decision" isMarkerVisible="true">
        <dc:Bounds x="718" y="95" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="652" y="110" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

目前有几种流程执行方式,

第一种是审批流

{{HOST}}/api/bpm/process/execute

申请流程

{
  "id": 1,
  "task": "ask",
  "inputs": {
    "action": "xxxxx"
  }
}

审批流程

{
  "id": 1,
  "task": "agree",
  "inputs": {
    "action": "receive" // reject
  }
}

第二种是运算流

{{HOST}}/api/bpm/definition/execute
{
  "id": 1,
  "inputs": {
    "action": "receive" // reject
  }
}

创建一个服务流程类

export class TaskService {
  /**
   * args: 页面请求的输入值、之前所有任务的输出值
   * scope: 当前流程的数据
   * next 进入下一步
   */
  async checkToken(args, scope, next): Promise<any> {
    let error = null
    next(error, {
      cover: false, // 清空上一个任务返回给客户端的数据
      ctx: { // 返回给客户端的数据
      }
    })
  }
}

创建一个用户流程类

export class UserService {
  /**
   * args: 页面请求的输入值、之前所有任务的输出值
   * userTask: 当前流程的数据
   * definition 整体流程
   */
  async execute(args, userTask, definition): Promise<any> {
    userTask.signal({
      cover: false, // 清空上一个任务返回给客户端的数据
      ctx: { // 返回给客户端的数据
      }
    })
  }
}