TaskInstanceEntity taskInstanceTemp = getTaskInstanceEntity();
// 获取正在操作的任务命令对象实例
TaskCommandInst taskCommand = getTaskCommandInst();
ProcessInstanceEntity processInstanceImpl = getProcessInstance();
String userId = null;
if (StringUtil.isEmpty(admin)) {
if (StringUtil.isEmpty(agent)) {
userId = Authentication.getAuthenticatedUserId();
} else {
userId = agent;
}
}
List<TaskInstance> endTaskInstances = null;
if (userId == null) {
endTaskInstances = taskService.createTaskQuery().processInstanceId(taskInstanceTemp.getProcessInstanceId()).taskIsEnd().nodeId(recoverNodeId)
.list();
} else {
endTaskInstances = taskService.createTaskQuery().processInstanceId(taskInstanceTemp.getProcessInstanceId()).taskAssignee(userId).taskIsEnd()
.nodeId(recoverNodeId).list();
}
TaskInstance recoverToTask = endTaskInstances.get(0);
String tokenId = recoverToTask.getTokenId();
Token recoverToToken = runtimeService.createTokenQuery().tokenId(tokenId).singleResult();
if (recoverToToken.getEndTime() == null) {
ProcessDefinitionBehavior processDefinition = processInstanceImpl.getProcessDefinition();
UserTaskBehavior userTask = (UserTaskBehavior) processDefinition.getDefinitions().getElement(recoverNodeId);
TokenEntity tokenEntity = processInstanceImpl.getTokenMap().get(tokenId);
tokenEntity.terminationChildTokenWithTask(taskCommand.getTaskCommandType(), taskCommand.getName(), this.taskComment, userId, this.agent, this.admin);
//TokenEntity token = processInstanceImpl.getTokenMap().get(tokenId);
ExecutionContext executionContext = ProcessObjectFactory.FACTORYINSTANCE.createExecutionContext(tokenEntity);
//taskInstanceTemp.setAssigneeWithoutCascade(userId);
taskInstanceTemp.customEnd(taskCommand, taskComment);
tokenEntity.removeTaskInstanceSynchronization(taskCommand.getTaskCommandType(), taskCommand.getName(), this.taskComment, userId, this.agent, this.admin);
if (recoverToTask.getTaskGroup() != null) {
if (taskCommand != null) {
userTask.enter(executionContext);
}
try {
saveProcessInstance(commandContext);
} catch (Exception e) {
throw new FixFlowException("流程实例持久化失败!", e);
}
return null;
} else {
if (taskCommand != null) {
executionContext.setRollBackAssignee(recoverToTask.getAssignee());
userTask.enter(executionContext);
}
try {
saveProcessInstance(commandContext);
} catch (Exception e) {
throw new FixFlowException("流程实例持久化失败!", e);
}
return null;
}
} else {
ProcessDefinitionBehavior processDefinition = processInstanceImpl.getProcessDefinition();
UserTaskBehavior userTask = (UserTaskBehavior) processDefinition.getDefinitions().getElement(recoverNodeId);
TokenEntity tokenEntity = processInstanceImpl.getRootToken();
tokenEntity.terminationChildTokenWithTask(taskCommand.getTaskCommandType(), taskCommand.getName(), this.taskComment, userId, this.agent, this.admin);
//TokenEntity token = processInstanceImpl.getTokenMap().get(tokenId);