-
Notifications
You must be signed in to change notification settings - Fork 0
/
Part6.java
130 lines (127 loc) · 6.39 KB
/
Part6.java
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
package com.viathink.flowable;
import org.flowable.engine.*;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class Part6 {
private ProcessEngine processEngine = null;
// 初始化流程引擎
@Before
public void createDeployment() {
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
cfg.setJdbcDriver("com.mysql.cj.jdbc.Driver");
cfg.setJdbcUrl("jdbc:mysql://localhost:3306/flowable621?useUnicode=true&characterEncoding=utf8&useSSL=false");
cfg.setJdbcUsername("root");
cfg.setJdbcPassword("rootroot");
cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
processEngine = cfg.buildProcessEngine();
}
// 历史流程实例查看(查找按照某个规则或流程定义一共执行了多少次流程)
@Test
public void queryHistoricProcessInstance() {
HistoryService historyService = processEngine.getHistoryService();
List<HistoricProcessInstance> hpiList = historyService.createHistoricProcessInstanceQuery()
.processDefinitionKey("myProcess")
.orderByProcessInstanceStartTime()
.desc()
.list();
for (HistoricProcessInstance hpi: hpiList) {
System.out.println("pId: " + hpi.getId());
System.out.println("pdId: " + hpi.getProcessDefinitionId());
System.out.println("startTime: " + hpi.getStartTime());
System.out.println("endTime: " + hpi.getEndTime());
System.out.println("duration: " + hpi.getDurationInMillis());
System.out.println("----------------------------------------");
}
}
// 某一次流程一共经历了多少个活动
@Test
public void queryHistoricActivityInstance() {
String processInstanceId = "2501";
HistoryService historyService = processEngine.getHistoryService();
List<HistoricActivityInstance> haiList = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricActivityInstanceEndTime()
.asc()
.list();
for (HistoricActivityInstance hai: haiList) {
System.out.println("id: " + hai.getId());
System.out.println("activityId: " + hai.getActivityId());
System.out.println("taskId: " + hai.getTaskId());
System.out.println("pId: " + hai.getProcessInstanceId());
System.out.println("name: " + hai.getActivityName());
System.out.println("type: " + hai.getActivityType());
System.out.println("assignee: " + hai.getAssignee());
System.out.println("startTime: " + hai.getStartTime());
System.out.println("endTime: " + hai.getEndTime());
System.out.println("duration: " + hai.getDurationInMillis());
System.out.println("--------------------------------------");
}
}
// 历史任务查询(某一次流程的执行经历了多少任务节点)
@Test
public void queryHistoricTask() {
String processInstanceId = "2501";
HistoryService historyService = processEngine.getHistoryService();
List<HistoricTaskInstance> htiList = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricTaskInstanceStartTime()
.asc()
.list();
for (HistoricTaskInstance hti: htiList) {
System.out.println("--------------------------------------");
System.out.println("taskId: " + hti.getId());
System.out.println("name: " + hti.getName());
System.out.println("pId: " + hti.getProcessInstanceId());
System.out.println("pdId: " + hti.getProcessDefinitionId());
System.out.println("workTime: " + hti.getWorkTimeInMillis());
System.out.println("assignee: " + hti.getAssignee());
System.out.println("startTime: " + hti.getStartTime());
System.out.println("endTime: " + hti.getEndTime());
System.out.println("duration: " + hti.getDurationInMillis());
}
}
// 某一次流程执行时设置的流程变量
@Test
public void queryHistoricVariables() {
String processInstanceId = "2501";
HistoryService historyService = processEngine.getHistoryService();
List<HistoricVariableInstance> hviList = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(processInstanceId)
.orderByVariableName()
.asc()
.list();
for (HistoricVariableInstance hvi: hviList) {
System.out.println("--------------------------------------");
System.out.println("id: " + hvi.getId());
System.out.println("pId: " + hvi.getProcessInstanceId());
System.out.println("variableName: " + hvi.getVariableName());
System.out.println("variableType: " + hvi.getVariableTypeName());
System.out.println("variableValue: " + hvi.getValue());
}
}
// 通过流程变量查询历史流程实例
@Test
public void queryProcessInstanceByVariable() {
HistoryService historyService = processEngine.getHistoryService();
List<HistoricProcessInstance> hpiList = historyService.createHistoricProcessInstanceQuery()
.variableValueEquals("sheetId", "12345")
.orderByProcessInstanceStartTime()
.desc()
.list();
for (HistoricProcessInstance hpi: hpiList) {
System.out.println("pId: " + hpi.getId());
System.out.println("pdId: " + hpi.getProcessDefinitionId());
System.out.println("businessKey: " + hpi.getBusinessKey());
System.out.println("startTime: " + hpi.getStartTime());
System.out.println("endTime: " + hpi.getEndTime());
System.out.println("duration: " + hpi.getDurationInMillis());
System.out.println("----------------------------------------");
}
}
}