camunda 引擎是否提供 API 来查询流程的所有已完成实例?
问问题
2110 次
1 回答
5
您可以使用以下代码获取进程的所有已完成实例:
package org.camunda.bpm;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import java.util.List;
public class AllFinishedProcessInstances {
public List<HistoricProcessInstance> getAllFinishedProcessInstances(String processDefinitionName) {
ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
HistoryService historyService = processEngine.getHistoryService();;
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinition myProcessDefinition =
repositoryService.createProcessDefinitionQuery()
.processDefinitionName(processDefinitionName)
.latestVersion() // we are only interested in the latest version
.singleResult();
List<HistoricProcessInstance> processInstances =
historyService.createHistoricProcessInstanceQuery()
.processDefinitionId(myProcessDefinition.getId())
.finished() // we only want the finished process instances
.list();
return processInstances;
}
}
于 2014-04-24T13:01:39.873 回答