flowable 候选人候选组同时使用

目录

  • 前言
  • 一、流程xml
  • 二、测试流程
    • 1.部署流程
    • 2.启动流程
    • 3.获取任务
  • 总结


前言

本文主要演示候选组和和候选人同时使用的场景。


一、流程xml

flowable 候选人候选组同时使用_第1张图片

<?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:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" xmlns:flowable="http://flowable.org/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.flowable.org/processdef">
  <process id="group_assignee_test" name="候选组候选人同时使用测试">
    <startEvent id="startNode1" name="开始">
      <outgoing>Flow_14bgmff</outgoing>
    </startEvent>
    <endEvent id="Event_1x74o82">
      <incoming>Flow_10icilg</incoming>
    </endEvent>
    <userTask id="Activity_0xiexcw" name="测试审批" flowable:candidateGroups="${group1}" flowable:candidateUsers="${user1}">
      <incoming>Flow_14bgmff</incoming>
      <outgoing>Flow_10icilg</outgoing>
    </userTask>
    <sequenceFlow id="Flow_14bgmff" sourceRef="startNode1" targetRef="Activity_0xiexcw" />
    <sequenceFlow id="Flow_10icilg" sourceRef="Activity_0xiexcw" targetRef="Event_1x74o82" />
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_flow">
    <bpmndi:BPMNPlane id="BPMNPlane_flow" bpmnElement="group_assignee_test">
      <bpmndi:BPMNEdge id="Flow_10icilg_di" bpmnElement="Flow_10icilg">
        <di:waypoint x="720" y="215" />
        <di:waypoint x="1012" y="215" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_14bgmff_di" bpmnElement="Flow_14bgmff">
        <di:waypoint x="270" y="215" />
        <di:waypoint x="620" y="215" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="BPMNShape_startNode1" bpmnElement="startNode1" bioc:stroke="">
        <omgdc:Bounds x="240" y="200" width="30" height="30" />
        <bpmndi:BPMNLabel>
          <omgdc:Bounds x="242" y="237" width="23" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1x74o82_di" bpmnElement="Event_1x74o82">
        <omgdc:Bounds x="1012" y="197" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1lkyh98_di" bpmnElement="Activity_0xiexcw">
        <omgdc:Bounds x="620" y="175" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

里面只有一个审批节点,定义了审批人和审批组两个变量,分别是 ${group1} 和 ${user1},流程的key是 group_assignee_test

<userTask id="Activity_0xiexcw" name="测试审批" flowable:candidateGroups="${group1}" flowable:candidateUsers="${user1}">

二、测试流程

1.部署流程

@Test
    public void createDeploymentTest() {
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("候选组候选人同时使用测试.bpmn20.xml")
                .deploy();
        System.out.println(deployment.getId());
    }

2.启动流程

给变量 group1 赋值 “开发组,测试组”,
给变量 user1 赋值 “张三,李四”,
然后启动 group_assignee_test 流程

 @Test
    public void startProcessDefinition() {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("group1", "开发组,测试组");
        variables.put("user1", "张三,李四");
        ProcessInstance processInstance =
                runtimeService.startProcessInstanceByKey("group_assignee_test", variables);
        System.out.println(processInstance.getName());
    }

3.获取任务

(1)通过候选人 “张三” 获取任务

	@Test
    public void getTaskByCandidateUser() {
        List<Task> tasks = taskService.createTaskQuery()
                .active()
                .includeProcessVariables()
                .taskCandidateUser("张三")
                .includeIdentityLinks()
                .list();
        System.out.println("You have " + tasks.size() + " tasks:");
        for (int i = 0; i < tasks.size(); i++) {
            System.out.println((i + 1) + ") " + tasks.get(i).getName());
        }
    }

结果能查询出任务

You have 1 tasks:
1) 测试审批

(2)通过候选组 “开发组” 获取任务

	@Test
    public void getTaskByCandidateGroup() {
        List<Task> tasks = taskService.createTaskQuery()
                .active()
                .includeProcessVariables()
                .taskCandidateGroupIn(List.of("开发组"))
                .includeIdentityLinks()
                .list();
        System.out.println("You have " + tasks.size() + " tasks:");
        for (int i = 0; i < tasks.size(); i++) {
            System.out.println((i + 1) + ") " + tasks.get(i).getName());
        }
    }

结果,同样能够查询出该任务

You have 1 tasks:
1) 测试审批

总结

通过测试,说明工作流是支持候选人和候选组同时使用的,在一些特殊业务场景就能够使用上。

你可能感兴趣的:(flowable,java)