JeecgBoot工作流集成:Flowable流程引擎实战应用
【免费下载链接】jeecg-boot 项目地址: https://gitcode.com/gh_mirrors/jee/jeecg-boot
本文详细介绍了JeecgBoot企业级低代码平台与Flowable流程引擎的深度集成方案,涵盖了从基础配置到高级应用的完整实现路径。内容包括Flowable依赖配置、数据库优化、安全认证集成、中文字体支持、多数据源配置等核心技术要点,以及在线流程设计器、表单挂接机制、业务流程自动化等实战应用。通过标准化接口设计和分离架构模式,实现了流程引擎与业务表单的松耦合集成,为企业级工作流应用提供了完整的解决方案。
Flowable流程引擎集成配置
JeecgBoot作为一款优秀的企业级低代码开发平台,与Flowable流程引擎的深度集成为企业业务流程管理提供了强大的技术支撑。本文将详细解析JeecgBoot中Flowable流程引擎的完整配置方案,涵盖依赖管理、数据库配置、安全认证、字体优化等核心环节。
依赖配置管理
在JeecgBoot项目中集成Flowable,首先需要在pom.xml文件中添加相应的Maven依赖。根据项目需求和版本兼容性,推荐使用Flowable 6.7.2版本:
<properties>
<flowable.version>6.7.2</flowable.version>
</properties>
<dependencies>
<!-- Flowable核心依赖 -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>${flowable.version}</version>
</dependency>
<!-- 流程设计器REST API -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-rest</artifactId>
<version>${flowable.version}</version>
</dependency>
<!-- 流程设计器配置 -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
<version>${flowable.version}</version>
</dependency>
<!-- 任务管理配置 -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-task-conf</artifactId>
<version>${flowable.version}</version>
</dependency>
<!-- 管理控制台配置 -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-admin-conf</artifactId>
<version>${flowable.version}</version>
</dependency>
<!-- 身份管理配置 -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-idm-conf</artifactId>
<version>${flowable.version}</version>
</dependency>
</dependencies>
数据库配置优化
Flowable引擎需要与数据库进行深度交互,JeecgBoot通过动态数据源配置实现多数据源支持:
# application.yml配置
flowable:
# 异步执行器激活
async-executor-activate: true
# 数据库模式更新策略
database-schema-update: true
# 流程定义文件位置
process-definition-location-prefix: classpath*:/processes/
process-definition-location-suffixes: "**.bpmn20.xml, **.bpmn"
# 通用应用配置
common:
app:
idm-admin:
password: test
user: test
idm-url: http://localhost:8080/flowable-demo
引擎配置类实现
创建FlowableConfig配置类,对流程引擎进行个性化配置,特别是中文字体支持:
package org.jeecg.config;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
@Override
public void configure(SpringProcessEngineConfiguration configuration) {
// 设置中文字体支持
configuration.setActivityFontName("宋体");
configuration.setLabelFontName("宋体");
configuration.setAnnotationFontName("宋体");
// 数据库连接配置(如果使用独立数据源)
configuration.setJdbcUrl("jdbc:mysql://localhost:3306/jeecg_flowable");
configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver");
configuration.setJdbcUsername("root");
configuration.setJdbcPassword("password");
// 其他高级配置
configuration.setAsyncExecutorActivate(true);
configuration.setDatabaseSchemaUpdate("true");
}
}
安全认证配置
由于JeecgBoot使用Shiro进行权限管理,需要配置Flowable的安全策略以集成现有认证体系:
package org.jeecg.config;
import org.flowable.ui.common.security.SecurityConstants;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* Flowable安全配置 - 绕过默认登录验证
*/
@Configuration
public class SecurityConfiguration {
@Configuration(proxyBeanMethods = false)
@Order(SecurityConstants.FORM_LOGIN_SECURITY_ORDER - 1)
public static class FormLoginWebSecurityConfigurerAdapter
extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().disable();
http.csrf().disable()
.authorizeRequests()
.antMatchers("/modeler/**", "/flowable/**")
.permitAll();
}
}
}
用户身份集成
实现自定义认证上下文,将JeecgBoot的用户体系与Flowable集成:
package org.jeecg.modules.oa.flowable;
import org.flowable.common.engine.api.identity.AuthenticationContext;
import org.flowable.ui.common.security.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import java.security.Principal;
/**
* 自定义认证上下文实现
*/
public class MyAuthenticationContext implements AuthenticationContext {
@Override
public String getAuthenticatedUserId() {
return SecurityUtils.getCurrentUserId();
}
@Override
public Principal getPrincipal() {
return null;
}
@Override
public void setPrincipal(Principal principal) {
}
}
/**
* 应用启动监听器 - 设置认证上下文
*/
@Component
public class FlowableStartedListener implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
Authentication.setAuthenticationContext(new MyAuthenticationContext());
}
}
数据库表结构管理
Flowable使用Liquibase进行数据库版本管理,确保表结构的一致性:
@Bean
public Liquibase liquibase(DataSource dataSource) {
log.info("Configuring Liquibase for Flowable");
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(connection);
// 设置Flowable特定的表名前缀
database.setDatabaseChangeLogTableName("ACT_DE_" + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName("ACT_DE_" + database.getDatabaseChangeLogLockTableName());
Liquibase liquibase = new Liquibase(
"META-INF/liquibase/flowable-modeler-app-db-changelog.xml",
new ClassLoaderResourceAccessor(), database);
liquibase.update("flowable");
return liquibase;
} catch (Exception e) {
throw new InternalServerErrorException("Error creating liquibase database", e);
}
}
流程部署配置
配置流程部署的相关参数,支持自动部署和版本管理:
# 流程部署配置
flowable:
deployment:
# 自动部署流程定义
deploy-changed-only: true
# 部署名称
name: JeecgBoot流程部署
# 部署分类
category: BUSINESS_PROCESS
# 租户标识
tenant-id: jeecg_tenant
# 历史数据配置
history:
level: audit
cleanup-enabled: true
cleanup-schedule: 0 0 2 * * ?
# 作业执行器配置
async-executor:
core-pool-size: 10
max-pool-size: 50
queue-size: 100
keep-alive-time: 300
多数据源支持
对于需要独立流程数据库的场景,配置多数据源支持:
@Configuration
public class FlowableDataSourceConfig {
@Bean(name = "flowableDataSource")
@ConfigurationProperties(prefix = "spring.datasource.flowable")
public DataSource flowableDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public PlatformTransactionManager flowableTransactionManager(
@Qualifier("flowableDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
对应的application.yml配置:
spring:
datasource:
# 主数据源
dynamic:
datasource:
master:
url: jdbc:mysql://localhost:3306/jeecg_boot
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
# Flowable独立数据源
flowable:
url: jdbc:mysql://localhost:3306/jeecg_flowable
username: flowable
password: flowable123
driver-class-name: com.mysql.cj.jdbc.Driver
配置验证与测试
完成配置后,可以通过以下方式验证Flowable集成是否成功:
- 数据库表验证:检查是否生成了ACT_开头的流程表
- API端点验证:访问
/flowable-ui
查看流程设计器 - 服务注入验证:注入RepositoryService测试流程部署
- 权限验证:测试用户身份在流程中的正确传递
@SpringBootTest
public class FlowableIntegrationTest {
@Autowired
private RepositoryService repositoryService;
@Test
public void testFlowableIntegration() {
// 验证流程引擎服务是否正常注入
assertNotNull(repositoryService);
// 验证流程部署功能
long processDefinitionCount = repositoryService.createProcessDefinitionQuery().count();
assertTrue(processDefinitionCount >= 0);
}
}
通过以上完整的配置方案,JeecgBoot项目可以成功集成Flowable流程引擎,为企业级业务流程管理提供强大的技术支撑。配置过程中需要注意版本兼容性、数据源隔离、权限集成等关键环节,确保系统的稳定性和安全性。
在线流程设计与表单挂接
JeecgBoot基于Flowable流程引擎提供了强大的在线流程设计能力,通过可视化的流程设计器和灵活的表单挂接机制,实现了业务流程的快速配置和部署。本节将详细介绍JeecgBoot中在线流程设计与表单挂接的实现原理和最佳实践。
流程设计器架构设计
JeecgBoot的流程设计器采用前后端分离架构,基于BPMN 2.0标准规范,提供了完整的流程建模、部署和执行能力。
表单挂接机制实现
JeecgBoot通过统一的表单挂接接口,实现了流程与表单的松耦合设计。表单挂接支持多种模式:
1. 静态表单挂接
静态表单通过流程定义时绑定固定的表单模板,适用于业务流程固定的场景。
// 流程定义表单绑定示例
@RestController
@RequestMapping("/flowable/process")
public class ProcessDesignController {
@PostMapping("/deployWithForm")
public Result<?> deployProcessWithForm(@RequestBody ProcessDeployDTO deployDTO) {
// 流程部署
Deployment deployment = repositoryService.createDeployment()
.addString(deployDTO.getProcessKey() + ".bpmn20.xml", deployDTO.getBpmnXml())
.deploy();
// 表单绑定
FormDefinition formDefinition = new FormDefinition();
formDefinition.setFormKey(deployDTO.getFormKey());
formDefinition.setProcessDefinitionId(deployment.getId());
formService.saveFormDefinition(formDefinition);
return Result.ok("流程部署成功");
}
}
2. 动态表单挂接
动态表单支持运行时根据业务数据动态渲染表单内容,提供了更大的灵活性。
<template>
<div class="process-form-container">
<a-card title="流程表单" :bordered="false">
<dynamic-form
:form-config="formConfig"
:form-data="formData"
@submit="handleFormSubmit"
/>
<div class="form-actions">
<a-button type="primary" @click="submitForm">提交</a-button>
<a-button @click="saveDraft">保存草稿</a-button>
</div>
</a-card>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { getFormConfigByProcess } from '@/api/process'
const route = useRoute()
const formConfig = ref({})
const formData = ref({})
// 根据流程实例加载表单配置
const loadFormConfig = async () => {
const { processInstanceId } = route.query
const res = await getFormConfigByProcess(processInstanceId)
formConfig.value = res.result
}
onMounted(() => {
loadFormConfig()
})
</script>
3. 外部表单挂接
支持挂接外部系统已有的表单,通过API接口进行数据交互。
流程节点表单配置
每个流程节点都可以独立配置表单,支持不同的业务场景需求。
节点类型 | 表单配置方式 | 适用场景 | 配置示例 |
---|---|---|---|
开始节点 | 必须配置表单 | 流程启动数据收集 | 请假申请表单 |
用户任务 | 可选配置表单 | 任务处理数据录入 | 审批意见表单 |
服务任务 | 无表单配置 | 系统自动处理 | 数据同步任务 |
结束节点 | 无表单配置 | 流程结束处理 | 流程归档 |
表单数据流转机制
JeecgBoot通过流程变量机制实现表单数据在流程节点间的传递和共享。
高级表单配置特性
1. 条件表单显示
根据流程变量动态控制表单字段的显示和隐藏。
// 条件表单配置示例
const formConfig = {
fields: [
{
field: 'leaveType',
label: '请假类型',
type: 'select',
options: [
{ label: '事假', value: 'personal' },
{ label: '病假', value: 'sick' },
{ label: '年假', value: 'annual' }
],
rules: [{ required: true, message: '请选择请假类型' }]
},
{
field: 'medicalCertificate',
label: '医疗证明',
type: 'upload',
visible: '${leaveType === "sick"}', // 条件显示
rules: [{ required: true, message: '请上传医疗证明' }]
}
]
}
2. 表单字段级权限
支持字段级别的读写权限控制,满足不同处理环节的数据权限需求。
// 字段权限控制示例
public class FormPermissionService {
public Map<String, Object> applyFieldPermissions(
String processInstanceId,
String taskId,
Map<String, Object> formData) {
// 获取当前任务节点字段权限配置
TaskFormPermission permission = formPermissionService
.getTaskFormPermissions(processInstanceId, taskId);
// 应用字段权限
Map<String, Object> filteredData = new HashMap<>();
for (Map.Entry<String, Object> entry : formData.entrySet()) {
String fieldName = entry.getKey();
if (permission.isFieldWritable(fieldName)) {
filteredData.put(fieldName, entry.getValue());
}
}
return filteredData;
}
}
3. 表单版本管理
支持表单模板的版本控制,确保流程定义与表单版本的兼容性。
最佳实践建议
-
表单设计原则
- 保持表单简洁,避免过多字段
- 合理分组相关字段,提高用户体验
- 使用合适的表单控件类型
-
流程设计建议
- 明确每个节点的业务职责
- 合理设置流程变量,避免数据冗余
- 考虑异常处理流程和回退机制
-
性能优化
- 对大表单采用分步加载机制
【免费下载链接】jeecg-boot 项目地址: https://gitcode.com/gh_mirrors/jee/jeecg-boot
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考