直接简单粗暴上代码
/** 使用代码创建工作流的23张表 */
@Test
public void testCreateTable() {
ProcessEngineConfiguration p = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
p.setJdbcDriver("com.mysql.jdbc.Driver");
p.setJdbcUrl("jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf8");
p.setJdbcUsername("root");
p.setJdbcPassword("");
p.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
// 工作流的核心对象ProcessEngine
ProcessEngine pe = p.buildProcessEngine();
System.out.println("ProcessEngine:" + pe);
}
package com.ljw.activiti;
import java.util.List;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
public class HelloWorlf {
ProcessEngine processEngines = ProcessEngines.getDefaultProcessEngine();
// 部署流程定义
@Test
public void deploymentProcessDefinition() {
Deployment deployment = processEngines.getRepositoryService()// 与流程定义和部署对象相关的sevices
.createDeployment()// 创建一个部署对象
.name("helloworld-activiti-first")// 添加部署名称
.addClasspathResource("diagrams/helloworld.bpmn")// 从classpath的资源中加载,一次只能加载一个文件
.addClasspathResource("diagrams/helloworld.png").deploy();// 完成部署
System.out.println("部署ID:" + deployment.getId());
System.out.println("部署名称" + deployment.getName());
}
// 启动流程实例
@Test
public void deploymentProcessInstance() {
String key = "helloworld";
ProcessInstance pi = processEngines.getRuntimeService()// 与正在执行的流程是咧和执行对象相关的services
.startProcessInstanceByKey(key);// 使用流程定义的key启动流程实例key对呀的helloworld.bnpm文件里的id的属性值
System.out.println("流程实例ID:" + pi.getId());
System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
}
// 查询当前人的个人任务
@Test
public void findMyPersonalTask() {
String assingnee = "王五";
List<Task> list = processEngines.getTaskService()// 与正在执行的任务管理相关的services
.createTaskQuery()// 创建任务查询对象
.taskAssignee(assingnee)// 指定个人任务查询,指定
.list();
if (list != null && list.size() > 0) {
for (Task task : list) {
System.out.println("任务ID:" + task.getId());
System.out.println("任务名称:" + task.getName());
System.out.println("任务的创建时间:" + task.getCreateTime());
System.out.println("任务的办理人:" + task.getAssignee());
System.out.println("流程实例ID:" + task.getProcessInstanceId());
System.out.println("执行对象ID:" + task.getExecutionId());
System.out.println("流程定义ID:" + task.getProcessDefinitionId());
}
}
}
// 完成我的任务
@Test
public void completeMyPersonalTask() {
// 任务ID
String taskId = "7502";
processEngines.getTaskService()// 与正在执行的任务管理相关的services
.complete(taskId);
System.out.println("任务完成,任务ID:" + taskId);
}
}