Activiti delegate and resolve delegate

Activiti delegate and resolve delegate


Original article: reprint please note: original article address

Foreword:

I think the code can be read and understood, so there is no need to read the following, so let's go to the code first:

/**
 * Delegate the specified task
 *
 * @param taskId
 * @param assignee
 */
 public static void delegateTask (String taskId , String assignee) {
     taskService .delegateTask(taskId , assignee) ;
 }  

/**
 * Resolve the delegated task according to the taskId, dynamically pass the value to set the variable
 */
 public static void resolveTask (String taskId , Map<String , Object> variables) {
     //Extract the task according to
     the taskId Task task = taskService .createTaskQuery() .taskId(taskId).singleResult() ;     if (task.getOwner() != null && !task.getOwner().equals( "null" )) {

        DelegationState delegationState = task.getDelegationState();
        if (delegationState.toString().equals("RESOLVED")) {System.out 
            .println ( "This delegated task is already finished" ) ;
         } else if (delegationState.toString().equals( "PENDING" )) {
             //If it is a delegated task, it needs to be processed
 taskService .resolveTask(taskId , variables) ; 
        } else {            
            System.out.println ( "This task is not a delegated task" ) ;
         }
    }
}

/**
 * Resolve the delegated task according to taskId and proceed to the next node, dynamically pass values ​​to set variables
 */
 public static void resolveTask (String taskId , Map<String , Object> variables) {
     //Extract tasks according to taskId
     Task task =taskService.createTaskQuery().taskId(taskId).singleResult();
    if (task.getOwner() != null && !task.getOwner().equals("null")) {
        DelegationState delegationState = task.getDelegationState();
        if (delegationState.toString().equals("RESOLVED")) {System.out 
            .println ( "This delegated task is already finished" ) ;
         } else if (delegationState.toString().equals( "PENDING" )) {
             //If it is a delegated task, it needs to be processed
 taskService .resolveTask(taskId) ;
 taskService .complete(taskId , variables) ; } else {                        
        
            System.out.println ( "This task is not a delegated task" ) ;
         }
    }
}

text:

It's the first time to write a blog, so I don't know how to describe it, so I start writing with simple functions, please forgive me. . .

We often have such a requirement in business scenarios. I need to delegate my task to another person, and at the same time, I need to obtain the information of the delegator and the delegator, and I also need to know whether the task is being delegated or the delegator has already At this point, we need to use the delegation function in Activiti:


This is an ordinary task, we now look at the database :

We take out the data we currently need:


Comparing the id of the task, we see that the first item is the current data we need to observe:

Next start function



Check the information again at this point:


Comparing the data before the commission, we found some changes:

The value of the DELEGATION_ field changes to PENDING, indicating that this task is a delegated task being executed;

The OWNER_ field represents the principal;

ASSIGNEE_ represents the current task handler;

next


Compare with previous database


At this time, the value of the DELEGATION_ field changes to RESOLVED, indicating that this task is a resolved delegated task;

ps: 1. One thing to pay attention to, Activiti is written by Wei Guoren, and Wei Guoren thinks differently from ours. They believe that the delegated task must have the step of solving the delegate. When the delegate is solved, the process is not complete. The next node, but only when the entrusted person has completed the task operation can proceed to the next step, and most of the Chinese-style requirements are to solve the task is to complete the task, if you need to solve this problem, you can execute a completion after calling the solution commission. Task code action



2. If the delegated task is not resolved, it will not be able to proceed to the next node, and an exception will be thrown directly when the task is completed:


So to complete the task to determine whether it is a delegated task.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325653270&siteId=291194637