The first is that after we have an understanding of the opening of the Activiti process, we will proceed as follows
The most used tasks in the process are user tasks, including who handles it, when it handles it, what is the result of the handling, and handling history, etc.
The following describes the operations related to the handling of user tasks.
User task classification:
Divided into 4 states: not signed/pending, signed/in process, running/in process, completed/completed
First, we need to understand the role of the TaskService service:
1. Query tasks assigned to users or groups
2. Create an independent running task. These tasks are independent of process instances.
3. Manually set the executor of the task, or how these users are associated with the task.
4. Claim and complete a task. Claiming means that a person expects to be the performer of a task, i.e. the user will complete the task. Done means "do what this task requires". Generally speaking, there are many forms of processing.
condition:
Get tasks through TaskService
API brief
Fields inherited from class org.activiti.engine.impl.ServiceImpl
All implemented interfaces: TaskService
TaskService taskService = processEngine.getTaskService();
//Here I define several general variables
//String userId = "Ypp";
//String userGroup = new String["Ypp1","Ypp101"];
1. Not signed / pending
So after the process is started, how can the next manager get the to-do task?
Through the following methods, the to-do data of the designated recipient/handler will be obtained
//Single person to be signed/to be processed
List<Task> tasks = taskService.createTaskQuery().taskCandidateUser(userId).list();
//User group to be signed/to be processed
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup(userGroup).list();
//Perform the sign-in operation, that is, the task will be received and processed
//You can use a loop here, or you can use other methods. The common method is to load a task to-do list on the page first, and sign the task to pass a taskId in the background.
//task.getId () = taskId
taskService.claim(task.getId(), userId);//When the receipt is completed, the Assignee property of the task has a value
//The task list that has been signed, in a sense, I understand it as the real manager
List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).list();
2. Handling
After obtaining the tasks that need to be processed through 1. Unsigned/to be processed
//Call task.getId() = taskId to complete the processing of the task, and the taskService service automatically flows to the next processing node
taskService.complete(task.getId());
//taskService.complete() method provides overloading and provides 3 ways for you to choose
complete(String taskId)
complete(String taskId, Map<String,Object> variables)
complete(String taskId, Map<String,Object> variables, boolean localScope)
If you have a deeper understanding of how to flow, you can view the source code
---------------------------------------------------------------------------
plug it in
The task does not have to be signed first and then processed, it can go directly to pending, not pending
can put
taskService.claim(task.getId(), userId);方法
replace with
setAssignee(String taskId, String userId)
After the above steps, the task is already in the state of being processed
3. Completed/finished
The completion of the task (the complete method has been called) refers to the current to-do task status, not the completion status of the entire process instance.
The data in the process uses the historyService service
//Query the process initiated by the specified user (initiated by the process history user)
//finished completed process
//unfinish process that is still running
List<HistoricActivityInstance> hais = 3 methods below
historyService.createHistoricProcessInstanceQuery().finished().startedBy(name).orderByProcessInstanceStartTime().desc().listPage(firstResult, maxResults);
//Query the process information of the specified user participation (process history user participation)
List hpis = historyService.createHistoricProcessInstanceQuery().involvedUser(name).orderByProcessInstanceStartTime().desc().listPage(firstResult, maxResults);
//Query the task flow path of the specified process (process history task flow path)
historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).orderByHistoricTaskInstanceEndTime().asc().list();
//There are several ways to check whether the process is complete and complete.
for (HistoricActivityInstance hai: hais) {
//If the return of the following method is not empty, it is completed
hai.getEndTime()
}
//View ACT_RU_TASK table
Long long = taskService.createTaskQuery().processInstanceId("processInstanceId").taskId("taskId").count();
//If long is empty, then it is also done
taskService.createTaskQuery() query condition is optional
can be
taskService.createTaskQuery().processInstanceId("processInstanceId")
taskService.createTaskQuery().taskId("taskId")
or other conditions
Summarize:
//The process can be dynamically adjusted and changed for the current manager/group and signer/group during the flow
//Need to perform special processing on the program, add monitoring or other methods
//Get the user group to sign for
TaskService taskService = processEngine.getTaskService();
//Single person to sign
//List<Task> tasks = taskService.createTaskQuery().taskCandidateUser(userId).list();
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup(userGroup).list();
for (Task task : tasks) {
// sign
taskService.claim(task.getId(), userId);
}
// get user to do
tasks = taskService.createTaskQuery().taskAssignee(userId).list();
for (Task task : tasks) {
// handle
taskService.complete(task.getId());
}
//Check the history by the way
HistoryService historyService = processEngine.getHistoryService();
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
The more complex business is still being sorted out, and there are still shortcomings. I hope everyone can make progress together.
The article is written in Notepad++, there are differences in format understanding