1、流程实例迁移(可以迁移启动的流程)
MigrationPlanBuilder migrationPlan = runtimeService.createMigrationPlan("fromDefinitionId", "toDefinitionId");
runtimeService.newMigration(migrationPlan.build()).processInstanceIds("instanceId").execute();
2、任意节点启动流程
ProcessInstantiationBuilder processInstantiationBuilder = runtimeService.createProcessInstanceByKey(key);
ProcessInstance execute = processInstantiationBuilder.startAfterActivity(activityId).execute();
3、添加审批意见
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
taskService.createComment(taskId, task.getProcessInstanceId(), comment);
4、撤回(驳回)
try {
TaskEntity taskEntity = (TaskEntity) taskService.createTaskQuery().taskId(taskId).singleResult();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(taskEntity.getProcessInstanceId()).singleResult();
String processInstanceId = processInstance.getId();
String taskDefinitionKey = taskEntity.getTaskDefinitionKey();
AtomicReference<String> backTask = new AtomicReference<>("");
List<HistoricTaskInstance> taskInstances = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();
for (HistoricTaskInstance historicTaskInstance : taskInstances) {
String nowTask = historicTaskInstance.getTaskDefinitionKey();
if (taskDefinitionKey.equals(nowTask)) {
break;
}
backTask.set(nowTask);
}
if (StringUtils.isEmpty(backTask.get())) {
R.errorDefinition("错误");
}
runtimeService.createProcessInstanceModification(processInstanceId)
.cancelAllForActivity(taskDefinitionKey)
.setAnnotation("comment")
.startBeforeActivity(backTask.get())
.execute();
} catch (Exception e) {
e.printStackTrace();
}
5、流程撤销
runtimeService.deleteProcessInstance(processId, "流程撤销");