flowable多人会签
12、多人会签
1、流程图绘制
多人会签是指一个任务需要多个来处理,案例讲解
流程绘制本人用了flowable
主键ID:userTask1 #自己来决定
名称:用户任务 #自己决定
多实例类型:Parallel
基数(多实例):3 #输入会签人数
集合(多实例) : persons
元素变量(多实例) : person
完成条件(多实例 completeTask) : ${mulitiInstanceCompleteTask.completeTask(execution)} #调用监听器组件里的completeTask方法记得参数名写对了
completeTask:${mulitiInstanceTaskListener.completeListener(execution)} #表达式,事件下拉框中选择create,类名为空
完整的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" exporter="Flowable Open Source Modeler" exporterVersion="6.8.0">
<process id="MyHolidayUI" name="用户多实例会签" isExecutable="true">
<documentation>请假流程</documentation>
<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<userTask id="userTask1" name="用户任务" flowable:assignee="$INITIATOR" flowable:formFieldValidation="true">
<extensionElements>
<flowable:taskListener event="create" expression="${mulitiInstanceTaskListener.completeListener(execution)}"></flowable:taskListener>
<modeler:activiti-idm-initiator xmlns:modeler="http://flowable.org/modeler"><![CDATA[true]]></modeler:activiti-idm-initiator>
</extensionElements>
<multiInstanceLoopCharacteristics isSequential="false" flowable:collection="persons" flowable:elementVariable="person">
<extensionElements></extensionElements>
<loopCardinality>3</loopCardinality>
<completionCondition>${mulitiInstanceCompleteTask.completeTask(execution)}</completionCondition>
</multiInstanceLoopCharacteristics>
</userTask>
<sequenceFlow id="sid-611184F4-3FB0-4151-A9DA-041802A716C0" sourceRef="startEvent1" targetRef="userTask1"></sequenceFlow>
<endEvent id="sid-7002B6DC-458F-409A-8D71-286DC617B942"></endEvent>
<sequenceFlow id="sid-D1309118-5A7A-40E9-BC28-F734AB72B884" sourceRef="userTask1" targetRef="sid-7002B6DC-458F-409A-8D71-286DC617B942"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_MyHolidayUI">
<bpmndi:BPMNPlane bpmnElement="MyHolidayUI" id="BPMNPlane_MyHolidayUI">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="194.99999710552157" y="509.99998485965136"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="userTask1" id="BPMNShape_userTask1">
<omgdc:Bounds height="79.99999999999983" width="100.0" x="345.0000086241834" y="480.00001199886384"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-7002B6DC-458F-409A-8D71-286DC617B942" id="BPMNShape_sid-7002B6DC-458F-409A-8D71-286DC617B942">
<omgdc:Bounds height="28.0" width="28.0" x="504.99999465634755" y="510.9999704614771"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-D1309118-5A7A-40E9-BC28-F734AB72B884" id="BPMNEdge_sid-D1309118-5A7A-40E9-BC28-F734AB72B884" flowable:sourceDockerX="50.0" flowable:sourceDockerY="39.999999999999915" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
<omgdi:waypoint x="444.95000862416634" y="520.0000119988638"></omgdi:waypoint>
<omgdi:waypoint x="475.0000016402655" y="520.0000119988638"></omgdi:waypoint>
<omgdi:waypoint x="475.0000016402655" y="524.9999704614771"></omgdi:waypoint>
<omgdi:waypoint x="504.99999465634755" y="524.9999704614771"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-611184F4-3FB0-4151-A9DA-041802A716C0" id="BPMNEdge_sid-611184F4-3FB0-4151-A9DA-041802A716C0" flowable:sourceDockerX="14.999999999999996" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.00000000000001" flowable:targetDockerY="39.999999999999915">
<omgdi:waypoint x="224.94999385865802" y="524.9999848596514"></omgdi:waypoint>
<omgdi:waypoint x="285.0000028648525" y="524.9999848596514"></omgdi:waypoint>
<omgdi:waypoint x="285.0000028648525" y="520.0000119988638"></omgdi:waypoint>
<omgdi:waypoint x="345.0000086241834" y="520.0000119988638"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
2、流程说明
3、案例演示
3.1部署流程
测试代码:
yaml文件
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/flowable1?serverTimezone=UTC&nullCatalogMeansCurrent=true
username: root
password: 123456
hikari:
minimum-idle: 5
idle-timeout: 600000
maximum-pool-size: 10
auto-commit: true
pool-name: MyHikariCP
max-lifetime: 180000
connection-timeout: 30000
connection-test-query: SELECT 1
flowable:
async-executor-activate: false #关闭定时任务
#J0B将databaseSchemaupdate 设置为true。当FLowable发现库与数库表结构不一致时,会自动将数据库表结构升级至新版本.
database-schema-update: true
server:
port: 8082
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bonc</groupId>
<artifactId>flowable-springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>flowable-springboot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.32</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.bonc;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.task.api.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
/**
* @description:
* @author: defu
* @date: 2023/3/21 13:42
* @version:1.0
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class FlowableSpringBootApplicationTests {
@Qualifier("processEngine")
@Autowired
private ProcessEngine processEngine;
@Autowired
private RepositoryService repositoryService;
@Autowired
private TaskService taskService;
@Autowired
private RuntimeService runtimeService;
/**
* 部署
*/
@Test
public void testDeploy() {
Deployment deploy = repositoryService.createDeployment().addClasspathResource("用户多实例会签.bpmn20.xml").name("会签案例").deploy();
System.out.println("deploy.getId() = " + deploy.getId());
System.out.println("deploy.getName() = " + deploy.getName());
System.out.println("部署开始时间: " + new Date());
}
/**
* 启动流程
*/
@Test
public void testStratFlow() {
HashMap<String, Object> map = new HashMap<>();
//设置多人会签的数据,一定要大于等于3
map.put("persons", Arrays.asList("张三", "李四", "王五", "赵六"));
runtimeService.startProcessInstanceById("MyHolidayUI:1:a275fa34-e3e5-11ed-9555-00ffaabbccdd", map);
}
/**
* 完成任务
*/
@Test
public void completeTask() {
HashMap<String, Object> map = new HashMap<>();
map.put("flag", false);//设置为true,结束多人会签
taskService.complete("d41b1f43-e3e0-11ed-b803-00ffaabbccdd", map);
System.out.println("complete....");
}
/**
* 完成任务
* 执行完成任务,在数据库里的task表中数据为空
*/
@Test
public void completeTask2() {
HashMap<String, Object> map = new HashMap<>();
map.put("flag", true);//设置为true,结束多人会签
taskService.complete("d41d6938-e3e0-11ed-b803-00ffaabbccdd", map);
System.out.println("complete....");
}
/**
* 完成任务
*/
@Test
public void completeTask3() {
Task task = taskService.createTaskQuery()
.processDefinitionId("holiday-springboot:1:94b7de0c-c7b1-11ed-8c58-00ffaabbccdd")
.taskAssignee("zhangsan")
.singleResult();
if (task != null) {
taskService.complete(task.getId());
System.out.println("处理完成。。。。。");
}
}
}
/**
* 部署
*/
@Test
public void testDeploy() {
Deployment deploy = repositoryService.createDeployment()
.addClasspathResource("用户多实例会签.bpmn20.xml").name("会签案例").deploy();
System.out.println("deploy.getId() = " + deploy.getId());
System.out.println("deploy.getName() = " + deploy.getName());
System.out.println("部署开始时间: " + new Date());
}
执行结果
3.2 启动流程
/**
* 启动流程
*/
@Test
public void testStratFlow() {
HashMap<String, Object> map = new HashMap<>();
//设置多人会签的数据,一定要大于等于3
map.put("persons", Arrays.asList("张三", "李四", "王五", "赵六"));
runtimeService.startProcessInstanceById("MyHolidayUI:1:a275fa34-e3e5-11ed-9555-00ffaabbccdd", map);
}
执行结果
3.3 会签处理任务
/**
* 完成任务
*/
@Test
public void completeTask() {
HashMap<String, Object> map = new HashMap<>();
map.put("flag", false);//设置为true,结束多人会签
taskService.complete("f7517575-e3e5-11ed-bc21-00ffaabbccdd", map);
System.out.println("complete....");
}
结束多人会签
/**
* 完成任务
* 执行完成任务,在数据库里的task表中数据为空
*/
@Test
public void completeTask2() {
HashMap<String, Object> map = new HashMap<>();
map.put("flag", true);//设置为true,结束多人会签
taskService.complete("d41d6938-e3e0-11ed-b803-00ffaabbccdd", map);
System.out.println("complete....");
}
本文来自博客园,作者:星星之草%,转载请注明原文链接:https://www.cnblogs.com/zhaodefu/p/17355246.html