Activiti框架——查询历史任务
在Activiti框架的使用中,当我们走完一套流程之后,怎么查询我们的已经完成的任务呢?下边的方法就来介绍怎么使用。
创建测试类,引入测试用到的配置文件
private final String key = "groupTaskDelegate";//key值
private final int version = 1;//版本号
//Service接口的父类,可以直接获取下边的Service
private ProcessEngine processEngine;
//Activiti的七大Service类
private RepositoryService repositoryService;
private RuntimeService runtimeService;
private HistoryService historyService;
private ManagementService managementService;
private TaskService taskService;
private IdentityService identityService;
private FormService formService;
@Before
public void init() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-activiti.xml");
processEngine = ProcessEngines.getDefaultProcessEngine();
repositoryService = (RepositoryService) context.getBean("repositoryService");
runtimeService = (RuntimeService) context.getBean("runtimeService");
historyService = (HistoryService) context.getBean("historyService");
managementService = (ManagementService) context.getBean("managementService");
identityService = (IdentityService) context.getBean("identityService");
formService = (FormService) context.getBean("formService");
taskService = processEngine.getTaskService();
System.out.println("========== 初始化完成 ==========");
}
查询流程任务
这里有两种查询,根据所需 选择自己适合的方式来处理
这里我们需要注意两个方法的区别
HistoricActivityInstance(所有流程,包含流程启动、结束等)
HistoricTaskInstance(人物执行相关,只有流程处理的节点)
/**查询历史活动
* act_hi_actinst 表中查
* HistoricActivityInstance(所有流程)和 HistoricTaskInstance(人物执行相关)
*/
@Test
public void findHisActivitiList(){
String processInstanceId = "5001";
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processInstanceId).orderByProcessInstanceId().asc()
.list();
if(list != null && list.size()>0){
for(HistoricActivityInstance hai : list){
System.out.println(hai.getId()+""+hai.getActivityName());
}
}
}
/**
* 查询历史任务
* act_hi_taskinst 表中查
*/
@Test
public void findHisTaskList(){
String processInstanceId = "5001";
List<HistoricTaskInstance> list = processEngine.getHistoryService()
.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId).orderByProcessInstanceId().asc()
.list();
if(list!=null && list.size()>0){
System.out.println("ID 流程名字 流程Key");
for(HistoricTaskInstance hti:list){
System.out.println(hti.getId()+" "+hti.getName()+" "+hti.getTaskDefinitionKey());
}
}
}
查询历史流程变量
查询完成的流程中,查询审核意见等一些参数(根据实例ID查询)。
/**
* 查询历史流程变量
* act_hi_varinst 表中查
*/
@Test
public void findHisVariablesList(){
String processInstanceId = "5006";
List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(processInstanceId)
.list();
if(list != null && list.size()>0){
for(HistoricVariableInstance hvi:list){
System.out.println(hvi.getId()+" "+hvi.getVariableName()+" "+hvi.getValue());
}
}
}