springboot集成activity

2021-02-06 23:16

阅读:739

标签:proc   iter   data   etc   port   als   start   方法   fast   

1.第一步添加bpmn文件得插件,不然没法查看和编辑bpmn文件,添加插件的方法各自百度即可,很简单

技术图片

 

 

 2.安装好bpmn插件后开始新建bpmn文件,也就是画流程图

技术图片

 

 

 技术图片

 

 

 一般是在代码中进行指定流程审批人的,我这里只做入门案例

3.添加pom依赖

   这里包含了在线设计流程图的相关依赖,在下一篇会写出来,项目中一般都是在前端在线设计;所以直接放上去也没事

技术图片
技术图片
4.0.0org.springframework.boot
        spring-boot-starter-parent
        2.2.0.RELEASEcom
    springboot_activiti
    0.0.1-SNAPSHOTspringboot_activitiDemo project for Spring Boot2.2.0.RELEASEUTF-8UTF-81.8
        6.0.0
    org.activiti
            activiti-engine
            ${activiti.version}org.activiti
            activiti-spring
            ${activiti.version}org.codehaus.jackson
                    jackson-core-asl
                org.slf4j
                    slf4j-log4j12
                
                    spring-context
                    org.springframework
                    spring-jdbc
                    org.springframework
                    spring-tx
                    org.springframework
                    spring-orm
                    org.springframework
                    spring-beans
                    org.springframework
                    mybatis
                    org.mybatis
                    activation
                    javax.activationorg.activiti
            activiti-spring-boot-starter-basic
            ${activiti.version}org.activiti
            activiti-common-rest
            ${activiti.version}org.activiti
            activiti-modeler
            5.22.0
                    spring-beans
                    org.springframework
                    spring-context
                    org.springframework
                    spring-core
                    org.springframework
                    spring-tx
                    org.springframework
                    spring-web
                    org.springframework
                    spring-security-config
                    org.springframework.security
                    spring-security-core
                    org.springframework.security
                    spring-security-crypto
                    org.springframework.security
                    spring-security-web
                    org.springframework.security
                    spring-webmvc
                    org.springframework
                    activation
                    javax.activation
                    commons-io
                    commons-ioorg.springframework.boot
            spring-boot-autoconfigure
            ${springboot.version}org.springframework.boot
            spring-boot-starter-tomcat
        org.springframework.boot
            spring-boot-starter-test
            testorg.springframework.boot
            spring-boot-starter-thymeleaf
        org.springframework.boot
            spring-boot-starter-web
        commons-io
            commons-io
            2.3com.fasterxml.jackson.core
            jackson-core
            2.10.0org.springframework.boot
            spring-boot-starter-data-jpa
        mysql
            mysql-connector-java
            runtimeorg.junit.jupiter
            junit-jupiter-api
            RELEASEcompileorg.springframework.boot
                spring-boot-maven-plugin
            org.apache.tomcat.maven
                tomcat7-maven-plugin
                8081/activity4000
技术图片

4.yml文件

 这里采用的数据库还是mysql

 这里有个需要注意的地方,springboot2.2中的driver-class-name值变了,不是以前的那个了,不然会报错

技术图片
技术图片
spring:
  datasource:
    url: jdbc:mysql://localhost:3307/t2?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
  activiti:
    # 自动部署验证设置:true-开启(默认)、false-关闭
    check-process-definitions: false
    #自动部署文件路径后缀
#   process-definition-location-prefix: classpath:/processes/
#   process-definition-location-suffixes:
#      - **.bpmn
#      - **.bpmn20.xml
server:
  port: 8082
技术图片

5.配置已经好了,下面开始写代码了,只是初步写了一些新建流程,正常提交流程,直接结束流程,以及查询待办的案例,细节还需要各自自己去调试学习

   controller

技术图片
技术图片
package com.springboot_activiti.controller;

import com.springboot_activiti.service.ActivityConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/activiti")
public class ActivitiController {

    @Autowired
    private ActivityConsumerService activityConsumerService;

    /**
     * 注册流程
     * @return
     */
    @RequestMapping("/createDeployment")
    public Boolean createDeployment(){
        return activityConsumerService.createDeployment();
    }

    /**
     * 启动流程
     * @return
     */
    @RequestMapping("/startActivityDemo")
    public Boolean startActivityDemo(){
        return activityConsumerService.startActivityDemo("test01");
    }

    /**
     * 获取待办
     * @return
     */
    @RequestMapping("/getTaskList")
    public boolean getTaskList(){
        return activityConsumerService.getTaskList();
    }

    /**
     * 提交
     * @param taskId
     * @return
     */
    @RequestMapping("/complete")
    public boolean complete(String taskId){
        return activityConsumerService.complete(taskId);
    }
    /**
     * 根据流程id直接结束流程
     * @paramru
     * @return
     */
    @RequestMapping("/deleteProcessInstance")
    public boolean deleteProcessInstance(String runId){
        return activityConsumerService.deleteProcessInstance(runId);
    }



}
技术图片

 service

技术图片
技术图片
package com.springboot_activiti.service;

public interface ActivityConsumerService {

    boolean createDeployment();
    boolean startActivityDemo(String key);
    boolean getTaskList();
    boolean  complete(String taskId);
    boolean  deleteProcessInstance(String runId);
}
技术图片

实现类

技术图片
技术图片
package com.springboot_activiti.service;


import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("activityService")
public class ActivityConsumerServiceImpl implements ActivityConsumerService {


    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;

    @Autowired
    private RepositoryService repositoryService;

    /**
     * 注册一个流程
     * @return
     */
    @Override
    public boolean createDeployment() {
        DeploymentBuilder builder=repositoryService.createDeployment();
        builder.addClasspathResource("test01.bpmn");
        builder.deploy();
        return true;
    }

    /**
     * 查询待办
     * @return
     */
    public boolean getTaskList(){
        //获取待办的一些信息,这里可以传入需要查询的用户,
        //我这里查询的所有待办
        List tasks = taskService.createTaskQuery().list();
        for (Task t:tasks) {
            System.out.println(t.getCreateTime());
            System.out.println(t.getId());
            System.out.println(t.getName());
            System.out.println(t.getProcessInstanceId());
            System.out.println(t.getTaskDefinitionKey());
            System.out.println(t.getParentTaskId());
        }
        return true;
    }


    /**
     * 根据流程key开启一个流程
     * @param key
     * @return
     */
    @Override
    public boolean startActivityDemo(String key) {
        ProcessInstance test01 = runtimeService.startProcessInstanceByKey(key);
        String id = test01.getId();
        System.out.println("流程id="+id);
        /*  */
    /*    String assignee = "abc";*/
        return true;
    }

    /**
     * 根据任务id提交任务
     * @param taskId
     * @return
     */
    @Override
    public boolean  complete(String taskId){
        taskService.complete(taskId);
        return true;
    }

    /**
     * 根据流程id直接结束流程
     * @param runId
     * @return
     */
   @Override
   public boolean  deleteProcessInstance(String runId){
       runtimeService.deleteProcessInstance(runId,"结束");
       return true;
   }


}
技术图片

启动类,这里存在一个在线视图设计的验证处理,

技术图片
技术图片
package com.springboot_activiti;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan("com")
@SpringBootApplication
@EnableAutoConfiguration(exclude = {
        org.activiti.spring.boot.SecurityAutoConfiguration.class
        })
public class SpringbootActivitiApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootActivitiApplication.class, args);
    }

}
技术图片

所有的代码已经写好了

备注说明:

        项目启动会新建28张表,各自代表的含义自行百度把

        因为我的数据都是直接在流程图bpmn文件里面写好的,实际中肯定是在代码里面指定的

        首先访问注册流程

        启动流程(会返回一个流程id)

       查看待办就可以获取相关的信息了

       正常提交任务,会审批到下一节点(查看待办可以得到任务id)

       直接结束流程(非正常结束,启动流程的id传入即可)

      

请求案例

  查询待办

技术图片

 

 技术图片

 

 启动流程

技术图片

 

 

 技术图片

 

 
 

springboot集成activity

标签:proc   iter   data   etc   port   als   start   方法   fast   

原文地址:https://www.cnblogs.com/3xiaoleilei/p/12780379.html


评论


亲,登录后才可以留言!