• 【工作流引擎】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());
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    流程定义删除

    
        @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");
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    当流程没走完的时候,这种方式是不可以的,我们可以用级联删除的方式
    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();
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    在这里插入图片描述

    历史记录查询

        /**
         * 流程历史信息查看
         */
        @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());
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

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

    在这里插入图片描述

  • 相关阅读:
    ASDIP Foundation简单的图形环境
    UE4 顶点网格动画播放后渲染模糊问题
    pclpy 可视化点云(多窗口可视化、单窗口多点云可视化)
    UART通信
    java数据类型与变量的安全性
    java计算机毕业设计江西婺源旅游文化推广系统源码+mysql数据库+系统+lw文档+部署
    三款经典的轮式/轮足机器人讲解,以及学习EG2133产生A/B/C驱动电机。个人机器人学习和开发路线(推荐)
    【系统分析师之路】第七章 复盘系统设计(面向服务开发方法)
    2024能源动力、机械自动化与航天航空技术国际学术会议(ICEPMAT2024)
    【Scan kit】Sechunter针对统一扫码SDK扫出漏洞该如何解决?
  • 原文地址:https://blog.csdn.net/weixin_54061333/article/details/133765912