idea2020.1集成actibmp插件

idea2020.1集成actibpm插件

由于项目需要使用到Activiti工作流框架,而idea2020.1没有直接下载的插件,需要手动安装,故记录下,以后方便安装使用。

1、下载安装插件

版本是2020.1.1
idea2020.1集成actibmp插件_第1张图片

idea插件官网
idea2020.1集成actibmp插件_第2张图片
选择本地安装
idea2020.1集成actibmp插件_第3张图片
找到下载到的本地的jar,然后重启idea即可。
idea2020.1集成actibmp插件_第4张图片
安装完之后
idea2020.1集成actibmp插件_第5张图片

2、编写demo测试

2.1、创建springboot项目

idea2020.1集成actibmp插件_第6张图片

2.2、引入依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.mystery</groupId>
    <artifactId>demo_activiti</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo_activiti</name>
    <description>Demo project for Activiti</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--- Activiti依赖导入 -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring</artifactId>
            <version>5.22.0</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-engine</artifactId>
            <version>5.22.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jackson-core-asl</artifactId>
                    <groupId>org.codehaus.jackson</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-lang3</artifactId>
                    <groupId>org.apache.commons</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-lang3</artifactId>
                    <groupId>org.apache.commons</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--MySQL 驱动包,如果是其他库的话需要换驱动包-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.15</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2.3、创建流程文件

idea2020.1集成actibmp插件_第7张图片
idea2020.1集成actibmp插件_第8张图片
各个流程配置如下:
idea2020.1集成actibmp插件_第9张图片
idea2020.1集成actibmp插件_第10张图片
idea2020.1集成actibmp插件_第11张图片
idea2020.1集成actibmp插件_第12张图片
idea2020.1集成actibmp插件_第13张图片
idea2020.1集成actibmp插件_第14张图片
idea2020.1集成actibmp插件_第15张图片
idea2020.1集成actibmp插件_第16张图片

2.4、复制test.bpmn,并重命名(名字一定要以 bpmn20结尾)

idea2020.1集成actibmp插件_第17张图片
idea2020.1集成actibmp插件_第18张图片

生成png图片
idea2020.1集成actibmp插件_第19张图片
将生成的图片导出到processes目录下
idea2020.1集成actibmp插件_第20张图片

2.5、代码

测试类

package com.mystery.activiti;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LeaveActi {
    /**
     * 会默认按照Resources目录下的activiti.cfg.xml创建流程引擎
     */
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    @Test
    public void test() {
        //读对应的配置文件,初始化
        testCreateProcessEngineByCfgXml();
        //部署
        deployProcess();
        //启动
        startProcess();
        //查看
        queryTask();
        //处理
        handleTask();
    }

    /**
     * 根据配置文件activiti.cfg.xml创建ProcessEngine
     */
    @Test
    public void testCreateProcessEngineByCfgXml() {
        ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        ProcessEngine engine = cfg.buildProcessEngine();
    }

    /**
     * 发布流程
     * RepositoryService
     */
    @Test
    public void deployProcess() {
        RepositoryService repositoryService = processEngine.getRepositoryService();
        DeploymentBuilder builder = repositoryService.createDeployment(); //创建部署对象
        builder.name("请假审批流程"); //流程名称
        builder.addClasspathResource("/processes/test.bpmn"); //加载资源文件    xml发布有问题
        builder.addClasspathResource("/processes/test.png");
        Deployment deploy = builder.deploy();
        System.out.println("流程部署的ID: "+deploy.getId());
    }

    /**
     * 启动流程
     * RuntimeService
     */
    @Test
    public void startProcess() {
        RuntimeService runtimeService = processEngine.getRuntimeService();

        ProcessInstance leaveInstance = runtimeService.startProcessInstanceByKey("myProcess_1");

        System.out.println("流程id: "+leaveInstance.getId());
    }

    /**
     * 查看任务
     * TaskService
     */
    @Test
    public void queryTask() {
        TaskService taskService = processEngine.getTaskService();
        //根据assignee(代理人)查询任务
//        String assignee = "项目经理";
//        String assignee = "组长";
        String assignee = "张三";
        List<Task> tasks = taskService.createTaskQuery().taskAssignee(assignee).list();
        System.out.println("任务数量:"+tasks.size());
        int size = tasks.size();
        for (int i = 0; i < size; i++) {
            Task task = tasks.get(i);

        }
        for (Task task : tasks) {

            System.out.println("taskId:" + task.getId() +
                    ",taskName:" + task.getName() +
                    ",assignee:" + task.getAssignee() +
                    ",createTime:" + task.getCreateTime());
        }
    }

    /**
     * 办理任务
     */
    @Test
    public void handleTask() {
        TaskService taskService = processEngine.getTaskService();

        Map<String, Object> variables = new HashMap<>();
        variables.put("day", 2);  // 写申请流程变量
        variables.put("action","同意"); //审批流程变量  (驳回/同意)

        //根据上一步生成的taskId执行任务
        String taskId = "10005";//5005
        taskService.complete(taskId, variables);
        System.out.println("任务完成");
    }
}

acitiviti.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/activiti_test" />
        <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>

2.6、测试

加载activiti.cfg.xml配置文件并部署流程
idea2020.1集成actibmp插件_第21张图片
启动流程
idea2020.1集成actibmp插件_第22张图片
根据角色查看任务
idea2020.1集成actibmp插件_第23张图片
处理任务
idea2020.1集成actibmp插件_第24张图片

你可能感兴趣的:(idea2020.1集成actibmp插件)