1 部署流程定义
Ø 部署流程定义(方式一):将设计的流程图发布到数据库中
public void run3() {
// 创建流程部署建造对象
DeploymentBuilder deployment = processEngine.getRepositoryService()
.createDeployment();
// 读取两个流程定义文件(png、pbmn)
deployment.addClasspathResource("qingjia.png");
deployment.addClasspathResource("qingjia.bpmn");
// 部署流程定义,返回值是
Deployment deploy = deployment.deploy();
System.out.println(deploy.getId());
}
Ø 部署流程定义(方式二):加载zip压缩文件
public void run4() throws Exception {
// 创建流程部署对象
DeploymentBuilder deploymentBuilder = processEngine
.getRepositoryService().createDeployment();
// 创建压缩文件输入流
// 类路径下(不常用)
/*
* ZipInputStream zip = new ZipInputStream(this.getClass()
* .getClassLoader().getResourceAsStream("qingjia.zip"));
*/
// 磁盘路径
ZipInputStream zip = new ZipInputStream(new FileInputStream(new File(
"D:/qingjia.zip")));
// 创建流程部署对象
deploymentBuilder.addZipInputStream(zip);
// 设置流程部署名称
deploymentBuilder.name("请假");
Deployment deploy = deploymentBuilder.deploy();
}
2 查询流程部署
public void run5() {
// 获取流程部署查询对象
DeploymentQuery deploymentQuery = processEngine.getRepositoryService()
.createDeploymentQuery();
// 设置查询条件
deploymentQuery.deploymentName("请假");
// 结果进行排序
deploymentQuery.orderByDeploymentId().desc();
// 进行查询
// 分页查询
List<Deployment> listPage = deploymentQuery.listPage(0, 2);
List<Deployment> list = deploymentQuery.list();
for (Deployment deployment : list) {
System.out.println(deployment.getId());
}
}
3 查询流程定义
public void run6() {
// 创建流程定义查询对象
ProcessDefinitionQuery query = processEngine.getRepositoryService()
.createProcessDefinitionQuery();
List<ProcessDefinition> list = query.processDefinitionKey("myProcess")
.list();
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getId());
}
}
4 启动流程实例
public void run12(){
//方式一:根据流程定义ID启动
//定义定义id
String id = "myProcess:3:204";
//获取流程实例对象
//ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(id);
//System.out.println(instance.getId()+" "+instance.getBusinessKey());
//方式二 ,默认最新版本
//定义流程定义key
String key = "myProcess";
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey(key);
System.out.println(pi.getId());
}
5 查询流程实例
public void run13(){
//获取流程实例查询对象
ExecutionQuery query = processEngine.getRuntimeService().createExecutionQuery();
List<Execution> list = query.list();
for (Execution execution : list) {
System.out.println(execution.getId()+":"+execution.getParentId());
}
}
6 查询个人任务
public