SpringBoot集成Flowable

一、项目结构

 

二、maven配置

<?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.1.9.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.mk</groupId><artifactId>flowable</artifactId><version>1.0-SNAPSHOT</version><name>flowable</name><description>flowable</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.20</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.0</version></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-spring-boot-starter</artifactId><version>6.5.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>1.3.168</version><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

application.yml 

spring:application:name: flowableprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYSdatasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: "jdbc:mysql://localhost:3306/flowable?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false"username: "root"password: "admin"druid:initial-size: 10max-active: 100min-idle: 10max-wait: 60000pool-prepared-statements: truemax-pool-prepared-statement-per-connection-size: 20time-between-eviction-runs-millis: 60000min-evictable-idle-time-millis: 300000validation-query: SELECT 1 FROM DUALtest-while-idle: truetest-on-borrow: falsetest-on-return: falsefilter:stat:log-slow-sql: trueslow-sql-millis: 1000merge-sql: trueenabled: truewall:config:multi-statement-allow: truestat-view-servlet:enabled: trueservlet:multipart:max-file-size: 10MBmax-request-size: 10MBmvc:date-format: yyyy-MM-dd HH:mm:ssserver:port: 8008mybatis:mapper-locations: classpath*:mapper/*.xmltype-aliases-package: com.mk.flowable.entityconfiguration:map-underscore-to-camel-case: trueconfiguration-properties:prefix:blobType: BLOBboolValue: TRUE

 

 

三、常用API

package com.mk.flowable.service;import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.EndEvent;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.identitylink.api.IdentityLinkInfo;
import org.flowable.task.api.Task;
import org.springframework.stereotype.Service;import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;@Service
public class FlowableService {@Resourceprivate TaskService taskService;@Resourceprivate RepositoryService repositoryService;@Resourceprivate RuntimeService runtimeService;@Resourceprivate HistoryService historyService;public ProcessInstance start(String processDefinitionKey, String userId) {Map<String, Object> variables = new HashMap<>();variables.put("userName", userId);variables.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);//允许执行跳过表达式Authentication.setAuthenticatedUserId(userId);ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);Authentication.setAuthenticatedUserId(null);return processInstance;}public ProcessInstance get(String processInstanceId){ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();return processInstance;}public List<Task> listTask(String processInstanceId) {List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().processInstanceId(processInstanceId).list();return tasks;}public Task getTask(String taskId) {Task task = taskService.createTaskQuery().taskId(taskId).singleResult();return task;}public void complete(String taskId, Map<String, Object> variables) {taskService.complete(taskId, variables);}public void move(Task task, String activityName) {runtimeService.createChangeActivityStateBuilder().processInstanceId(task.getProcessInstanceId()).moveActivityIdsToSingleActivityId(Arrays.asList(task.getTaskDefinitionKey()),activityName).changeState();}public List<EndEvent> getEnd(String processDefinitionId) {BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);List<EndEvent> endEvents = bpmnModel.getProcesses().stream().flatMap(v->v.findFlowElementsOfType(EndEvent.class).stream()).collect(Collectors.toList());return endEvents;}public FlowElement getFlowElement(Task task) {BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionId());return flowElement;}public Map<String, Object> getVariables(String taskId) {Map<String, Object> variables = taskService.getVariables(taskId);return variables;}public  List<String> getCandidateUsers(String taskId) {Task task = taskService.createTaskQuery().taskId(taskId).includeIdentityLinks().singleResult();List<? extends IdentityLinkInfo> linkInfos = task.getIdentityLinks();List<String> candidateUsers = linkInfos.stream().filter(v -> "candidate".equals(v.getType())).map(IdentityLinkInfo::getUserId).filter(StringUtils::isNotBlank).collect(Collectors.toList());return candidateUsers;}public List<String> getCandidatGroups(String taskId) {Task task = taskService.createTaskQuery().taskId(taskId).includeIdentityLinks().singleResult();List<? extends IdentityLinkInfo> linkInfos = task.getIdentityLinks();List<String> candidateUsers = linkInfos.stream().filter(v -> "candidate".equals(v.getType())).map(IdentityLinkInfo::getGroupId).filter(StringUtils::isNotBlank).collect(Collectors.toList());return candidateUsers;}}

 

四、事件和委托

结束事件监听

package com.mk.flowable.listener;import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;@Slf4j
public class EndListener implements ExecutionListener {@Overridepublic void notify(DelegateExecution execution) {}
}

任务监听

package com.mk.flowable.listener;import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;public class FirstTaskListener implements TaskListener {@Overridepublic void notify(DelegateTask delegateTask) {}}

自动节点委托

package com.mk.flowable.service;import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;public class AutoExeService implements JavaDelegate {public void execute(DelegateExecution execution) {}
}

 

testFlowable.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"><process id="testFlowable" name="testFlowable" isExecutable="true"><startEvent id="startevent1" name="Start"></startEvent><endEvent id="endevent1" name="End"><extensionElements><activiti:executionListener event="end" class="com.mk.flowable.listener.EndListener"></activiti:executionListener></extensionElements></endEvent><serviceTask id="servicetask1" name="Service Task1" activiti:class="com.mk.flowable.service.AutoExeService"><documentation>{"data":"es"}</documentation></serviceTask><serviceTask id="servicetask2" name="Service Task2" activiti:class="com.mk.flowable.service.AutoExeService"></serviceTask><serviceTask id="servicetask3" name="Service Task3" activiti:class="com.mk.flowable.service.AutoExeService"></serviceTask><sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask0"></sequenceFlow><sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow><sequenceFlow id="flow3" sourceRef="servicetask2" targetRef="servicetask3"></sequenceFlow><sequenceFlow id="flow4" sourceRef="servicetask3" targetRef="endevent1"></sequenceFlow><userTask id="usertask0" name="User Task0" activiti:assignee="${userName}"></userTask><sequenceFlow id="flow5" sourceRef="usertask0" targetRef="servicetask1"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_testFlowable"><bpmndi:BPMNPlane bpmnElement="testFlowable" id="BPMNPlane_testFlowable"><bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"><omgdc:Bounds height="35.0" width="35.0" x="30.0" y="180.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"><omgdc:Bounds height="35.0" width="35.0" x="730.0" y="180.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1"><omgdc:Bounds height="55.0" width="105.0" x="280.0" y="170.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2"><omgdc:Bounds height="55.0" width="105.0" x="430.0" y="170.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3"><omgdc:Bounds height="55.0" width="105.0" x="580.0" y="170.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask0" id="BPMNShape_usertask0"><omgdc:Bounds height="55.0" width="105.0" x="120.0" y="170.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"><omgdi:waypoint x="65.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="120.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"><omgdi:waypoint x="385.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="430.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"><omgdi:waypoint x="535.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="580.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"><omgdi:waypoint x="685.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="730.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"><omgdi:waypoint x="225.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="280.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/322413.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

04-插入操作更新操作删除操作

保存更新删除 目录 插入操作获取插入的最后一个id更新操作删除操作插入操作 映射文件 Customer.xml &#xff1a; 插入数据的标签为 insert&#xff0c;与查询 select 区分开来。 parameterType 是输入参数类型&#xff0c;这里指定为 Customer 对象&#xff0c;即需要传入一…

微软跨平台移动开发工具套件HockeyApp宣布免费

HockeyApp 是一款领先的移动崩溃分析和应用发布服务&#xff0c;可为开发者提供实时崩溃分析报告、用户反馈、测试版分发平台以及测试分析等功能&#xff0c;于 2016 年被微软收购&#xff0c;随后集成在了 Visual Studio 应用中心中&#xff0c;与 Xamarin Insights 一起提供移…

P3914-染色计数【树形dp】

正题 题目链接:https://www.luogu.org/problemnew/show/P3914 题目大意 nnn个点每个点有些可以染的颜色&#xff0c;要求相邻颜色不相同&#xff0c;方案总数。 解题思路 树形dpdpdp&#xff0c;定义fx,if_{x,i}fx,i​表示点xxx的染颜色iii的方案数。然后定义zx∑i1mfxiz_x\s…

ASP.NET Core使用静态文件、目录游览与MIME类型管理

前言今天我们来了解了解ASP.NET Core中的静态文件的处理方式.以前我们寄宿在IIS中的时候,很多静态文件的过滤 和相关的安全措施 都已经帮我们处理好了.ASP.NET Core则不同,因为是跨平台的,解耦了IIS,所以这些工作 我们可以在管道代码中处理.正文在我们的Web程序开发中,肯定要提…

P5283-[十二省联考2019]异或粽子【可持久化Trie,堆】

正题 题目链接:https://www.luogu.org/problemnew/show/P5283 题目大意 给定一个序列&#xff0c;求kkk个不同的的[l..r][l..r][l..r]的区间异或值的和最大。 解题思路 先让aiaixorai−1a_ia_i\ xor\ a_{i-1}ai​ai​ xor ai−1​(异或前缀和)。 然后现在问题变成了求kkk对最…

ES快速入门

转载自 ES快速入门 3 ES快速入门 ES作为一个索引及搜索服务&#xff0c;对外提供丰富的REST接口&#xff0c;快速入门部分的实例使用head插件来测试&#xff0c;目的是对ES的使用方法及流程有个初步的认识。 3.1 创建索引库 ES的索引库是一个逻辑概念&#xff0c;它包括了分…

05-传统开发模式DAO

传统开发模式DAO 目录 定义接口 CustomerDao.java实现接口 CustomerDaoImpl.java测试类在传统开发模式DAO下&#xff0c;我们自己先定义好接口&#xff0c;然后再去定义实现类&#xff0c;在实现类中实现接口的操作。到时候只需要创建一个 dao 对象&#xff0c;即可调用其中的…

AspnetCore 2.0 自动API文档生成组件,支持protobuffer

关于API文档自动生成&#xff0c;用于对APP端的开发帮助文档生成&#xff0c;默认ProtoBuffer传输格式。本项目并不是RESTful风格&#xff0c;是面向功能的API类型。ApiDoc的作用是根据定义好的API接口和注释来自动生成给内部开发者提供的API对接文档。欢迎Star一下&#xff0c…

P5127-子异和【线段树,树链剖分,位运算】

正题 题目链接:https://www.luogu.org/problemnew/show/P5127 题目大意 定义一个序列的子异和为所有自己的异或和的和。 然后有点权的树&#xff0c;要求支持路径异或和路径求子异和。 解题思路 首先树链剖分是肯定的&#xff0c;然后我们考虑用哪个数据结构。 从每个位单独…

06-Mapper动态代理

Mppaer 动态代理 目录 创建 Mapper 工程定义接口的要求测试类Mapper 中参数传递单个参数多个参数param命名参数多个参数封装成 Map多个参数之 POJO参数处理源码分析之前我们一直都使用传统开发模式DAO&#xff0c;即定义接口&#xff0c;然后定义实现类。这个其实是较为繁琐的…

ASP.NET Core MVC中的 [Required]与[BindRequired]

在开发ASP.NET Core MVC应用程序时&#xff0c;需要对控制器中的模型校验数据有效性&#xff0c;元数据注释(Data Annotations)是一个完美的解决方案。元数据注释最典型例子是确保API的调用者提供了某个属性的值&#xff0c;在传统的ASP.NET MVC中使用的是RequiredAttribute特性…

ES集群管理

转载自 ES集群管理 8 集群管理 ES通常以集群方式工作&#xff0c;这样做不仅能够提高 ES的搜索能力还可以处理大数据搜索的能力&#xff0c;同时也增加了系统的容错能力及高可用&#xff0c;ES可以实现PB级数据的搜索。 下图是ES集群结构的示意图&#xff1a; 从上图总结以下…

【Java探索之旅】我与Java的初相识(完):注释,标识符,关键字

&#x1f3a5; 屿小夏 &#xff1a; 个人主页 &#x1f525;个人专栏 &#xff1a; Java入门到精通 &#x1f304; 莫道桑榆晚&#xff0c;为霞尚满天&#xff01; 文章目录 &#x1f4d1;前言一. Java的注释方式二. 标识符三. 关键字四. 全篇总结 &#x1f4d1;前言 在Java编程…

P5290-[十二省联考2019]春节十二响【贪心,堆】

正题 题目链接:https://www.luogu.org/problemnew/show/P5290 题目大意 将一棵树的所有节点分城若干个组。每个组的价格是这个组中价格最大的点&#xff0c;要求这个组中没有任何祖孙关系。 求所有组的权值和最小。(1号为根节点) 解题思路 我们先想10,11,1210,11,1210,11,12…

07-MyBatis 核心配置文件

MyBatis 核心配置文件 目录 properties 定义属性及读取属性文件settings 设置运行时行为typeAliases 类型别名定义单个别名批量定义别名typeHandlers 类型处理器Plugins&#xff08;后续有文章专门介绍这个&#xff09;Environments 运行环境databaseIDProvider 定义数据库厂…

Office 365也是.NET Core应用开发新战场

最近有幸阅读了陈希章花了一年时间为国内开发者贡献的《Office 365 开发入门指南》。 虽然早期接触过SharePoint的开发&#xff0c;2007年之后就再也没有接触SharePoint的开发&#xff0c;这次阅读这本书让我重新认识了Office的系统开发技术&#xff0c;让我意识到现在的Office…

jzoj4802-[GDOI2017模拟9.24]探险计划【费用流,拆点】

正题 题目大意 一个nnn行的不完全矩阵第iii行有mi−1mi-1mi−1个格子&#xff0c;然后每个格子有危险度。 每次可以从(i,j)(i,j)(i,j)走到(i−1,j)(i-1,j)(i−1,j)或(i−1,j−1)(i-1,j-1)(i−1,j−1) 求 m次&#xff0c;每个格子和路不可以重复走的最小危险度。m次&#xff0…

Scala与Java差异(一)之基础语法

一、Scala解释器的使用 &#xff08;1&#xff09;REPL Read&#xff08;取值&#xff09;-> Evaluation&#xff08;求值&#xff09;-> Print&#xff08;打印&#xff09;-> Loop&#xff08;循环&#xff09;。 scala解释器也被称为REPL&#xff0c;会快速编译…

08-输出类型

输出类型 目录 输出简单类型输出 Map 类型key:列名 value:列名对应的值key:自己指定的列 value:自定义对象resultMap输出简单类型 CustomerMapper.java&#xff1a;返回值为简单类型。 public interface CustomerMapper {/*查询总数*/public Integer getAccountCustomer();…

在Ubuntu 16.04环境下安装Docker-CE(附视频教程)

“ 任何的课程都逃不开理论的支持”久等了各位&#xff0c;上一篇说Docker开始的消息已经过去了一周多的时间&#xff0c;今天推送的消息是告诉大家视频可以学习了&#xff01;52ABP .NET CORE QQ群 : 633751348大纲Docker的介绍Ubuntu下安装Docker快速体验Docker利用Docker搭…