Activiti使用手册(2)- Java API
# Activiti使用手册(2)- Java API
# 四、Activiti6 接口
- 核心类:ProcessEngine
- 七大核心服务类,一个Activiti6新增服务类
- RepositoryService:流程仓库Service,可以管理流程仓库例,如:部署、删除、读取流程资源
- RuntimeService:运行时Service,可以处理所有运行状态的流程实例流程控制(开始、暂停、挂起等)
- TaskService:任务Service,用于管理、查询任务,例如签收、办理、指派等
IdentitiService:身份Service(Actitivi7不支持),可以管理查询用户、组之间的关系FormService:表单Service(Actitivi7不支持),用于读取和流程、任务相关的表单数据- HistoryService:历史Service,用于查询所有的历史数据
- ManagementService:引擎管理Service,和具体业务无关,主要查询引擎配置,数据库作业
- DynamicBpmService:动态bpm服务
# 1、RepositoryService,流程存储服务
功能
- 管理流程定义文件xml及静态资源服务
- 对流程定义文件对暂停激活(流程定义)
- 流程定义启动权限管理
基础API
- 部署文件构造器:DeploymentBuilder(对资源进行封装,手动部署Resource)
- 部署文件查询器:DeploymentQuery
- 流程定义文件查询对象:ProcessDefinitionQuery
基础对象
- 流程部署文件对象:Deployment
- 流程定义文件对象:ProcessDefinition
- 流程定义的Java格式:BpmnModel(纯Java的数据结构,Map、List)
# 1)常用API
序号 | 方法 | 含义 | 描述 | 库表字段 |
---|---|---|---|---|
1 | repositoryService.createDeployment().addClasspathResource("参数") .deploy() | 部署流程 | resources文件下面的xml流程文件 | 省略 |
2 | repositoryService.createDeploymentQuery().list() | 查询所有部署 | 省略 | 省略 |
3 | repositoryService.createProcessDefinitionQuery().list() | 查询所有部署流程 | 省略 | 省略 |
4 | repositoryService.suspendProcessDefinitionById(id)或ByKey | 挂起流程 | 根据流程id挂起流程 | 修改表ACT_RE_PROCDEF字段SUSPENSION_STATE_:1激活 2挂起 |
5 | repositoryService.activateProcessDefinitionById(id)或ByKey | 启动流程 | 根据流程id激活流程 | 修改表ACT_RE_PROCDEF字段SUSPENSION_STATE_:1激活 2挂起 |
6 | repositoryService.addCandidateStarterUser(流程id,用户id) | 流程与用户对应关系 | 添加流程与用户关系 | 操作ACT_RU_IDENTITYLINK表 |
7 | repositoryService.deleteCandidateStarterGroup(流程id,用户组id) | 流程与用户组对应关系 | 添加流程与用户组关系 | 操作ACT_RU_IDENTITYLINK表 |
8 | repositoryService.deleteCandidateStarterUser(流程id,用户id) | 流程与用户对应关系 | 删除流程与用户关系 | 操作ACT_RU_IDENTITYLINK表 |
9 | repositoryService.deleteCandidateStarterGroup(流程id,用户组id) | 流程与用户对应关系 | 删除流程与用户组关系 | 操作ACT_RU_IDENTITYLINK表 |
10 | repositoryService.getIdentityLinksForProcessDefinition(流程id) | 查询流程对应关系 | 查询流程对应用户跟组关系 | 查询ACT_RU_IDENTITYLINK表 |
# 2)测试代码
package com.guosh.activiti.coreapi;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.test.ActivitiRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
/**
* 流程存储服务
* @Author: Leo
* @Date: 2020-01-15 11:33
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:activiti-context.xml"})
public class RepostoryServiceTest {
private static final Logger logger = LoggerFactory
.getLogger(RepostoryServiceTest.class);
@Rule
@Autowired
public ActivitiRule activitiRule;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Test
public void testRepository(){
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
//classpath方式
Deployment deploy = deploymentBuilder.name("测试部署资源1")
.addClasspathResource("my-process.bpmn20.xml")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
//多次部署
//classpath方式
DeploymentBuilder deploymentBuilder2 = repositoryService.createDeployment();
Deployment deploy2 = deploymentBuilder2.name("测试部署资源2")
.addClasspathResource("my-process.bpmn20.xml")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
//查询部署
List<Deployment> deployments = repositoryService.createDeploymentQuery()
.orderByDeploymenTime().asc()
.list();
for (Deployment deployment:deployments){
logger.info("deployment = {}",deployment);
}
logger.info("deployments.size = {}",deployments.size());
//查询已经部署流程
List<ProcessDefinition> processDefinitions = repositoryService
.createProcessDefinitionQuery()
.list();
for (ProcessDefinition processDefinition:processDefinitions) {
logger.info("processDefinition = {}, version = {}, key = {}, id = {}",
processDefinition,
processDefinition.getVersion(),
processDefinition.getKey(),
processDefinition.getId());
}
}
//测试流程挂起启动
@Test
public void testSuspend(){
//流程挂起
repositoryService.suspendProcessDefinitionById("my-process:1:7506");
//如果流程挂起启动流程会报错
try{
logger.info("启动流程");
runtimeService.startProcessInstanceById("my-process:1:7506");
logger.info("启动成功");
}catch (Exception e){
logger.info("启动失败");
logger.info(e.getMessage(),e);
}
//流程激活
repositoryService.activateProcessDefinitionById("my-process:1:7506");
logger.info("启动流程");
runtimeService.startProcessInstanceById("my-process:1:7506");
logger.info("启动成功");
}
//测试指定用户或者用户组与流程的关系
@Test
public void testCandidateStarter(){
//给流程指定用户参数流程id与用户id
repositoryService.addCandidateStarterUser("my-process:1:7506","user");
//给流程指定用户组
repositoryService.addCandidateStarterGroup("my-process:1:7506","groupM");
//查询流程对应关系的所有用户
List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition("my-process:1:7506");
for (IdentityLink identityLink:identityLinks) {
logger.info("identityLink = {}",identityLink);
}
//删除关系
repositoryService.deleteCandidateStarterUser("my-process:1:7506","user");
repositoryService.deleteCandidateStarterGroup("my-process:1:7506","groupM");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 3)结果示例
# 2、RuntimeService,流程运行控制服务
- 功能及API
- 启动流程及对流程数据对控制
- 启动流程的常用方式(id、key、message)
- 启动流程可选参数(businesskey、variables、tenantId)
- 变量(variables)的设置和获取
- 流程实例(ProcessInstance)与执行流(Execution)查询
- 流程实例(ProcessInstance):表示一次工作流业务的数据实体
- 执行流(Execution):表示流程实例中具体的执行路径
- 流程实例接口继承与执行流
- 触发流程操作、接收消息和信号(驱动流程运行)
- 使用trigger触发ReceiveTask节点
- 触发信号捕获事件signalEvenReceived
- 触发消息捕获事件messageEventReceived
- 启动流程及对流程数据对控制
# 1)常用API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | runtimeService.startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) | 根据部署流程key启动一个流程 | 省略 |
2 | runtimeService.startProcessInstanceById(String processDefinitionId, Map<String, Object> variables) | 根据部署流程id启动一个流程 | 省略 |
3 | runtimeService.createProcessInstanceBuilder().businessKey("businessKey001") .processDefinitionKey(String processDefinitionKey).variables( Map<String, Object> variables) .start() | 根据processInstanceBuilder启动流程 | 省略 |
4 | runtimeService.getVariables(processInstance.getId()) | 根据流程实例id获取传参 | 省略 |
5 | runtimeService.setVariable(processInstance.getId(),"key3","value3") | 新增或修改参数 | 省略 |
6 | runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()) | 查询流程实例 | 根据流程id获取流程实例 |
7 | runtimeService.createExecutionQuery() | 获取流程执行对象 | 省略 |
# 2)测试代码
/**
* 流程运行控制服务
* @Author: Guosh
* @Date: 2019-07-19 11:33
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:activiti-context.xml"})
public class RuntimeServiceTest {
private static final Logger logger = LoggerFactory.getLogger(RuntimeServiceTest.class);
@Rule
@Autowired
public ActivitiRule activitiRule;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
//部署流流程
@Test
public void testRepository(){
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
//classpath方式
Deployment deploy = deploymentBuilder.name("测试部署资源1")
.addClasspathResource("my-process-signal-received.bpmn20.xml")
.deploy();
}
//根据key启动流程
@Test
public void testStartProcess(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
//启动流程根据key默认使用的流程的最新版本
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
}
//根据id启动流程
@Test
public void testStartProcessById(){
ProcessDefinition processDefinition = repositoryService
.createProcessDefinitionQuery().singleResult();
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceById(processDefinition.getId(), variables);
logger.info("processInstance = {}",processInstance);
}
//根据processInstanceBuilder启动流程
@Test
public void testProcessInstanceBuilder(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
//启动流程
ProcessInstanceBuilder processInstanceBuilder = runtimeService
.createProcessInstanceBuilder();
ProcessInstance processInstance = processInstanceBuilder
.businessKey("businessKey001")
.processDefinitionKey("my-process")
.variables(variables)
.start();
logger.info("processInstance = {}",processInstance);
}
//根据其流程实例id获取参数
@Test
public void testVariables(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
variables.put("key2","value2");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
//新增一个参数
runtimeService.setVariable(processInstance.getId(),"key3","value3");
//修改一个参数
runtimeService.setVariable(processInstance.getId(),"key2","value2_1");
//获取流程实例传过来的参数
Map<String, Object> variables1 = runtimeService
.getVariables(processInstance.getId());
logger.info("variables1 = {}",variables1);
}
//根据其流程实例id获取
@Test
public void testProcessInstanceQuery(){
Map<String,Object> variables=new HashMap<String,Object>();
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
ProcessInstance processInstance1 = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstance.getId()).singleResult();
}
//流程执行对象查询操作
@Test
public void testExecutionQuery(){
Map<String,Object> variables=new HashMap<String,Object>();
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
//流程执行对象
List<Execution> executions = runtimeService.createExecutionQuery().list();
for (Execution execution:executions){
logger.info("execution = {}",execution);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 3)结果示例
# 4)流程触发
# ①原理
# ②测试代码
//流程触发
@Test
public void testTrigger(){
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
//流程执行对象
Execution executions = runtimeService
.createExecutionQuery()
.activityId("someTask")
.singleResult();
logger.info("executions = {}",executions);
//触发执行
runtimeService.trigger(executions.getId());
executions = runtimeService.createExecutionQuery()
.activityId("someTask")
.singleResult();
logger.info("executions = {}",executions);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# ③流程文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<receiveTask id="someTask"/>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# ④结果示例
# 5)信号捕获节点触发
# ①原理
# ②测试代码
//信号流程节点触发
@Test
public void testSignalEventReceived(){
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
//查询触发信号
Execution executions = runtimeService
.createExecutionQuery().signalEventSubscriptionName("my-signal").singleResult();
logger.info("executions = {}",executions);
//触发执行
runtimeService.signalEventReceived("my-signal");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ③流程文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<!--信号-->
<signal id="signalStart" name="my-signal"/>
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="signal-received" />
<!--捕获事件-->
<intermediateCatchEvent id="signal-received">
<signalEventDefinition signalRef="signalStart"/>
</intermediateCatchEvent>
<sequenceFlow id="flow2" sourceRef="signal-received" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ④结果示例
# 6)消息触发
# ①原理
# ②测试代码
//消息流程节点触发
@Test
public void testMessageEventReceived(){
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
//查询触发信号
Execution executions = runtimeService
.createExecutionQuery().messageEventSubscriptionName("my-message").singleResult();
logger.info("executions = {}",executions);
//触发执行
runtimeService.messageEventReceived("my-message",executions.getId());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# ③流程文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<!--信号-->
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="message-received" />
<!--捕获事件-->
<intermediateCatchEvent id="message-received">
<messageEventDefinition messageRef="messageStart"/>
</intermediateCatchEvent>
<sequenceFlow id="flow2" sourceRef="message-received" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ④结果示例
# 7)流程基于message启动
# ①原理
# ②测试代码
@Test
public void testMessageStart(){
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByMessage("my-message");
logger.info("processInstance = {}",processInstance);
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# ③流程文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<!--信号-->
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start" >
<messageEventDefinition messageRef="messageStart"/>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" />
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ④结果示例
# 3、TaskService,流程管理服务
- 功能
- 对用户任务(UserTask)管理和流程控制
- Task对象的创建,删除
- 查询Task,并驱动Task节点完成执行
- Task相关参数变量(variable)设置
- 设置用户任务(UserTask)对权限信息(拥有者、候选人、办理人)
- 候选用户(candidateUser)和候选组(candidateGroup)
- 指定拥有人(Owner)和办理人(Assignee)
- 通过claim设置办理人
- 针对用户任务添加任务附件、任务评论和事件记录
- 任务附件(Attachment)创建与查询
- 任务评价(Comment)创建与查询
- 事件记录(Event)创建与查询
- 对用户任务(UserTask)管理和流程控制
# 1)常用API
# ①管理和流程控制API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | taskService.createTaskQuery().list() | 查询所有任务 | 省略 |
2 | taskService.setVariable("任务id","键","值") | 设置普通变量 | 省略 |
3 | taskService.setVariableLocal("任务id","键","值") | 设置本地变量 | 省略 |
4 | taskService.getVariables("任务id") | 获取普通变量 | 省略 |
5 | taskService.getVariablesLocal(("任务id") | 获取本地变量 | 省略 |
6 | runtimeService.getVariables(task.getExecutionId()) | 通过流获取变量 | 省略 |
7 | taskService.complete("任务id","传值Map") | 到下一个节点 | 省略 |
# ②权限信息设置API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | taskService.setOwner("taskId","user") | 设置流程发起人 | 省略 |
2 | taskService.claim(""taskId"","user") | 指定代办人 | 省略 |
3 | taskService.addCandidateUser("user") | 添加候选人 | 省略 |
4 | taskService.addCandidateGroup("group") | 添加候选组 | 省略 |
5 | taskService.createTaskQuery().taskCandidateUser("user").taskUnassigned().list() | 查询候选人列表有user但是没指定代办人任务 | 省略 |
6 | taskService.createTaskQuery().taskCandidateUser("user").taskUnassigned().list() | 查询候选人列表有我但是没指定代办人任务 | 省略 |
7 | taskService.createTaskQuery().taskAssignee("user").list() | 查询代办人为user的任务 | 省略 |
8 | taskService.getIdentityLinksForTask("taskId") | 查询任务与人员之间的关系 | 省略 |
# ③任务附件、评论、事件记录API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | taskService.createAttachment("类型","任务id","流程Id","附件名称","附件描述","流或者url) | 上传附件 | 省略 |
2 | taskService.getTaskAttachments("任务id") | 上传附件 | 省略 |
3 | taskService.addComment("任务id","流程id","批注1") | 添加审批批注 | 省略 |
4 | taskService.getTaskComments("任务id") | 查询审批批注 | 省略 |
5 | taskService.getTaskEvents("任务id") | 查询任务日志记录 | 省略 |
# 2)测试代码
# ①管理和流程控制API
- Java代码
@Test
public void testTaskService(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//设置普通变量
taskService.setVariable(task.getId(),"key1","value1");
//设置本地变量
taskService.setVariableLocal(task.getId(),"localkey1","localval1");
//获取普通变量
Map<String, Object> taskServiceVariables = taskService.getVariables(task.getId());
//获取本地变量
Map<String, Object> taskServiceVariablesLocal = taskService.getVariablesLocal(task.getId());
//通过执行流获取
Map<String, Object> variables1 = runtimeService.getVariables(task.getExecutionId());
//{key1=value1, localkey1=localval1, message=my test message !!}
logger.info("taskServiceVariables = {}",taskServiceVariables);
//{localkey1=localval1}
logger.info("taskServiceVariablesLocal = {}",taskServiceVariablesLocal);
//{key1=value1, message=my test message !!}
logger.info("variables1 = {}",variables1);
Map<String,Object> completeVar=new HashMap<String, Object>();
completeVar.put("ckey1","cvalue1");
//执行下一个节点
taskService.complete(task.getId(),completeVar);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
- 运行结果
# ②权限信息设置API
- 流程配置文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<!--activiti:candidateStarterUsers指定候选人-->
<userTask id="someTask"
name="Activiti is awesome!"
activiti:candidateUsers="jimmy,user1,user2">
<!--添加描述-->
<documentation>some task ${message}</documentation>
</userTask>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- Java代码
//用户权限测试
@Test
public void testTaskServiceUser(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//设置流程到发起人
taskService.setOwner(task.getId(),"user1");
//指定办理人
//taskService.setAssignee(task.getId(),"jimmy");
//查询候选人列表有我但是没指定代办人任务
List<Task> taskList = taskService.createTaskQuery()
.taskCandidateUser("jimmy")
.taskUnassigned().list();
//指定办理人claim会检查该任务是否已经被认领
//如果被认领则会抛出ActivitiTaskAlreadyClaimedException
for (Task task1:taskList){
taskService.claim(task1.getId(),"jimmy");
}
//查询task与多少用户相关数据
List<IdentityLink> identityLinksForTask = taskService
.getIdentityLinksForTask(task.getId());
for(IdentityLink identityLink:identityLinksForTask){
logger.info("identityLink = {}",identityLink);
}
//查询代办人为jimmy的任务
List<Task> taskList1 = taskService.createTaskQuery().taskAssignee("jimmy").list();
for (Task task1:taskList1){
Map<String,Object> completeVar=new HashMap<String, Object>();
completeVar.put("ckey1","cvalue1");
taskService.complete(task.getId(),completeVar);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
- 运行结果
# ③任务附件、评论、事件记录API
//文件附件测试
@Test
public void testTaskServiceAttachment(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//上传附件
taskService.createAttachment("url",task.getId(),
task.getProcessInstanceId(),"附件名称","附件描述","/url/test.png");
//查询附件
List<Attachment> taskAttachments = taskService.getTaskAttachments(task.getId());
for (Attachment attachment:taskAttachments){
logger.info("attachment = {}",attachment);
}
}
//批注测试
@Test
public void testTaskServiceComment(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//添加审批批注
taskService.addComment(task.getId(),task.getProcessInstanceId(),"recourd note 1");
taskService.addComment(task.getId(),task.getProcessInstanceId(),"recourd note 2");
//查询审批批注
List<Comment> taskComments = taskService.getTaskComments(task.getId());
for (Comment comment:taskComments){
logger.info("comment = {}",comment);
}
//查询所有task日志记录
List<Event> taskEvents = taskService.getTaskEvents(task.getId());
for (Event event:taskEvents){
logger.info("event = {}",event);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
- 运行结果
# 4、IdentityService,用户和用户组管理服务
功能
- 管理用户(User)
- 管理用户组(Group)
- 用户与用户组关系(Membership)(多对多)
实现方式
# 1)常用API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | identityService.newUser("userid") | 创建一个用户 | 省略 |
2 | identityService.newGroup("groupid") | 创建一个组 | 省略 |
3 | identityService.saveUser(user) | 保存或者更新用户 | 省略 |
4 | identityService.saveGroup(group) | 保存或者更新组 | 省略 |
5 | identityService.createUserQuery() | 查询用户 | 省略 |
6 | identityService.createGroupQuery() | 查询组 | 省略 |
# 2)测试代码
@Test
public void testIdentity(){
//创建user
User user1 = identityService.newUser("user1");
//添加属性
user1.setEmail("user1@qq.com");
User user2 = identityService.newUser("user2");
user2.setEmail("user2@qq.com");
identityService.saveUser(user1);
identityService.saveUser(user2);
//创建group
Group group1 = identityService.newGroup("group1");
identityService.saveGroup(group1);
Group group2 = identityService.newGroup("group2");
identityService.saveGroup(group2);
//创建之间关系userid与grupid
identityService.createMembership("user1","group1");
identityService.createMembership("user2","group1");
identityService.createMembership("user1","group2");
//查询group1下面的用户
List<User> userList = identityService.createUserQuery().memberOfGroup("group1").list();
for (User user:userList) {
logger.info("user = {}",user);
}
//查询user1所属的group
List<Group> groupList = identityService.createGroupQuery().groupMember("user1").list();
for (Group group:groupList) {
logger.info("group = {}",group);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 3)结果示例
# 5、FormService,表单服务
- 功能
- 解析流程定义中表单项的配置
- 提交表单的方式驱动用户节点流转
- 获取自定义外部表单key
# 1)常用API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | formService.getStartFormKey(processDefinition.getId()) | 部署流程的id获取表单key | 省略 |
2 | formService.getStartFormData(processDefinition.getId()).getFormProperties() | 获取开始节点表单内容 | 省略 |
3 | formService.getStartFormData(processDefinition.getId()).getFormProperties() | 获取开始节点表单内容 | 省略 |
4 | formService.submitStartFormData(processDefinition.getId(), "传值参数") | 通过formservice启动流程 | 省略 |
5 | formService.submitTaskFormData("taskId","传参数") | 通过formservice提交task表单 | 省略 |
6 | formService.getTaskFormData("taskId") | 通过taskid获取task节点表单内容 | 省略 |
# 2)测试代码
- 流程文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<process id="my-process">
<startEvent id="start" activiti:formKey="/rest/process/form/start">
<extensionElements>
<activiti:formProperty id="message"
name="信息"
type="string"
required="true">
</activiti:formProperty>
</extensionElements>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!"
activiti:formKey="/rest/process/form/userTask">
<extensionElements>
<activiti:formProperty id="yewORno"
name="审批"
type="string"
required="true">
</activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
- Java代码
@Test
public void testFormService(){
//获取部署的流程
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
//获取startformkey
String startFormKey = formService.getStartFormKey(processDefinition.getId());
logger.info("startFormKey= {}",startFormKey);
//获取表单内容
StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
List<FormProperty> formProperties = startFormData.getFormProperties();
for (FormProperty formProperty:formProperties) {
logger.info("formProperty= {}",formProperty);
}
//通过formservice启动流程
Map<String,String> properties=new HashMap<String,String>();
properties.put("message","my test message");
ProcessInstance processInstance = formService.submitStartFormData(processDefinition.getId(), properties);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
//查询task表单
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
List<FormProperty> formProperties1 = taskFormData.getFormProperties();
for (FormProperty formProperty:formProperties1) {
logger.info("formProperties1= {}",formProperty);
}
Map<String, String> properties2 = new HashMap<String, String>();
properties2.put("yewORno","yes");
//用formservice提交task
formService.submitTaskFormData(task.getId(),properties2);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
- 结果示例
# 6、HistoryService,历史数据服务
功能
- 管理流程实例结束后的历史数据
- 构建历史数据查询对象
- 根据流程实例id删除流程历史数据
历史数据对象
HistoryService 构建历史查询对象
- create**[历史数据实体]**Query
- createNative**[历史数据实体]**Query | 通过原生sql查询
- createProcessInstanceHistoryLogQuery | 查询一个流程实例的所有其他数据
HistoryService 删除历史操作
- deleteHistoricProcessInstance | 删除历史流程实例及联删除其他信息
- deleteHistoricTaskInstance | 删除历史的task实例
# 1)常用API
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | historyService.createHistoricProcessInstanceQuery() | 查询流程实例变量 | 省略 |
2 | historyService.createHistoricActivityInstanceQuery() | 查询活动节点 | 省略 |
3 | historyService.createHistoricTaskInstanceQuery() | 查询任务实例 | 省略 |
4 | historyService.createHistoricVariableInstanceQuery() | 查询流程任务变量 | 省略 |
5 | historyService.createHistoricDetailQuery() | 历史任务流程活动详细信息 | 省略 |
6 | historyService.createProcessInstanceHistoryLogQuery("流程实例id") | 查询一个流程实例的所有其他数据 | 省略 |
7 | historyService.deleteHistoricProcessInstance("流程实例id") | 删除历史流程实例 | 省略 |
8 | historyService.deleteHistoricTaskInstance("taskid") | 删除历史任务 | 省略 |
# 2)测试代码
@Test
public void testHistory(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key0","value0");
variables.put("key1","value1");
variables.put("key2","value2");
Map<String,Object> transientVariables=new HashMap<String,Object>();
//传入参数
transientVariables.put("tkey1","tvalue1");
//启动流程
ProcessInstanceBuilder processInstanceBuilder = runtimeService
.createProcessInstanceBuilder();
ProcessInstance processInstance = processInstanceBuilder
.processDefinitionKey("my-process")
.variables(variables)
//瞬时变量不会持久化到数据库
.transientVariables(transientVariables)
.start();
logger.info("processInstance = {}",processInstance);
//修改key1值
runtimeService.setVariable(processInstance.getId(),"key1","value1_1");
Task task = taskService.createTaskQuery()
.processInstanceId(processInstance.getId())
.singleResult();
Map<String,String> properties =new HashMap<String, String>();
properties.put("fkey1","fvalue1");
properties.put("key2","value2_2");
formService.submitTaskFormData(task.getId(),properties);
//查询流程实例变量
List<HistoricProcessInstance> historicProcessInstances = historyService
.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance:historicProcessInstances) {
logger.info("historicProcessInstance = {}",historicProcessInstance);
}
//查询活动节点对象
List<HistoricActivityInstance> historicActivityInstances = historyService
.createHistoricActivityInstanceQuery().list();
for (HistoricActivityInstance historicActivityInstance:historicActivityInstances) {
logger.info("historicActivityInstance = {}",historicActivityInstance);
}
//查询任务实例
List<HistoricTaskInstance> historicTaskInstances = historyService
.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance historicTaskInstance:historicTaskInstances) {
logger.info("historicTaskInstance = {}",historicTaskInstance);
}
//查询流程任务变量值
List<HistoricVariableInstance> historicVariableInstances = historyService
.createHistoricVariableInstanceQuery().list();
for (HistoricVariableInstance historicVariableInstance:historicVariableInstances) {
logger.info("historicVariableInstance = {}",historicVariableInstance);
}
//历史任务流程活动详细信息
List<HistoricDetail> historicDetails = historyService
.createHistoricDetailQuery().list();
for (HistoricDetail historicDetail:historicDetails) {
logger.info("historicDetail = {}",historicDetail);
}
//查询一个流程实例的所有其他数据
ProcessInstanceHistoryLog processInstanceHistoryLog = historyService
.createProcessInstanceHistoryLogQuery(processInstance.getId())
//包含数据
.includeVariables()
.includeFormProperties()
.includeComments()
.includeTasks()
.includeActivities()
.includeVariableUpdates()
.singleResult();
List<HistoricData> historicDatas = processInstanceHistoryLog.getHistoricData();
for (HistoricData historicData:historicDatas) {
logger.info("historicData = {}",historicData);
}
//删除流程实例id
historyService.deleteHistoricProcessInstance(processInstance.getId());
//确认是否删除
HistoricProcessInstance historicProcessInstance = historyService
.createHistoricProcessInstanceQuery()
.processInstanceId(processInstance.getId())
.singleResult();
logger.info("historicProcessInstance = {}",historicProcessInstance);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# 3)结果示例
# 7、ManageService,管理服务
- 功能
- job任务管理
- JobQuery 查询一般工作
- TimerJobQuery 查询定时工作
- SuspendedJobQuery 查询中断工作
- DeadLetterJobQuery 查询无法执行的工作
- 数据库相关通用操作
- 查询表结构元数据(TableMetaData)
- 通用查询(TablePageQuery)
- 执行自定义Sql查询(executeCustomSql)
- 执行流程引擎命令(Command)
- job任务管理
# 1)核心API
# ①job任务管理
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | managementService.createTimerJobQuery() | 查询定时工作 | 省略 |
2 | managementService.createJobQuery() | 查询一般工作省略 | 省略 |
3 | managementService.createSuspendedJobQuery() | 查询中断工作 | 省略 |
4 | managementService.createDeadLetterJobQuery() | 查询无法执行的工作 | 省略 |
# ②数据库相关操作
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | managementService.createTablePageQuery().tableName(managementService.getTableName(class)) | 查询实体到所有数据 | 省略 |
2 | managementService.executeCustomSql() | 自定义sql查询 | 省略 |
# 2)测试代码
# ①job任务管理
- Java代码
@Test
public void testJobQuery(){
//工作任务查询
List<Job> timerJobList = managementService.createTimerJobQuery().list();
for (Job timerJob:timerJobList) {
logger.info("timerJob={}",timerJob);
}
JobQuery jobQuery = managementService.createJobQuery();
//中断的
SuspendedJobQuery suspendedJobQuery = managementService.createSuspendedJobQuery();
//不再执行
DeadLetterJobQuery deadLetterJobQuery = managementService.createDeadLetterJobQuery();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 流程文件
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.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.activiti.org/test">
<process id="my-process">
<startEvent id="start">
<timerEventDefinition>
<!--定时任务循环五次每十秒钟执行一次-->
<timeCycle>R5/PT10S</timeCycle>
</timerEventDefinition>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" />
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
- 结果示例
# ②数据库相关操作
- Java代码
public interface MyCustomMapper {
@Select("SELECT * FROM ACT_RU_TASK")
public List<Map<String,Object>> findAll();
}
1
2
3
4
2
3
4
@Test
public void testCustSql(){
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
//自定义sql语句
List<Map<String, Object>> mapList = managementService.executeCustomSql(new AbstractCustomSqlExecution<MyCustomMapper, List<Map<String, Object>>>(MyCustomMapper.class) {
@Override
public List<Map<String, Object>> execute(MyCustomMapper o) {
return o.findAll();
}
});
for (Map<String,Object> stringObjectMap:mapList) {
logger.info("stringObjectMap={}",stringObjectMap);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 流程文件
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/activiti6unit?
useUnicode=true&characterEncoding=utf8&
useSSL=false&autoReconnect=true&
failOverReadOnly=false" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
<!--数据库更新策略-->
<property name="databaseSchemaUpdate" value="true"/>
<!--异步激活器-->
<property name="asyncExecutorActivate" value="true"/>
<!--注册mapper对象-->
<property name="customMybatisMappers">
<set>
<value>com.guosh.activiti.mapper.MyCustomMapper</value>
</set>
</property>
</bean>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- 结果示例
# ③执行流程引擎命令(Command)
- Java代码
@Test
public void testCommand(){
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
//创建命令
ProcessDefinitionEntity processDefinitionEntity= managementService.executeCommand(new Command<ProcessDefinitionEntity>() {
@Override
public ProcessDefinitionEntity execute(CommandContext commandContext) {
ProcessDefinitionEntity processDefinitionEntity= commandContext.getProcessDefinitionEntityManager()
//最后一个流程定义的对象
.findLatestProcessDefinitionByKey("my-process");
return processDefinitionEntity;
}
});
logger.info("processDefinitionEntity={}",processDefinitionEntity);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 结果示例
# 8、DynamicBpmnService,动态流程定义服务
Activiti6 新引入的服务,较激进,暂不介绍。
# 9、ActivitiEXception,异常策略
- Activiti所有异常均继承自RuntimeException
- 常见Activiti异常
- ActivitiWrongDbException 引擎与数据库版本不匹配
- ActivitiOptimisticLockingException 并发导致乐观锁异常
- ActivitiClassLoadingException 加载类异常
- ActivitiObjectNotFoundException 操作对象不存在
- ActivitilllegalArgumentException 非法的参数
- ActivitiTaskAlreadyClaimedException 任务被重新声明代理人
- BpmnError 定义业务异常控制流程
上次更新: 2020/06/11, 15:06:00
- 01
- Activiti使用手册(4)- Bpmn2规范06-11
- 02
- linux手动RPM安装gcc,g++06-11