历史数据查询
HistoricProcessInstanceQuery query = pe.getHistoryService()
.createHistoricProcessInstanceQuery();
List<HistoricProcessInstance> list = query.list();
for (HistoricProcessInstance hi : list) {
System.out.println(hi.getId());
}
HistoricActivityInstanceQuery query = pe.getHistoryService()
.createHistoricActivityInstanceQuery();
List<HistoricActivityInstance> list = query.list();
for (HistoricActivityInstance hi : list) {
System.out.println(hi.getActivityId());
}
HistoricTaskInstanceQuery query = pe.getHistoryService()
.createHistoricTaskInstanceQuery();
List<HistoricTaskInstance> list = query.list();
for (HistoricTaskInstance hi : list) {
System.out.println(hi.getAssignee());
}
流程变量
设置流程变量
String processDefinitionKey = "variable";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("key1", "value1");
variables.put("key2", 200);
ProcessInstance pi = pe.getRuntimeService().startProcessInstanceByKey(
processDefinitionKey, variables);
System.out.println(pi.getId());
String taskId = "1206";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("user", new User(1,"小王"));
pe.getTaskService().complete(taskId, variables);
String executionId = "601";//流程实例id
String variableName = "key3";
Object value = "value3";
pe.getRuntimeService().setVariable(executionId , variableName , value);
String taskId = "704";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("key4", 400);
variables.put("k5", "v5");
pe.getTaskService().setVariables(taskId , variables);
获取流程变量
String executionId = "1201";
Map<String, Object> variables = pe.getRuntimeService().getVariables(executionId);
Set<String> set = variables.keySet();//key2 key1 user
for (String key : set) {
Object value = variables.get(key);
System.out.println(key + " = " + value);
}
String taskId = "1305";
Map<String, Object> variables = pe.getTaskService().getVariables(taskId );
System.out.println(variables);
任务
- 任务分为个人任务、公共任务、接收任务,个人任务由单个人执行,公共任务由多人执行,接收任务是通过程序调用signal方法执行(如:下发通知短信的流程)
- 查询公共任务
TaskQuery query = pe.getTaskService().createTaskQuery();
String candidateUser = "李四";
//根据候选人过滤
query.taskCandidateUser(candidateUser);
List<Task> list = query.list();
for (Task task : list) {
System.out.println(task.getName());
}
String taskId = "1602";
String userId = "王五";
pe.getTaskService().claim(taskId , userId);
String taskId = "1602";
pe.getTaskService().setAssignee(taskId , null);
String executionId = "2101";
pe.getRuntimeService().signal(executionId );
监听器
执行监听器
- 定义一个类实现ExecutionListener接口,重写notify方法,如下
public class MyExecutionListener implements ExecutionListener {
//当监听的事件发送时执行此方法
public void notify(DelegateExecution execution) throws Exception {
System.out.println("自定义的监听器执行了。");
}
}
任务监听器
- 定义一个类实现TaskListener接口,重写notify方法,如下
public class MyTaskListener implements TaskListener{
//监听任务的事件
public void notify(DelegateTask delegateTask) {
String assignee = delegateTask.getAssignee();
String eventName = delegateTask.getEventName();
String name = delegateTask.getName();
String processInstanceId = delegateTask.getProcessInstanceId();
Set<String> variableNames = delegateTask.getVariableNames();
for (String key : variableNames) {
Object value = delegateTask.getVariable(key);
System.out.println(key + " = " + value);
}
System.out.println("一个任务["+name+"]被创建了,由["+assignee+"]负责办理");
}
}
vzfearless
发布了22 篇原创文章 · 获赞 15 · 访问量 1万+
私信
关注