예제 #1
0
 /** 这个结束并不会去推动令牌向下。例如用在退回的时候。 */
 public void end(TaskCommand taskCommand, String taskComment) {
   if (this.isSuspended()) {
     throw ExceptionUtil.getException("10303001");
   }
   end();
   setTaskComment(taskComment);
   if (taskCommand != null
       && taskCommand.getTaskCommandType() != null
       && !taskCommand.getTaskCommandType().equals("")) {
     String taskCommandType = taskCommand.getTaskCommandType();
     String taskCommandName = taskCommand.getName();
     // 设置流程自动结束信息 autoEnd
     this.setCommandId(taskCommand.getId());
     this.setCommandType(taskCommandType);
     if (taskCommandName == null) {
       TaskCommandDefinition taskCommandDef =
           Context.getProcessEngineConfiguration().getTaskCommandDefinition(taskCommandType);
       if (taskCommandDef != null) {
         this.setCommandMessage(taskCommandDef.getName());
       }
     } else {
       this.setCommandMessage(taskCommandName);
     }
   } else {
     this.setCommandId(TaskCommandSystemType.AUTOEND);
     this.setCommandType(TaskCommandSystemType.AUTOEND);
     TaskCommandDefinition taskCommandDef =
         Context.getProcessEngineConfiguration()
             .getTaskCommandDefinition(TaskCommandSystemType.AUTOEND);
     if (taskCommandDef != null) {
       this.setCommandMessage(taskCommandDef.getName());
     }
   }
 }
예제 #2
0
  /** 结束任务,并驱动流程向下运转。 指定需要去的节点和指定节点的任务处理者 */
  public void complete(KernelFlowNodeImpl toFlowNode, String assignee) {

    /** 设置任务结束状态 */
    end();
    /** 正常处理任务不能处理已经暂停的任务 */
    if (this.isSuspended) {
      throw ExceptionUtil.getException("10303001");
    }
    /** 获取令牌 */
    if (tokenId != null) {
      TokenEntity token = null;
      token = getToken();
      if (toFlowNode != null) {
        // 如果指定了目标节点,则首先判断本令牌是否走过该节点
        // 如果走过该节点(taskCount != 0)则正常退回
        // 如果未走过该节点,则递归查询父令牌是否经过,如果父令牌走过,则结束父令牌的child,并推动父令牌退回,如果父令牌也未走过,则抛出异常
        String nodeId = toFlowNode.getId();
        TaskQuery taskQuery = new TaskQueryImpl(Context.getCommandContext());
        long taskCount = taskQuery.tokenId(tokenId).nodeId(nodeId).count();
        if (taskCount == 0) {
          token = getParentTokenByNodeId((TokenEntity) token.getParent(), toFlowNode.getId());
          if (token == null) {
            throw ExceptionUtil.getException("10303002");
          }
          token.terminationChildToken();
        }
        token.setToFlowNode(toFlowNode);
      }
      /** 移除令牌上注册任务 */
      token.removeTask(this);
      if (StringUtil.isNotEmpty(assignee)) {
        token.setTaskAssignee(assignee);
      }
      /** 驱动令牌向下 */
      token.signal();
    } else {
      log.warn("任务:" + id + "没有令牌号,仅做结束任务处理,不驱动流程向下。");
    }
  }