activiti节点撤回
最近项目的需求是对已审批的节点进行撤回操作,核心的思路是:
- 校验任务和流程信息
- 处理已经完成审批的节点信息,做删除操作
- 处理下一节点未审批信息,做删除操作
public Boolean processWithdraw(ProcessWithdrawParam processWithdrawParam) {
String taskId = processWithdrawParam.getTaskId();
String userId = processWithdrawParam.getUserId();
HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).taskAssignee(userId).singleResult();
if (null == task) {
throw new ApplicationException("撤回失败,失败原因:未查到任务信息或者你没有权限撤回该任务");
}
//获取流程模型
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
if (null == bpmnModel) {
throw new ApplicationException("撤回失败,失败原因:未查到流程信息!");
}
String processInstanceId = task.getProcessInstanceId();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if (null == processInstance) {
throw new ApplicationException("撤回失败,失败原因:流程已经结束,或者最后节点已经审批过,不支持撤回!");
}
if (processInstance.isSuspended()) {
throw new ApplicationException("撤回失败,失败原因:流程已经被禁用,不支持撤回!");
}
UserTask currentUserTask = (UserTask)bpmnModel.getFlowElement(task.getTaskDefinitionKey());
if(currentUserTask == null){
throw new ApplicationException("撤回失败,失败原因:当前节点不存在,不支持撤回!");
}
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstan