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