启动流程方式
直接启动
ProcessInstance processInstance =
runtimeService.startProcessInstanceByKey(processDefinitionKey);
任意节点启动
/**
* 任意节点
*/
@Test
public void createProcessInstanceByKey(){
String processDefinitionKey = "Process_0ihs6z7";
String activityId = "Task_1ojlhmg";
ProcessInstantiationBuilder instantiationBuilder = runtimeService.createProcessInstanceByKey(processDefinitionKey);
instantiationBuilder.businessKey("gjf")
// .startBeforeActivity(activityId) //节点之前
// .startBeforeActivity(activityId) //节点之后
.startTransition("SequenceFlow_1ojnaaf") //线
.execute();
}
状态
历史记录
- act_ru_execition : 正在执行的信息
- act_hi_procinst : 已经执行完成的历史流程实例信息
- act_hi_actinst : 存放历史所有完成的活动
- act_ru_task : 正在执行的任务信息
- act_hi_taskinst : 已经执行完成的历史任务信息
历史活动信息查询
历史任务查询
发起人设置
@Test
public void start(){
String authenticatedUserId = "gjf";
identityService.setAuthenticatedUserId(authenticatedUserId);
runtimeService.startProcessInstanceById("Process_0ihs6z7:1:3");
}
删除实例
删除单个
删除多个
/**
* 删除
* delete from ACT_RU_TASK where ID_ = ? and REV_ = ?
* delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
* UPDATE ACT_HI_ACTINST SET EXECUTION_ID_ = ?, PROC_DEF_KEY_ = ?, PROC_DEF_ID_ = ?, ACT_ID_ = ?, ACT_NAME_ = ?, ACT_TYPE_ = ?, PARENT_ACT_INST_ID_ = ? , END_TIME_ = ? , DURATION_ = ? , ACT_INST_STATE_ = ? WHERE ID_ = ?
* update ACT_HI_PROCINST set PROC_DEF_ID_ = ?, PROC_DEF_KEY_ = ?, BUSINESS_KEY_ = ?, END_ACT_ID_ = ?, DELETE_REASON_ = ?, SUPER_PROCESS_INSTANCE_ID_ = ?, STATE_ = ? , END_TIME_ = ? , DURATION_ = ? where ID_ = ?
* update ACT_HI_TASKINST set EXECUTION_ID_ = ?, PROC_DEF_KEY_ = ?, PROC_DEF_ID_ = ?, NAME_ = ?, PARENT_TASK_ID_ = ?, DESCRIPTION_ = ?, OWNER_ = ?, ASSIGNEE_ = ?, DELETE_REASON_ = ?, TASK_DEF_KEY_ = ?, PRIORITY_ = ?, DUE_DATE_ = ?, FOLLOW_UP_DATE_ = ?, CASE_INST_ID_ = ? , END_TIME_ = ? , DURATION_ = ? where ID_ = ?
*/
@Test
public void deleteProcessInstance(){
runtimeService.deleteProcessInstance("301","删除测试");
}
@Test
public void deleteProcessInstance1(){
List<String> processInstanceIds = Arrays.asList("401", "501");
runtimeService.deleteProcessInstances(processInstanceIds,"批量删除",true,true);
}
流程实例获取运行的活动节点
/**
* select * from ACT_RU_EXECUTION where PROC_INST_ID_ = ?
*/
@Test
public void getActiveActivityIds() {
String executionId = "101";
List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);
activeActivityIds.stream().forEach(System.out::println);
}
@Test
public void getActivityInstance() {
String processInstanceId = "101";
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstanceId);
System.out.println(activityInstance);
}
源码
流程定义的挂起和激活操作
指定流程定义的挂起
@Test
public void suspendProcessDefinitionById(){
//挂起
// repositoryService.suspendProcessDefinitionById("Process_0ihs6z7:3:603");
//测试 发起流程
//org.camunda.bpm.engine.SuspendedEntityInteractionException:
// ENGINE-03043 Process Definition with id 'Process_0ihs6z7:3:603' is suspended.
// runtimeService.startProcessInstanceById("Process_0ihs6z7:3:603");
//激活
repositoryService.updateProcessDefinitionSuspensionState()
.byProcessDefinitionId("Process_0ihs6z7:3:603")
.activate();
}