Activiti工作流启动流程

/**
* 启动流程
*
*/
public class ActivitiTest2 { RepositoryService repositoryService; RuntimeService runtimeService; @Before
public void setUp() throws Exception {
//获取流程引擎,配置文件必须命名为activiti.cfg.xml
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取流程定义
repositoryService = processEngine.getRepositoryService(); runtimeService = processEngine.getRuntimeService();
} /**
* 启动流程
* select * from act_ru_execution;-- 运行时流程执行实例表
* select * from act_hi_procinst;-- 历史流程实例表
* select * from act_ru_task;-- 运行时任务节点表
* select * from act_hi_taskinst;-- 历史任务实例表
* select * from act_hi_actinst;-- 历史节点表
*/
@Test
public void startProcess(){
//根据流程定义的key,如果相同定义有多个,那么启动最高版本那个
//runtimeService.startProcessInstanceByKey("activiti_leave");
//启动其他版本,需要根据流程定义的id来启动
ProcessInstance processInstance = runtimeService.startProcessInstanceById("activiti_leave:2:504");
System.out.println("流程实例ID:" + processInstance.getId());
System.out.println("正在活动的流程节点ID:" + processInstance.getActivityId());
System.out.println("流程定义ID:" + processInstance.getProcessDefinitionId());
} /**
* 查询流程实例
*/
@Test
public void queryProcessInstance() {
//创建流程实例查询对象
ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
List<ProcessInstance> processInstanceList = processInstanceQuery
.processDefinitionKey("activiti_leave")//根据流程定义的key(activiti_leave)来查询
.orderByProcessDefinitionKey()//根据流程定义的key排序
.desc()//倒序排序
.list();
for (ProcessInstance processInstance : processInstanceList) {
System.out.println("流程实例ID:" + processInstance.getId());
System.out.println("正在活动的流程节点ID:" + processInstance.getActivityId());
System.out.println("流程定义ID:" + processInstance.getProcessDefinitionId());
} //processInstanceQuery.singleResult(); //如果能确定查询的结果只有一条,可以使用这个查询单个流程实例。多个结果情况就会报错
} }
05-01 06:13