Dynamic Assignment Tasks for Activiti Development Cases

Keywords: Java SQL

Flow chart

The above is a leave flow chart. The following is a description of the process task node:

  • Employees initiate leave process
  • Departmental Manager Approval
  • Consent goes into personnel examination and approval
  • Refusal adjusts the application or closes the process directly
  • Personnel examination and approval will enter the stage of selling holiday
  • Personnel approval rejection adjusts the application or closes the process directly
  • Employee vacation closure process

task allocation

Employees initiate applications

ProcessInstance process = runtimeService.startProcessInstanceByKey("leave",businessKey, variables);
Task task = taskService.createTaskQuery().processInstanceId(process.getId()).active().singleResult();
//At this point, do not delete the role assigned in the flow chart, otherwise it will repeat.
taskService.addCandidateGroup(task.getId(),"Division Manager");

Departmental Manager Approval

Through logic:

Map<String,Object> variables=new HashMap<String,Object>();
variables.put("approve", "true");
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();
//Be sure to claim the task, retrieve the current task, and assign roles.
taskService.claim(taskId, userId);
taskService.complete(taskId, variables);
task = taskService.createTaskQuery().processInstanceId(process.getId()).active().singleResult();
//At this point, do not delete the role assigned in the flow chart, otherwise it will repeat.
taskService.addCandidateGroup(task.getId(),"Personnel matters");

Refusal logic:

Map<String,Object> variables=new HashMap<String,Object>();
variables.put("approve", "false");
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();
//Be sure to claim the task, retrieve the current task, and assign roles.
taskService.claim(taskId, userId);
taskService.complete(taskId, variables);
task = taskService.createTaskQuery().processInstanceId(process.getId()).active().singleResult();
//applyId is the applicant ID
taskService.addCandidateUser(task.getId(),applyId);

Task to do

API query

TaskQuery taskQuery = taskService.createTaskQuery();
List<Task>  list = taskQuery.taskCandidateOrAssigned(userId)

With API, view mapping is needed. Creating User Table View to Realize Association Query in Activiti Development Case

SQL query

-- Multiple users or roles can be used IN 
select  distinct RES.* from ACT_RU_TASK RES 

left join ACT_RU_IDENTITYLINK I on I.TASK_ID_ = RES.ID_ 

WHERE SUSPENSION_STATE_ = '1' 

AND ( RES.ASSIGNEE_ ='99' or (RES.ASSIGNEE_ is null 

AND ( I.USER_ID_  = '99' or I.GROUP_ID_  = 'Division Manager'  ))) 

Posted by fnbcprog on Sun, 06 Oct 2019 00:22:43 -0700