activiti+5.21+mysql_springBoot2.1.5集成Activiti7.1.24

一、使用IDEA快速搭建SpringBoot项目

二、设置pom.xml

pom文件配置如下:<?xml version="1.0" encoding="UTF-8"?>

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.1.5.RELEASE

com.example

activiti7

0.0.1-SNAPSHOT

activiti7

Demo project for Spring Boot

UTF-8

UTF-8

1.8

${java.version}

${java.version}

7.1.24

org.activiti.dependencies

activiti-dependencies

${activiti-dependencies.version}

import

pom

org.springframework.boot

spring-boot-starter-web

org.activiti

activiti-spring-boot-starter

mysql

mysql-connector-java

runtime

com.alibaba

druid

1.1.16

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-starter-security

org.springframework.boot

spring-boot-maven-plugin

alfresco

Activiti Releases

https://artifacts.alfresco.com/nexus/content/repositories/activiti-releases/

true

三、设计流程图

52481010ac334f4ca2714fbc06035f77.png

流程图代码<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

3}]]>

四、配置文件spring:

#Activiti property configuration

activiti:

database-schema-update: true

history-level: full

db-history-used: true

datasource:

url: jdbc:mysql://localhost:3306/activiti7?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC&nullCatalogMeansCurrent=true

username: root

password: root

driver-class-name: com.mysql.cj.jdbc.Driver

type: com.alibaba.druid.pool.DruidDataSource

initialization-mode: always

initialSize: 5

minIdle: 5

maxActive: 20

maxWait: 60000

timeBetweenEvictionRunsMillis: 60000

minEvictableIdleTimeMillis: 300000

validationQuery: SELECT 1 FROM DUAL

testWhileIdle: true

testOnBorrow: false

testOnReturn: false

poolPreparedStatements: true

filters: stat,wall,log4j

maxPoolPreparedStatementPerConnectionSize: 20

useGlobalDataSourceStat: true

connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

logging:

level:

com.ascendant: debug

pattern:

console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(-%5p) %clr(${PID:- }){magenta} --- %clr([%15.15t]){faint} %highlight(%-80.80logger{300}){cyan} %clr(:) %m %n%wEx"

五、SpringBootTest测试

部署流程定义@Test

public void prepare() {

Deployment deployment = repositoryService.createDeployment()//创建一个部署对象

.name("请假流程")

.addClasspathResource("processes/myProcess.bpmn")

.addClasspathResource("processes/myProcess.png")

.deploy();

System.out.println("部署ID:"+deployment.getId());

System.out.println("部署名称:"+deployment.getName());

}

启动流程实例分配任务给个人/**启动流程实例分配任务给个人*/

@Test

public void start() {

String userKey="PTM";//脑补一下这个是从前台传过来的数据

String processDefinitionKey ="myProcess";//每一个流程有对应的一个key这个是某一个流程内固定的写在bpmn内的

HashMap variables=new HashMap<>();

variables.put("userKey", userKey);//userKey在上文的流程变量中指定了

variables.put("day", 2);

variables.put("users", "a");

ProcessInstance instance = runtimeService

.startProcessInstanceByKey(processDefinitionKey,variables);

System.out.println("流程实例ID:"+instance.getId());

System.out.println("流程定义ID:"+instance.getProcessDefinitionId());

}

查询当前人的个人任务/**查询当前人的个人任务*/

@Test

public void findTask(){

String assignee = "a";

List list = taskService.createTaskQuery()//创建任务查询对象

.taskAssignee(assignee)//指定个人任务查询

.list();

if(list!=null && list.size()>0){

for(Task task:list){

System.out.println("任务ID:"+task.getId());

System.out.println("任务名称:"+task.getName());

System.out.println("任务的创建时间:"+task.getCreateTime());

System.out.println("任务的办理人:"+task.getAssignee());

System.out.println("流程实例ID:"+task.getProcessInstanceId());

System.out.println("执行对象ID:"+task.getExecutionId());

System.out.println("流程定义ID:"+task.getProcessDefinitionId());

System.out.println("getOwner:"+task.getOwner());

System.out.println("getCategory:"+task.getCategory());

System.out.println("getDescription:"+task.getDescription());

System.out.println("getFormKey:"+task.getFormKey());

Map map = task.getProcessVariables();

for (Map.Entry m : map.entrySet()) {

System.out.println("key:" + m.getKey() + " value:" + m.getValue());

}

for (Map.Entry m : task.getTaskLocalVariables().entrySet()) {

System.out.println("key:" + m.getKey() + " value:" + m.getValue());

}

}

}

}

完成任务@Test

public void completeTask(){

//任务ID

String taskId = "6825fdf2-7e04-11e9-a0c6-408d5ccf513c";

HashMap variables=new HashMap<>();

variables.put("days", 1);//userKey在上文的流程变量中指定了

taskService.complete(taskId,variables);

System.out.println("完成任务:任务ID:"+taskId);

}

查询当前人的组任务/**查询当前人的组任务*/

@Test

public void findTaskGroup(){

String assignee = "a";

List list = taskService.createTaskQuery()//创建任务查询对象

// .taskCandidateUser("ZJ")//指定组任务查询

.taskAssignee(assignee)

.list();

String taskid ="";

String instanceId ="";

if(list!=null && list.size()>0){

for(Task task:list){

System.out.println("任务ID:"+task.getId());

System.out.println("任务名称:"+task.getName());

System.out.println("任务的创建时间:"+task.getCreateTime());

System.out.println("任务的办理人:"+task.getAssignee());

System.out.println("流程实例ID:"+task.getProcessInstanceId());

System.out.println("执行对象ID:"+task.getExecutionId());

System.out.println("流程定义ID:"+task.getProcessDefinitionId());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值