return 2;
}
// 先找到历史任务
HistoricTaskInstanceEntity historicTaskInstanceEntity = Context
.getCommandContext().getHistoricTaskInstanceEntityManager()
.findHistoricTaskInstanceById(historyTaskId);
// 再反向查找历史任务对应的历史节点
HistoricActivityInstanceEntity historicActivityInstanceEntity = getHistoricActivityInstanceEntity(historyTaskId);
logger.info("historic activity instance is : {}",
historicActivityInstanceEntity.getId());
Graph graph = new ActivitiHistoryGraphBuilder(
historicTaskInstanceEntity.getProcessInstanceId()).build();
Node node = graph.findById(historicActivityInstanceEntity.getId());
if (!checkCouldRollback(node)) {
logger.info("cannot rollback {}", taskId);
return 2;
}
if (this.isSameBranch(historicTaskInstanceEntity)) {
// 如果退回的目标节点的executionId与当前task的executionId一样,说明是同一个分支
// 只删除当前分支的task
this.deleteActiveTask();
} else {
// 否则认为是从分支跳回主干
// 删除所有活动中的task
this.deleteActiveTasks(historicTaskInstanceEntity
.getProcessInstanceId());
// 获得期望退回的节点后面的所有节点历史
List<String> historyNodeIds = new ArrayList<String>();
collectNodes(node, historyNodeIds);
this.deleteHistoryActivities(historyNodeIds);
}
// 恢复期望退回的任务和历史
this.processHistoryTask(historicTaskInstanceEntity,
historicActivityInstanceEntity);
logger.info("activiti is rollback {}",
historicTaskInstanceEntity.getName());
return 0;
}