}
public Void execute(CommandContext commandContext) {
if (taskId == null) {
throw new FixFlowException("任务编号为空!");
}
TaskInstanceEntity taskInstance = Context.getCommandContext().getTaskManager().findTaskById(taskId);
if (taskInstance == null) {
throw new FixFlowException("无法找到编号为: " + taskId + " 的任务!");
}
if (transferUserId != null) {
if (taskInstance.getAssignee() == null) {
throw new FixFlowException("任务 " + taskId + " 无代理人!");
} else {
String nodeId = taskInstance.getNodeId();
String processDefinitionId = taskInstance.getProcessDefinitionId();
ProcessDefinitionManager processDefinitionManager = commandContext.getProcessDefinitionManager();
ProcessDefinitionBehavior processDefinition = processDefinitionManager.findLatestProcessDefinitionById(processDefinitionId);
UserTaskBehavior userTask = (UserTaskBehavior) processDefinition.getDefinitions().getElement(nodeId);
TaskCommandInst taskCommand = userTask.getTaskCommandsMap().get(userCommandId);
taskInstance.setEndTime(ClockUtil.getCurrentTime());
taskInstance.setCommandId(taskCommand.getId());
taskInstance.setCommandType(StringUtil.getString(taskCommand.getTaskCommandType()));
taskInstance.setCommandMessage(taskCommand.getName());
taskInstance.setTaskComment(taskComment);
Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstance);
taskInstance.setId(GuidUtil.CreateGuid());
taskInstance.setAssignee(transferUserId);
taskInstance.setCreateTime(ClockUtil.getCurrentTime());
taskInstance.setEndTime(null);
taskInstance.setCommandType(null);
taskInstance.setCommandMessage(null);
taskInstance.setTaskComment(null);
Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstance);
}
} else {
throw new FixFlowException("转发人不能为空!");
}
return null;
}