activiti 中HistoricProcessInstance、HistoricActivityInstance、HistoricTaskInstance、HistoricVariableInst

ProcessEngine processEngine=ProcessEngines.getDefaultProcessEngine();

/**
* 查询历史流程实例  HistoricProcessInstance
*/
@Test
public void findHistoryProcessIntance(){
String processInstanceId="1301";
HistoricProcessInstance hpi=processEngine.getHistoryService()      //与历史数据(历史表)相关的Service
                   .createHistoricProcessInstanceQuery()  //创建历史流程实例查询
                   .processInstanceId(processInstanceId)  //使用流程实例ID查询
                   .orderByProcessInstanceStartTime().asc()
                   .singleResult();
System.out.println(hpi.getId()+"    "+hpi.getProcessDefinitionId()+"   "
+ " "+hpi.getStartTime()+"    "+hpi.getEndTime()+"     "+hpi.getDurationInMillis());
System.out.println("---------------- HistoricProcessInstance -------------------");

}

/**
* 查询历史活动 HistoricActivityInstance
*/
@Test
public void findHistoryActiviti(){
String processInstanceId = "1301";
List list = processEngine.getHistoryService()//
.createHistoricActivityInstanceQuery()//创建历史活动实例的查询
.processInstanceId(processInstanceId)//
.orderByHistoricActivityInstanceStartTime().asc()//
.list();
if(list!=null && list.size()>0){
for (HistoricActivityInstance hpi: list) {
System.out.println(hpi.getId()+"   "+hpi.getProcessInstanceId()+"   "+hpi.getActivityType()+"  "+hpi.getStartTime()+"   "+hpi.getEndTime()+"   "+hpi.getDurationInMillis());
System.out.println("------------------- HistoricActivityInstance ----------------------");
}
}
}

/**
* 查询历史任务 HistoricTaskInstance
*/
@Test
public void findHistoryTask(){
String processIntanceId="1301";
List list=processEngine.getHistoryService()
                       .createHistoricTaskInstanceQuery()
                       .processInstanceId(processIntanceId)
//                        .orderByHistoricActivityInstanceStartTime().asc()
                       .list();
if(list!=null && list.size()>0){
for (HistoricTaskInstance hti : list) {
System.out.println(hti.getId()+"    "+hti.getName()+"    "+hti.getProcessInstanceId()+"   "+hti.getStartTime()+"   "+hti.getEndTime()+"   "+hti.getDurationInMillis());
System.out.println("-------------------- HistoricTaskInstance ---------------------------");
}
}
}

/**
* 查询历史流程变量 HistoricVariableInstance
*/
@Test
public void findHistoryProcessVariables(){
String processInstanceId = "1301";
List list=processEngine.getHistoryService()
                           .createHistoricVariableInstanceQuery()
                           .processInstanceId(processInstanceId)
                           .list();
if(list!=null && list.size()>0){
for (HistoricVariableInstance hti : list) {
System.out.println(hti.getId()+" "+hti.getProcessInstanceId()+" "+hti.getVariableName()+" "+
                      hti.getValue()+" "+hti.getVariableTypeName());
System.out.println("------------------------- HistoricVariableInstance ---------------------------");
}
}
}

你可能感兴趣的:(activiti,工作流)