在Activiti中,审批流程的定义主要涉及以下几个方面的方法:
1.部署流程定义:
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("processes/approval.bpmn") // 添加流程定义文件
.deploy(); // 部署流程定义
2.启动流程实例:
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("approvalProcess"); // 根据流程定义的key启动流程实例
3.查询待办任务:
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.createTaskQuery()
.taskAssignee("user1") // 查询指定用户的待办任务
.list();
4.完成任务:
taskService.complete(taskId); // 完成指定任务
5.查询历史任务:
HistoryService historyService = processEngine.getHistoryService();
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery()
.taskAssignee("user1") // 查询指定用户的历史任务
.list();
6.查询流程实例状态:
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId) // 根据流程实例ID查询流程实例
.singleResult();
boolean isProcessInstanceActive = processInstance != null && !processInstance.isEnded(); // 判断流程实例是否处于活动状态
7.查询历史流程实例:
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery()
.processDefinitionKey("approvalProcess") // 根据流程定义的key查询历史流程实例
.list();
标签:定义,activiti,所用,查询,processInstance,实例,审批,processEngine,流程
From: https://www.cnblogs.com/codeLearn/p/17811988.html