【工作流引擎】Activiti的使用03

流程定义查询

  // 获取部署时的信息
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        //根据表 act_re_procdef 表中的key查询部署的流程定义
        List<ProcessDefinition> myEvection = processDefinitionQuery.processDefinitionKey("MyEvection").orderByProcessDefinitionVersion().desc().list();
        for (ProcessDefinition pro :
                myEvection) {
            System.out.println(pro.getId());
            System.out.println(pro.getName());
            System.out.println(pro.getKey());
        }

流程定义删除


    @Test
    public void deleteProcess() {
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();


        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();

        //先获取已经部署的;
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        List<ProcessDefinition> myEvection = processDefinitionQuery.processDefinitionKey("MyEvection").orderByProcessDefinitionVersion().desc().list();
        for (ProcessDefinition pro :
                myEvection) {
            System.out.println(pro.getDeploymentId());//1
        }
        repositoryService.deleteDeployment("1");
    }

当流程没走完的时候,这种方式是不可以的,我们可以用级联删除的方式
repositoryService.deleteDeployment("1",true);

流程资源文件下载


    /**
     * 流程资源文件下载
     */

    @Test
    public void downloadProcessSource() {
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
        //获得流程定义的服务
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        //获得流程定义实例
        ProcessDefinition myEvection = processDefinitionQuery.processDefinitionKey("MyEvection").singleResult();
        //获得流程部署id
        String deploymentId = myEvection.getDeploymentId();
        //获得流程部署资源名称
        String pngName = myEvection.getDiagramResourceName();
        //读取数据---获得一个流
        InputStream pngStream = repositoryService.getResourceAsStream(deploymentId, pngName);
//        获得bpmn资源信息
        String bpmnName = myEvection.getResourceName();
        InputStream bpmnStream = repositoryService.getResourceAsStream(deploymentId, bpmnName);

//将流输出到本地

        File pngFile = new File("d:/evePng.png");
        File bpmnFile = new File("d:/eveBpmn.bpmn");
        try {
            FileOutputStream pngFileStream = new FileOutputStream(pngFile);
            FileOutputStream bpmnFileStream = new FileOutputStream(bpmnFile);

            IOUtils.copy(pngStream, pngFileStream);
            IOUtils.copy(bpmnStream, bpmnFileStream);
            bpmnFileStream.close();
            pngFileStream.close();
            pngStream.close();
            bpmnStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

在这里插入图片描述

历史记录查询

    /**
     * 流程历史信息查看
     */
    @Test
    public void SeeHistory() {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取历史服务service
        HistoryService historyService = processEngine.getHistoryService();
        //创建历史查询实例
        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
        //查询条件
        List<HistoricActivityInstance> list = historicActivityInstanceQuery.processInstanceId("2501").orderByHistoricActivityInstanceStartTime().asc().list();
        for (HistoricActivityInstance his : list
        ) {
            System.out.println(his.getActivityId());
            System.out.println(his.getActivityName());
            System.out.println(his.getAssignee());
        }
    }

demo部分差不多就这些,我们实际运用中要运用activiti表与实际业务表进行关联以满足复杂的业务需求;

【工作流引擎】Activiti的使用03_第1张图片

你可能感兴趣的:(工作流引擎,Java面试系列,activti,java,activiti)