在Activiti6和Activiti7中跳转节点都要自己实现,Flowable增加了这个功能。
串行流程
是指简单的一条线的流程,流程中如果包含会签
、排它网关
也算串行流程。
节点移动有三种方式:
串行流程节点移动有三个API,每个API都可以前进后退结束节点。
// 方式一
ChangeActivityStateBuilder moveActivityIdTo(String currentActivityId, String newActivityId);
// 方式二:只是目标节点是个List而已
ChangeActivityStateBuilder moveSingleActivityIdToActivityIds(String currentActivityId, List<String> newActivityIds);
// 方式三:通过指定执行id
ChangeActivityStateBuilder moveExecutionToActivityId(String executionId, String activityId);
@Test
void delopyProcess() {
Deployment deploy = repositoryService.createDeployment()
.addClasspathResource("processes/myProcess.bpmn20.xml")
.name("串行流程")
.deploy();
System.out.println(deploy.getId());
}
@Test
void startProcess() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
Task task = taskService.createTaskQuery()
.processInstanceId(processInstance.getId())
.singleResult();
taskService.setAssignee(task.getId(), "huihui");
taskService.complete(task.getId());
}
// 前进:group -> hr
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(processInstanceId)
.moveActivityIdTo("group", "hr")
.changeState();
insert into ACT_HI_TASKINST
insert into ACT_HI_ACTINST
// hr节点
insert into ACT_RU_EXECUTION
insert into ACT_RU_ACTINST
// 插入ACT_RU_TASK 人事审批节点
insert into ACT_RU_TASK
// 更新ACT_HI_ACTINST group节点的审批完成时间
update ACT_HI_ACTINST SET REV_ = ?, PROC_DEF_ID_ = ?, END_TIME_ = ?, DURATION_ = ?, DELETE_REASON_ = ? where ID_ = ? and REV_ = ?
// 更新ACT_HI_ACTINST group节点的审批完成时间,注意会更新删除原因字段
update ACT_HI_TASKINST SET REV_ = ?, END_TIME_ = ?, DURATION_ = ?, DELETE_REASON_ = ?, LAST_UPDATED_TIME_ = ? where ID_ = ? and REV_ = ?
update ACT_RU_ACTINST SET REV_ = ?, PROC_DEF_ID_ = ?, END_TIME_ = ?, DURATION_ = ?, DELETE_REASON_ = ? where ID_ = ? and REV_ = ?
update ACT_RU_EXECUTION SET REV_ = ?, IS_ACTIVE_ = ? where ID_ = ? and REV_ = ?
delete from ACT_RU_TASK where EXECUTION_ID_ = ?
delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
在Activiti6和Activiti7中都没有ACT_RU_ACTINST表,两张表结构一样,只是ACT_RU_ACTINST表中的数据会在流程结束时删除。
// 后退: manage <- hr
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(processInstanceId)
.moveSingleActivityIdToActivityIds("hr", Arrays.asList("manage"))
.changeState();
// 狠一点:直接结束流程
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(processInstanceId)
.moveExecutionToActivityId(task.getExecutionId(), "end")
.changeState();