Actiti Connection
https://blog.csdn.net/oChangWen/article/details/51910929
import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.activiti.engine.HistoryService; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.IdentityLink; import org.activiti.engine.task.Task; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author zcy * @version 2019/9/21 * Created by zcy on 2019/9/21. */ @RestController @RequestMapping("/study") @Api("study") public class StudyController { @Autowired private RepositoryService repositoryService; @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; @Autowired private HistoryService historyService; private static String processDefindKey= "mySecondProcess"; @ApiOperation("Boot instance") @GetMapping("startProcess") public void startProcess(){ System.out.println("Boot instance"); //Setting the author variable Map paramMap = new HashMap<>(); paramMap.put("submituser","Wang Xiaobao"); runtimeService.startProcessInstanceByKey(processDefindKey,paramMap); } @ApiOperation("Completion of submission tasks") @GetMapping("submitTaskProcess") public void submitTaskProcess(){ System.out.println("Completion of submission tasks"); String taskId = "50028"; Map paramMap = new HashMap(); //Judgment Conditions of Connections paramMap.put("leaveDay",4); //set variable taskService.setVariable(taskId,"manerUsers","Small A,Small B,Small C,Small D"); taskService.complete(taskId,paramMap); } @ApiOperation("Assignment of other personnel") @GetMapping("assignUser") public void assignUser(){ System.out.println("Assignment of other personnel"); String taskId = "50033"; //Delete the designator taskService.deleteCandidateUser(taskId,"Small A"); //Specify other small E processing taskService.addCandidateUser(taskId,"Small E"); //chian becomes a single person, not a group. The previous group is gone. //taskService.claim(taskId, "small K"); } @ApiOperation("Manager approval") @GetMapping("mangerTaskProcess") public void mangerTaskProcess(){ System.out.println("Manager approval"); String taskId = "50004"; taskService.complete(taskId); } }
Designated Processor
https://blog.csdn.net/oChangWen/article/details/52504210
3-1. Personal Tasks - Ways of Assigning Personal Tasks (Direct Assignment of Translators)
1: Configuration of Task Node in Flow Chart
3-2. Personal Task Assignment Mode 2 (Using Process Variables)
@ApiOperation("Boot instance") @GetMapping("startProcess") public void startProcess(){ System.out.println("Boot instance"); Map paramMap = new HashMap<>(); paramMap.put("submituser","Wang Xiaobao"); runtimeService.startProcessInstanceByKey(processDefindKey,paramMap); }
3-3. Personal Task Assignment Mode 3 (Use Class)
Asgin do not configure, set it in listener
@Service("secondListenr") public class SecondListner implements TaskListener{ @Override public void notify(DelegateTask delegateTask) { System.out.println("-----SecondListner--- "+delegateTask.getId()); delegateTask.setAssignee("Wang Er Bao"); } }
The task of checking and assigning persons
List<Task> taskList2 = taskService.createTaskQuery().taskAssignee("Wang Xiaobao").list(); for (Task task : taskList2) { System.out.println("taskname:" + task.getName() + " taskId:" + task.getId() + " assgin:" + task.getAssignee()); }
summary
Personal tasks and three ways of assignment:
1: Write assignee = "Zhang Sanfeng" directly in taskProcess.bpmn“
2: In taskProcess.bpmn, write assignee="#{userID}", and the value of the variable is String.
Use process variables to designate a broker
3. Using the TaskListener interface, to make the class implement the interface, define it in the class:
delegateTask.setAssignee(assignee); //Assignee for assigning personal tasks
3-4. Task Assignment Group 1 (Direct Assignment of Translators)
3-5. Personal Task Assignment Mode 2 (Using Process Variables)
@ApiOperation("Completion of submission tasks") @GetMapping("submitTaskProcess") public void submitTaskProcess(){ System.out.println("Completion of submission tasks"); String taskId = "50028"; Map paramMap = new HashMap(); paramMap.put("leaveDay",4); // Setting Group Personnel Variables taskService.setVariable(taskId,"manerUsers","Small A,Small B,Small C,Small D"); taskService.complete(taskId,paramMap); }
3-6. Personal Task Assignment Mode 3 (Use Class)
@Service("thirdLister") public class TaskListenerImpl implements TaskListener { /**Personnel to assign tasks*/ @Override public void notify(DelegateTask delegateTask) { //Personal or group assignments may also be designated. //Personal Tasks: Query the database through classes, query and obtain the next task's handler, and then specify the task's handler through setAssignee(). //delegateTask.setAssignee("Extinction Shitai"); //Group tasks: delegateTask.addCandidateUser("Guo Jing"); delegateTask.addCandidateUser("Huang Rong"); }
Query tasks for designated group members:
@ApiOperation("Query task:Designated person") @GetMapping("queryTaskByAssgin") public void queryTaskByAssgin() { System.out.println("Query task:Designated person"); //Task Query of Group Personnel List<Task> taskList = taskService.createTaskQuery().taskCandidateUser("Small D").list(); System.out.println("-----------------1"); for (Task task : taskList) { System.out.println("taskname:" + task.getName() + " taskId:" + task.getId() + " assgin:" + task.getAssignee()); } System.out.println("-----------------2"); //Single Person Task Query List<Task> taskList2 = taskService.createTaskQuery().taskAssignee("Small D").list(); for (Task task : taskList2) { System.out.println("taskname:" + task.getName() + " taskId:" + task.getId() + " assgin:" + task.getAssignee()); } }
Task Acquisition Team personnel:
@ApiOperation("Query task:Specify process instances") @GetMapping("queryTask") public void queryTask(){ List<Task> taskList = taskService.createTaskQuery().processInstanceId("50023").list(); for(Task task : taskList){ System.out.println("taskname:"+task.getName()+" taskId:"+task.getId()+" assgin:"+task.getAssignee()); List<IdentityLink> list = taskService .getIdentityLinksForTask(task.getId()); if(list!=null && list.size()>0){ for(IdentityLink identityLink:list){ System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId()); } } } }
Team members for the task of finding history
public void findHistoryPersonTask(){ //Process instance ID String processInstanceId = "6201"; List<HistoricIdentityLink> list = processEngine.getHistoryService()// .getHistoricIdentityLinksForProcessInstance(processInstanceId); if(list!=null && list.size()>0){ for(HistoricIdentityLink identityLink:list){ System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId()); } } }
Tasks assigned to individuals
public void claim(){ // Assigning group tasks to individual tasks / / task ID String taskId = "7204"; // Personal tasks assigned (can be members of group tasks or non-group tasks) String userId = Small D; processEngine.getTaskService()// .claim(taskId, userId); } The query task is taskService.createTaskQuery().taskAssignee("Little D").list(). Previous queries: taskService.createTaskQuery().taskCandidateUser("Little D").list()
Return personal tasks to group tasks. The premise is that it must be a group task before.
public void setAssigee(){ //Task ID String taskId = "6204"; processEngine.getTaskService()// .setAssignee(taskId, null); }
Adding members to group tasks
public void addGroupUser(){ //Task ID String taskId = "6204"; //Membership Manager String userId = "large H"; processEngine.getTaskService()// .addCandidateUser(taskId, userId); }
Delete members from group tasks
public void deleteGroupUser(){ //Task ID String taskId = "6204"; //Membership Manager String userId = "Small B"; processEngine.getTaskService()// .deleteCandidateUser(taskId, userId); }
1: In taskProcess.bpmn, write candidate-users= "Small A, Small B, Small C, Small D"“
2: In taskProcess.bpmn, write candidate-users = "#{userIDs}" and the value of the variable is String.
Use process variables to designate an agent
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("userIDs", "big, small, medium");
3. The TaskListener interface is used to implement the interface by using classes, which are defined in classes:
// Users who add group tasks
delegateTask.addCandidateUser(userId1);
delegateTask.addCandidateUser(userId2);
Group tasks are assigned to individual tasks (claim tasks):
processEngine.getTaskService().claim(taskId, userId);
Personal tasks are assigned to group tasks:
processEngine.getTaskService(). setAssignee(taskId, null);
Add people to group tasks:
processEngine.getTaskService().addCandidateUser(taskId, userId);
Delete personnel to group tasks:
processEngine.getTaskService().deleteCandidateUser(taskId, userId);
Personal and group tasks are stored in the corresponding form of the manager:
act_ru_identitylink table stores tasks, including personal and group tasks, indicating tasks being performed
act_hi_identitylink table holder of tasks, including personal and group tasks, representing historical tasks
The difference is: if the type of personal task TYPE represents participant (participant)
If the type of TYPE is a group task, it denotes candidate and participant.
gateway
https://blog.csdn.net/oChangWen/article/details/52504062
Monitoring, Task Type
There are several types of tasks, I choose user task and service task to introduce.
In general, the user task is selected as the process to set assgin and so on, and listener can also be set. Complete is required to complete the task and execute the next node.
The service task, which does not require complete, is executed. For example, the first one is user task 1 completing complte, followed by service task 2 correcting user task 3. After service task 2 is executed, create user task 3 and wait for user task 3 to execute
service task uses express:
Newly build Service Interfaces and Implementation Classes public interface ResumeService { void storeResume(); } @Service("resumeService") public class ResumeServiceImpl implements ResumeService { @Override public void storeResume() { System.out.println("Tasks have been executed....................................."); } }
listener
https://msd.misuland.com/pd/3255817997595449232
There are three types of listeners: Java Delegate TaskListener ExecutionListener
The listener for User Task is TaskListener
The Java Service Task listener is Java Delegate
The listener for other services is ExecutionListener
The parameter (Delegate Task) in TaskListener is about userTask.
Java Delegate and ExecutionListener parameters (Delegate Execution) are about processes
There are three ways to use listeners: 1.Direct use class The way to do this is to label it as follows activiti:class="org.activiti.examples.bpmn.servicetask.ToUpperCaseFieldInjected" class ToUpperCaseFieldInjected implment TaskListener 2.use expression The way (which has not yet been tested, and will be added later) <activiti:expression>${genderBean.getGenderString(gender)}</activiti:expression> @Service("genderBean") class GenderBean implment TaskListener { public void getGenderString(String gender){ } } 3.use delegateExpression Way activiti:delegateExpression="${someJavaDelegateBean}" @Service("someJavaDelegateBean") class SomeJavaDelegateBeanimplment TaskListener { @Override public void notify(DelegateTask delegateTask) { System.out.println("--FiveListner--notify taskId:"+delegateTask.getId()+" assin:"+delegateTask.getAssignee()); } } //This way is to use beans to find classes. Some Java Delegate Beans are beans. For example, projects are now managed by spring, and @Service ("some Java Delegate bean") can be added directly to the class of the listener. //This way can seamlessly dock with spring and solve the problem that custom service cannot be injected. The first way is to inject a custom service into the service customized; @Autowired
The above implementations are TaskListener s. That's because it's a user task, if it's replaced by Service Task's implementation Java Delegate
In fact, when drawing this picture, there are hints: