package org.jeecg.modules.system.test; import org.flowable.engine.ProcessEngine; import org.flowable.engine.RepositoryService; import org.flowable.engine.RuntimeService; import org.flowable.engine.TaskService; import org.flowable.engine.repository.Deployment; import org.flowable.task.api.Task; import org.jeecg.JeecgSystemApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class) public class FlowableTest { @Resource private RepositoryService repositoryService; @Autowired private ProcessEngine processEngine; /** * 部署流程 */ @Test public void deployFlow(){ Deployment deploy = processEngine.getRepositoryService().createDeployment() .addClasspathResource("flowableresourse/firstflow.bpmn20.xml") // 部署一个流程 .name("第一个流程案例") .deploy(); System.out.println(deploy.getId()); } /** * 启动流程 */ @Test public void startProcess(){ // 发起流程需要通过RuntimeService来实现 RuntimeService runtimeService = processEngine.getRuntimeService(); // act_re_procdef 表中的id String processId = "firstflow:1:9edacd29-0147-11ef-81c4-347df67c5574"; // 根据流程定义Id启动 返回的是当前启动的流程实例 ProcessInstance //ProcessInstance processInstance = runtimeService.startProcessInstanceById(processId); //System.out.println("processInstance.getId() = " + processInstance.getId()); String processKey = "firstflow"; runtimeService.startProcessInstanceById(processId); } /** * 待办任务查询 */ @Test public void findTask(){ // 任务查询这块我们可以通过 TaskService 来实现 TaskService taskService = processEngine.getTaskService(); // 查询的其实就是 act_ru_task 中的记录 List<Task> list = taskService.createTaskQuery() .taskAssignee("lisi") // 根据审批人来查询 .list();// 返回多条记录 for (Task task : list) { System.out.println(task.getId()); } } /** * 完成任务的审批 */ @Test public void completeTask(){ TaskService taskService = processEngine.getTaskService(); // 需要审批的任务 Id String taskId = "03535489-0157-11ef-967f-347df67c5574"; taskService.complete(taskId); // 通过complete方法完成审批 } }
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交