activiti工作流

activiti工作流基础教程,activiti工作流视频教程,activiti工作流 pdf电子书下载,activiti工作流免费视频教程,activiti工作流视频教程下载

Activiti入门程序-查看历史实例信息

2016-03-24| 发布: | 浏览: 1896 |保存PDF

HistoryService:查询历史信息的服务。在一个流程执行完成后,这个对象为我们提供查询历史信息。


历史实例查询包括:
1、历史流程实例查询 HistoricProcessInstanceQuery
HistoricProcessInstanceQuery hpiQuery = service.createHistoricProcessInstanceQuery();
2、查看历史活动实例 HistoricActivityInstanceQuery
HistoricActivityInstanceQuery haiq=service.createHistoricActivityInstanceQuery();
3、查看历史任务实例 HistoricTaskInstanceQuery
HistoricTaskInstanceQuery htiq = service.createHistoricTaskInstanceQuery();
以上历史实例对象可以设置流程定义的key或ID、人员、排序、分页查询等。获取相关历史流程的信息


实例:以下是刚启动了流程执行的结果

查看历史流程实例:

/** 查看历史流程实例 */
@Test
public void queryHistoricProcessInstanceTest() throws Exception {
    HistoryService service = processEngine.getHistoryService();
 
    // 获取历史流程实例的查询对象
    HistoricProcessInstanceQuery hpiQuery = service.createHistoricProcessInstanceQuery();
    // 设置流程定义KEY
    hpiQuery.processDefinitionKey("hello");
    // 分页条件
    //hpiQuery.listPage(firstResult, maxResults);
    // 排序
    hpiQuery.orderByProcessInstanceStartTime().desc();
 
    // 执行查询
    List<HistoricProcessInstance> hpis = hpiQuery.list();
    // 遍历查看结果
    for (HistoricProcessInstance hpi : hpis) {
        System.out.print("pid:" + hpi.getId() + ",");
        System.out.print("pdid:" + hpi.getProcessDefinitionId() + ",");
        System.out.print("startTime:" + hpi.getStartTime() + ",");
        System.out.print("endTime:" + hpi.getEndTime() + ",");
        System.out.print("duration:" + hpi.getDurationInMillis() + ",");
        System.out.println("vars:" + hpi.getProcessVariables());
    }
}

pid:2501,pdid:hello:1:4,startTime:Thu Mar 24 20:43:07 CST 2016,endTime:null,duration:null,vars:{}


查看历史活动实例


/** 查看历史活动实例 */
@Test
public void queryHistoricActivityInstanceTest() throws Exception {
    HistoryService service = processEngine.getHistoryService();
    HistoricActivityInstanceQuery haiq=service.createHistoricActivityInstanceQuery();
    //过滤条件
    haiq.processInstanceId("2501");
    // 分页条件
    //haiq.listPage(firstResult, maxResults);
    //排序
    haiq.orderByHistoricActivityInstanceEndTime().asc();
    List<HistoricActivityInstance> hais = haiq.list();
 
    for (HistoricActivityInstance hai : hais) {
        System.out.print("activitiId:" + hai.getActivityId() + ",");
        System.out.print("name:" + hai.getActivityName() + ",");
        System.out.print("type:" + hai.getActivityType() + ",");
        System.out.print("pid:" + hai.getProcessInstanceId() + ",");
        System.out.print("assignee:" + hai.getAssignee() + ",");
        System.out.print("startTime:" + hai.getStartTime() + ",");
        System.out.print("endTime:" + hai.getEndTime() + ",");
        System.out.println("duration:" + hai.getDurationInMillis());
    }
}

activitiId:usertask1,name:提交申请,type:userTask,pid:2501,assignee:张三,startTime:Thu Mar 24 20:43:07 CST 2016,endTime:null,duration:null
activitiId:startevent1,name:Start,type:startEvent,pid:2501,assignee:null,startTime:Thu Mar 24 20:43:07 CST 2016,endTime:Thu Mar 24 20:43:07 CST 2016,duration:16


查看历史任务实例


/** 查看历史任务实例 */
@Test
public void queryHistoricTaskInstanceTest() throws Exception {
    HistoryService service = processEngine.getHistoryService();
    HistoricTaskInstanceQuery htiq = service.createHistoricTaskInstanceQuery();
    htiq.taskAssignee("张三");
    List<HistoricTaskInstance> tasks = htiq.list();
 
    for (HistoricTaskInstance hti : tasks) {
        System.out.print("pid:" + hti.getProcessInstanceId() + ",");
        System.out.print("assignee:" + hti.getAssignee() + ",");
        System.out.print("startTime:" + hti.getStartTime() + ",");
        System.out.print("endTime:" + hti.getEndTime() + ",");
        System.out.println("duration:" + hti.getDurationInMillis());
    }
}

pid:2501,assignee:张三,startTime:Thu Mar 24 20:43:07 CST 2016,endTime:null,duration:null

示例程序参考于网络


系列教程

大家都在看

热门访问