activiti 模拟流程
流程图如下
- 部署流程
@Test
public void deployTest() {
//创建 部署对象
DeploymentBuilder deployment = repositoryService.createDeployment();
//拿取建模
deployment.addClasspathResource("diagrams/leave_app.bpmn")
.addClasspathResource("diagrams/leave_app.png");
//部署
deployment.deploy();
}
- 启动流程实例
@Test
public void startTest() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(Constant.PROCESS_KEY);
//拿取 流程实例 所在节点id
String activityId = processInstance.getActivityId();
//拿取 流程实例id
String id = processInstance.getId();
System.out.println(id+"-------------"+activityId);
}
- 查看我的个人任务
/** 任务服务类 */
TaskService taskService;
/** 当前用户角色 */
private String assignee = "employee";
@Before
public void setUp() throws Exception {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
taskService = processEngine.getTaskService();
}
@Test
public void queryMyTask() {
TaskQuery taskQuery = taskService.createTaskQuery();
List<Task> tasks = taskQuery.taskAssignee(assignee)//指定当前责任人
.list();//查询
for (Task task : tasks) {
System.out.println(task.getId()+"-------------- "+task.getName());
}
}
- 完成任务,推送下一节点
@Test
public void completeTaskTest() {
Task task = taskService.createTaskQuery()
.taskAssignee(assignee)
.orderByTaskCreateTime()
.desc()
.list().get(0);
System.out.println(task.getId());
taskService.complete(task.getId());
}