flowable多人会签与一票否决

先上代码,后面再详细讲解

Duorenhuiqian.bpmn20.xml

<?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="countersign" name="Duorenhuiqian" isExecutable="true">
    <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
    <userTask id="UserTask1" name="U1" flowable:assignee="${assignee}" flowable:formFieldValidation="true">
      <extensionElements>
        <!--<flowable:executionListener event="start" class="com.cars.ngtdms.cooperation.flowable.listener.CountersignListener"></flowable:executionListener>-->
        <flowable:executionListener event="start" delegateExpression="${countersignListener}"></flowable:executionListener>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="assigneeList" flowable:elementVariable="assignee">
        <completionCondition>${multiInstance.accessCondition(execution)}</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>
    <sequenceFlow id="sid-50622098-77B0-4413-A1D4-088B47DEC95F" sourceRef="startEvent1" targetRef="UserTask1"></sequenceFlow>
    <userTask id="UserTask2" name="U2" flowable:assignee="WXF" flowable:formFieldValidation="true">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <endEvent id="sid-814B8939-308D-4003-8B35-B750DC8F8A5C"></endEvent>
    <exclusiveGateway id="getWay" name="getWay"></exclusiveGateway>
    <userTask id="UserTask3" name="U3" flowable:assignee="PXY" flowable:formFieldValidation="true">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <endEvent id="sid-4C2BFAF2-08AC-4F89-A964-046EA583F0B5"></endEvent>
    <sequenceFlow id="sid-CE25CF8A-5BF2-4227-A747-98F6A053283E" sourceRef="UserTask3" targetRef="sid-4C2BFAF2-08AC-4F89-A964-046EA583F0B5"></sequenceFlow>
    <sequenceFlow id="sid-0F397F15-5685-4DF0-B7E0-75C3AB43F6D8" sourceRef="UserTask2" targetRef="sid-814B8939-308D-4003-8B35-B750DC8F8A5C"></sequenceFlow>
    <sequenceFlow id="sid-74E664CC-0FC9-49A6-A47C-BCFA1198F074" sourceRef="UserTask1" targetRef="getWay"></sequenceFlow>
    <sequenceFlow id="repply" name="通过" sourceRef="getWay" targetRef="UserTask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='通过'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="reject" name="否决" sourceRef="getWay" targetRef="UserTask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='否决'}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_countersign">
    <bpm
### Flowable 工作流引擎中会签功能的实现配置 #### 1. 实例活动的概念 在 Flowable 中,会签可以通过实例活动(Multi-Instance Activity)来实现。实例活动允许在一个业务流程中为特定步骤定义重复执行的方式[^2]。这种机制类似于编程中的 `for-each` 结构,能够针对集合中的每一项按顺序或并行地执行某个任务。 #### 2. 配置方式 为了支持会签,在设计流程时需要对目标用户任务节点启用实例特性。以下是具体的配置方法: ##### XML 定义 通过 BPMN 文件中的 `<userTask>` 节点添加实例扩展属性即可实现。以下是一个简单的示例: ```xml <userTask id="miUserTask" name="Multiple Instance User Task"> <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="${assignees}" flowable:elementVariable="assignee"> <!-- 设置并发模式 --> </multiInstanceLoopCharacteristics> </userTask> ``` 在此示例中: - 属性 `isSequential="false"` 表明该任务将以 **并行** 方式分配给个参者。 - 如果设置为 `true`,则表示任务将按照指定顺序逐一完成。 - 参数 `flowable:collection` 是一个值数据源,通常是从上下文中获取的一个列表对象,比如参者的 ID 列表。 - 参数 `flowable:elementVariable` 定义了每次迭代过程中使用的单个元素名称,这里指代每位具体参者。 #### 3. 默认流程变量的作用 当启用了实例特性之后,Flowable 自动提供了一些内置变量用于跟踪状态变化过程[^3]: - `nrOfInstances`: 总共创建了少个实例; - `nrOfCompletedInstances`: 当前已完成的任务数; - `nrOfActiveInstances`: 正处于活跃状态下的未结束任务数目; 这些信息可以帮助开发者监控整体进度以及判断何时满足条件从而继续后续逻辑处理。 #### 4. 示例代码展示如何动态加载参者名单 假设我们需要根据实际场景计算得出最终审批员,则可以在启动流程之前或者运行期间更新相关字段值。下面给出一段 Java 的伪代码演示这一操作: ```java // 假设我们有一个服务类负责返回候选数组 List<String> assignees = candidateService.getCandidatesForApproval(); Map<String, Object> variables = new HashMap<>(); variables.put("assignees", assignees); // 将候选列表放入流程变量中 runtimeService.startProcessInstanceByKey("processKey", variables); ``` 上述片段展示了怎样把外部获得的数据注入到正在构建的新实例里去供内部使用。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值