Activiti---流程部署

package com.an.processdeploy;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.zip.ZipInputStream;

public class ProcessDeploy {


    ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine();

    @Test
    public void deployOne(){

        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createDeployment().name("请假流程")
                .addClasspathResource("helloworld.bpmn")
                .addClasspathResource("helloworld.png")
                .deploy();
        System.out.println("流程部署成功!");

    }


    @Test
    public void deployTwo(){

        // helloworld.zip不加/  从当前包中找文件
        // helloworld.zip加/     从classpath中找文件
        InputStream inputStream = this.getClass().getResourceAsStream("/helloworld.zip");
        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createDeployment().name("请假流程")
                .addZipInputStream(new ZipInputStream(inputStream))
        .deploy();
        System.out.println("流程部署成功!");

    }


    /**
     * 查询流程定义
     */
    @Test
    public void queryProcessDefinition(){

        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createProcessDefinitionQuery()
        //条件
        .deploymentId("")
        .processDefinitionName("")
        //list
//        .list()
        //count()
//        .count()
        //排序
        .orderByDeploymentId().desc();

    }


    /**
     * 删除流程定义
     */
    @Test
    public void deleteProcessDefinition(){

        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.deleteDeployment("");

    }


    /**
     * 需改流程定义
     *      修改流程图,重新部署;
     *      只要key不变,version会+1
     */
    public void updateProcessDefinition(){

    }


    /**
     * 查询流程图
     */
    @Test
    public void queryProcessPic(){

        RepositoryService repositoryService = processEngine.getRepositoryService();

        //1、
        String processDefinitionId="";
        InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);

        //
        String processDeploymentId="";
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(processDeploymentId).singleResult();
        InputStream inputStream1 = repositoryService.getProcessDiagram(processDefinition.getId());

    }


    /**
     * 查询最新版本流程定义
     */
    @Test
    public void queryLatestProcessDefinition(){

        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createProcessDefinitionQuery()
                .orderByProcessDefinitionVersion().asc().list();

    }


    /**
     * 删除相同流程定义key
     */
    @Test
    public void deleteSameKeyProcessDefinition(){

        String processDefinitionKey="";
        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createProcessDefinitionQuery()
                .processDefinitionKey(processDefinitionKey).list();

    }

    /**
     * 查询流程部署信息
     */
    @Test
    public void queryProcessDeploy(){

        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createDeploymentQuery()
         //条件
        .deploymentId("")
        .deploymentName("")
        .deploymentNameLike("")
        //排序 asc()或desc() 必须和 orderBy...一起用
        .orderByDeploymentId().asc()
        .orderByDeploymentName().desc()
        //list
//        .list()
        //listPage
//        .listPage(1,3)
        //count
//        .count()
        //singleResult
        .singleResult();

    }

}

  

posted on 2020-08-09 22:12  anpeiyong  阅读(295)  评论(0编辑  收藏  举报

导航