Activiti7工作流引擎:基础篇 Hello World
Posted vbirdbest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti7工作流引擎:基础篇 Hello World相关的知识,希望对你有一定的参考价值。
示例一:负责人固定
Assignee: 表示任务负责人。
public class HelloWorldTest
/**
* 创建数据库表
*/
@Test
public void testCreateDBTable()
ProcessEngines.getDefaultProcessEngine();
/**
* 部署流程:将.bpmn文件保存到数据库中
*/
@Test
public void delopyBpmn()
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
Deployment deploy = processEngine.getRepositoryService()
.createDeployment()
.addClasspathResource("bpmn/helloworld.bpmn")
.name("请假流程")
.deploy();
// DeploymentEntity[id=1, name=请假流程]
System.out.println(deploy);
/**
* 启动流程实例:发起申请请求
*/
@Test
public void startProcessInstance()
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
ProcessInstance processInstance = processEngine.getRuntimeService()
.startProcessInstanceByKey("helloworld");
System.out.println(processInstance.getId());
System.out.println(processInstance.getProcessInstanceId());
System.out.println(processInstance.getProcessDefinitionId());
/**
* 办理(完成)任务:zhangsan审核自己通过,并将审批交给下个流程审核
*/
@Test
public void completeTask()
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
Task task = taskService
.createTaskQuery()
.processDefinitionKey("helloworld")
.taskAssignee("zhangsan")
.singleResult();
taskService.complete(task.getId());
/**
* 办理(完成)任务:项目经理完成审批,并将任务交给下个负责人审批
*/
@Test
public void completeTaskPM()
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
Task task = taskService
.createTaskQuery()
.processDefinitionKey("helloworld")
.taskAssignee("pm")
.singleResult();
taskService.complete(task.getId());
/**
* 办理(完成)任务:人事审批通过,整个流程结束
*/
@Test
public void completeTaskHR()
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
Task task = taskService
.createTaskQuery()
.processDefinitionKey("helloworld")
.taskAssignee("hr")
.singleResult();
taskService.complete(task.getId());
示例二:负责人变量
负责人在实际开发过程中一般都不会写死,申请人写死难道只能这一个人能发起审批吗?所以一般负责人都是是UEL表达式先定义一个变量,在启动实例或者其他时候给这个变量再赋值。
@Test
public void startProcessInstance()
Map<String, Object> variables = new HashMap<>();
variables.put("creator", "zhangsan");
variables.put("pm", "狗经理");
variables.put("hr", "小姐姐");
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
ProcessInstance processInstance = processEngine.getRuntimeService()
.startProcessInstanceByKey("helloworld", variables);
System.out.println(processInstance.getId());
System.out.println(processInstance.getProcessInstanceId());
System.out.println(processInstance.getProcessDefinitionId());
以上是关于Activiti7工作流引擎:基础篇 Hello World的主要内容,如果未能解决你的问题,请参考以下文章