注(version:5.15.1)
1.部署流程(定义流程)
1 InputStream in = new FileInputStream(file); 2 ZipInputStream zipInputStream = new ZipInputStream(in); 3 processEngine.this.getRepositoryService() 4 .createDeployment() 5 .name(processName) 6 .addZipInputStream(zipInputStream) 7 .deploy();
2.启动流程(所定义流程的一个实例)
1 processEngine().getRuntimeService() 2 /**第二个参数是businesskey:业务工单的主键,作为区分,一般流程名+id,当然如果id为uuid则无所谓 */ 3 .startProcessInstanceByKey("leave", "leaveBill", variables);
这样,业务表就与activiti的表关联起来了(一般为了方便,业务表里也会存一个processId)
其内部表之间关联如下
3.查看某人的任务
1 /** 2 * 当前登录人登录系统以后要执行的任务(包含个人任务+组任务) 3 */ 4 public List<Task> getTasksByAssignee(String userId){ 5 List<Task> assigneeTasks = this.getTaskService() 6 .createTaskQuery() 7 .taskAssignee(userId)//参与者,个人任务查询 8 .orderByTaskCreateTime() 9 .desc() 10 .list(); 11 List<Task> candidateTasks = this.getTaskService() 12 .createTaskQuery() 13 .taskCandidateUser(userId)//参与者,组任务查询 14 .orderByTaskCreateTime() 15 .desc() 16 .list(); 17 assigneeTasks.addAll(candidateTasks); 18 return assigneeTasks; 19 }
4.根据task -》 processInstance -》 businessKey -》 业务表
1 /** 2 * 根据taskId查找businessKey 3 */ 4 public String getBusinessKeyByTaskId(String taskId){ 5 Task task = this.processEngine 6 .getTaskService() 7 .createTaskQuery() 8 .taskId(taskId) 9 .singleResult(); 10 ProcessInstance pi = this.getRuntimeService() 11 .createProcessInstanceQuery() 12 .processInstanceId(task.getProcessInstanceId()) 13 .singleResult(); 14 return pi.getBusinessKey(); 15 }