Activiti5 入门学习整理

Wesley13
• 阅读 538

项目结构

Activiti5 入门学习整理

pom.xml 

 <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring</artifactId>
            <version>5.19.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-bpmn-model</artifactId>
            <version>5.19.0.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>

Activiti.cfg.xml --生成所需流程表

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="processEngineConfiguration"
          class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">

        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/act" />
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUsername" value="root" />
        <property name="jdbcPassword" value="root" />

        <property name="databaseSchemaUpdate" value="true" />

    </bean>

</beans>

流程bpmn文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/testm1480857817152" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1480857817152" name="" targetNamespace="http://www.activiti.org/testm1480857817152" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="myProcess_1" isClosed="false" isExecutable="true" name="act1" processType="None">
    <startEvent id="_2" name="StartEvent"/>
    <userTask activiti:assignee="comp" activiti:exclusive="true" id="_3" name="actTask">
      <extensionElements>
        <activiti:executionListener event="start"/>
        <activiti:formProperty/>
      </extensionElements>
    </userTask>
    <endEvent id="_4" name="EndEvent"/>
    <sequenceFlow id="_5" sourceRef="_3" targetRef="_4"/>
    <sequenceFlow id="_6" sourceRef="_2" targetRef="_3"/>
  </process>
  
</definitions>

流程图片

Activiti5 入门学习整理

测试方法

public class actCreateTable {

    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    // 创建流程所需表
    @Test
    public void createTableForAct(){

        // 引擎配置 创建activiti的25张表
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        // 获取流程引擎对象
        ProcessEngine processEngine = configuration.buildProcessEngine();
    }

   // 部署流程
    @Test
    public void deploy(){
        Deployment deployment = processEngine.getRepositoryService()    // 获取部署相关的service
                         .createDeployment()                            // 创建部署
                         .addClasspathResource("diagrams/myActPro.bpmn")// 加载资源文件
                         .name("actTask")
                         .deploy();                                     // 部署文件

        System.out.println("流程的ID:"+deployment.getId());
        System.out.println("流程的Name:"+deployment.getName());
    }

    //开始运行流程
    @Test
    public void runTask(){
        ProcessInstance processInstance = processEngine.getRuntimeService()
                .startProcessInstanceByKey("myProcess_1");
        System.out.println("流程实例ID:"+processInstance.getId());
        System.out.println("流程定义ID:"+processInstance.getProcessDefinitionId());


    }

    // 进行任务流程 走到任务节点
    @Test
    public void finishTask(){
       List<Task> list = processEngine.getTaskService()
            .createTaskQuery()
            .taskAssignee("comp")   // 指定委托人  查看当前委托人的所有流程
            .list();
        for(Task task : list){
            System.out.println("任务ID:"+task.getId());
            System.out.println("任务名称:"+task.getName());
            System.out.println(String.format( "任务创建时间:" +task.getCreateTime(), "yyyy-MM-DD"));
            System.out.println("任务委托人:"+task.getAssignee());
            System.out.println("流程实例ID:"+task.getProcessDefinitionId());
        }
        System.out.println("任务ID:"+list);

    }

    // 走完流程 end
    @Test
    public void tory(){
        processEngine.getTaskService() // 任务相关Service
                .complete("7504"); // 指定要完成的任务ID
    }

}

流程的curd

public class ActCurd {

    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    //通过流程部署id获得流程图片
    @Test
    public void actQueryById() throws IOException {
        InputStream in = processEngine.getRepositoryService()
                // 通过流程ID和流程资源名称获得输入流
            .getResourceAsStream("5001","diagrams/myActPro.myProcess_1.png");
        // 将图片存放在D盘中
        FileUtils.copyInputStreamToFile(in,new File("d://activit.png"));
    }

    // 查询流程定义的集合 -- 查询流程的最高版本
    @Test
    public void actQueryList(){
        List<ProcessDefinition> listPro = processEngine.getRepositoryService()  // 获取service
                .createProcessDefinitionQuery()                                 //创建流程定义查询
                .orderByProcessDefinitionVersion().asc()                        // 通过流程版本的升序来查询
                .list();
        // 定义一个有序的map 相同的key 假如添加map的值 后面的值会覆盖前面相同key的值
        Map<String,ProcessDefinition> map = new LinkedHashMap<String, ProcessDefinition>();
        //遍历集合 根据key来覆盖前面的值 来保证最新的Key覆盖前面的所有老的Key的值
        for (ProcessDefinition pro : listPro){
            map.put(pro.getKey(),pro);
        }
        // 定义一个有序的list 来保证最新的Key覆盖前面的所有老的Key的值
        List<ProcessDefinition> list = new LinkedList<ProcessDefinition>(map.values());
        // 遍历list
        for (ProcessDefinition pro : list){
            System.out.println("ID_:"+pro.getId());
            System.out.println("NAME_:"+pro.getName());
            System.out.println("KEY_:"+pro.getKey());
            System.out.println("VERSION_:"+pro.getVersion());
            System.out.println("===================");
        }
    }
    //流程定义的删除
    @Test
    public void actDelete(){
        List<ProcessDefinition> listPro = processEngine.getRepositoryService()
            .createProcessDefinitionQuery()
            .processDefinitionKey("act2") // 通过key 来进行删除
            .list();

        // 遍历list
        for (ProcessDefinition pro : listPro){
            processEngine.getRepositoryService()
                    // true 设置级联删除,相关表数据全部删除 通过部署id 来删除
                    .deleteDeployment(pro.getDeploymentId(),true);
        }
    }


}
点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
spring使用jetty+jndi配置druid数据源
maven项目pom.xml配置1、配置druid的jar依赖:<dependency<groupIdcom.alibaba</groupId<artifactIddruid</artifac
Wesley13 Wesley13
3年前
redhat 6.5 tomcate 配置
一、上传Tomcat服务器  !(https://static.oschina.net/uploads/space/2016/0929/164003_qBWh_914393.png)  !(https://static.oschina.net/uploads/space/2016/0929/164002_HoE2_
Stella981 Stella981
3年前
H5接入app准入报告
功能标准!(http://static.oschina.net/uploads/space/2016/0725/160658_qiJY_1032182.png)!(http://static.oschina.net/uploads/space/2016/0725/160850_gQgJ_1032182.png)iPhone性能标准!
可莉 可莉
3年前
15道非常经典的Java面试题
试题如下:!(http://static.oschina.net/uploads/space/2016/0729/022902_IBMr_121944.jpg)!(http://static.oschina.net/uploads/space/2016/0729/022923_Exeo_121944.jpg)!(http://static.o
Stella981 Stella981
3年前
AngularJS 学习笔记 (六) 基本概念和用法 之 Service与Provider
1、使用$http服务!(http://static.oschina.net/uploads/space/2016/0623/092916_7mPM_199513.gif)HTML代码:!(http://static.oschina.net/uploads/space/2016/0623/093044_Y
Stella981 Stella981
3年前
Num71 资金债权匹配(撮合)
待匹配资金查询分析:!(http://static.oschina.net/uploads/space/2016/0712/224621_yxKh_2356966.png)待匹配资金查询表结构分析:!(http://static.oschina.net/uploads/space/20
Wesley13 Wesley13
3年前
POI
!(http://static.oschina.net/uploads/space/2016/0120/131416_Dswb_1444646.png)!(http://static.oschina.net/uploads/space/2016/0120/131416_cIpL_1444646.jpg)ApachePOI是Apache(
Stella981 Stella981
3年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Stella981 Stella981
3年前
PHP+jQuery寥寥几行代码轻松实现百度搜索那样的无刷新PJAX的分页列表和导航链接
!(https://static.oschina.net/uploads/space/2016/1208/171419_U00R_561214.png)PHP寥寥几行代码轻松实现百度搜索那样的分页列表和导航链接,某些语言的拥趸哭晕在厕所.<?php$apparray('db_prefix''
Wesley13 Wesley13
3年前
ARP报文详解
格式图示:!(https://static.oschina.net/uploads/space/2016/1117/104712_qAKs_946750.png)真实案例:!(https://static.oschina.net/uploads/space/2016/1118/111953_B4ua_946750.png)!(https: