在camunda中使用java API 完成usertask流程,包含创建任务,设置审核人,审核人审批
时间: 2023-12-09 07:04:27 浏览: 119
流程控制用Java
在 Camunda 中使用 Java API 完成 User Task 流程可以分为以下几个步骤:
1. 获取 ProcessEngine 对象
```
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
```
2. 部署流程定义
```
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("processes/yourProcess.bpmn")
.deploy();
```
3. 启动流程实例
```
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("yourProcess");
```
4. 查询当前任务
```
Task task = taskService.createTaskQuery()
.processInstanceId(processInstance.getId())
.singleResult();
```
5. 设置任务的候选人
```
taskService.addCandidateUser(task.getId(), "user1");
```
6. 审批人审批任务
```
taskService.claim(task.getId(), "user1");
taskService.complete(task.getId());
```
完整的代码示例:
```
// 获取 ProcessEngine 对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 部署流程定义
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("processes/yourProcess.bpmn")
.deploy();
// 启动流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("yourProcess");
// 查询当前任务
Task task = taskService.createTaskQuery()
.processInstanceId(processInstance.getId())
.singleResult();
// 设置任务的候选人
taskService.addCandidateUser(task.getId(), "user1");
// 审批人审批任务
taskService.claim(task.getId(), "user1");
taskService.complete(task.getId());
```
阅读全文