FixFlow项目API使用指南:从基础到实践
2025-06-10 23:13:56作者:彭桢灵Jeremy
一、FixFlow API概述
FixFlow作为一款强大的流程引擎,其API设计遵循了直观易用的原则。整个API体系围绕ProcessEngine核心对象构建,通过获取不同的服务接口来实现各类流程操作。
1.1 核心服务接口
FixFlow提供了七大核心服务接口,每个接口都有明确的职责划分:
- ModelService - 负责流程模型的定义和部署
- RuntimeService - 处理流程实例的运行时操作
- TaskService - 管理任务实例和任务相关操作
- FormService - 处理表单相关功能
- HistoryService - 提供历史数据查询
- IdentityService - 管理用户和组织结构
- ScheduleService - 处理定时任务
这些服务接口的设计借鉴了业界成熟方案,使得有相关经验的开发者能够快速上手。
二、API基础使用
2.1 获取流程引擎实例
// 获取默认流程引擎实例
ProcessEngine processEngine = ProcessEngineManagement.getDefaultProcessEngine();
流程引擎实例是线程安全的单例对象,整个应用只需要一个实例即可。
2.2 获取服务接口
// 获取各种服务接口
ModelService modelService = processEngine.getModelService();
RuntimeService runtimeService = processEngine.getRuntimeService();
TaskService taskService = processEngine.getTaskService();
三、数据库连接管理
FixFlow提供了灵活的数据库连接管理机制,支持外部传入连接和内部创建连接两种方式。
3.1 外部连接传递
// 创建外部内容对象
ExternalContent externalContent = new ExternalContent();
// 设置操作用户
externalContent.setAuthenticatedUserId("user123");
// 设置数据库连接
externalContent.setConnection(connection);
// 应用到流程引擎
processEngine.setExternalContent(externalContent);
3.2 完整的事务控制示例
Connection connection = null;
try {
// 获取数据库配置
DataBase dataBase = processEngine.getProcessEngineConfiguration().getSelectedDatabase();
// 创建连接
Class.forName(dataBase.getDriverClassName());
connection = DriverManager.getConnection(
dataBase.getUrl(),
dataBase.getUsername(),
dataBase.getPassword());
connection.setAutoCommit(false);
// 设置到流程引擎
ExternalContent externalContent = new ExternalContent();
externalContent.setAuthenticatedUserId("user123");
externalContent.setConnection(connection);
processEngine.setExternalContent(externalContent);
// 执行业务和流程操作
// ...
connection.commit();
} catch (Exception e) {
if(connection != null) connection.rollback();
throw e;
} finally {
if(connection != null) {
processEngine.contextClose(true, false);
connection.close();
}
}
四、完整流程操作示例
4.1 流程部署
// 通过ZIP文件部署流程
String deploymentId = modelService.deploymentByZip(
"com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip");
4.2 流程启动
// 创建启动命令
StartProcessInstanceCommand command = new StartProcessInstanceCommand();
command.setProcessDefinitionKey("Process_TaskServiceTest");
command.setBusinessKey("order_123");
command.setStartAuthor("user123");
// 启动流程
ProcessInstance instance = runtimeService.noneStartProcessInstance(command);
4.3 任务处理
// 查询任务
List<TaskInstance> tasks = taskService.createTaskQuery()
.taskAssignee("user123")
.processInstanceId(instanceId)
.taskNotEnd()
.list();
// 完成任务
ExpandTaskCommand completeCommand = new ExpandTaskCommand();
completeCommand.setCommandType("general");
completeCommand.setUserCommandId("HandleCommand_2");
completeCommand.setTaskId(tasks.get(0).getId());
taskService.expandTaskComplete(completeCommand, null);
五、查询API详解
FixFlow提供了强大的查询API,支持各种复杂查询场景。
5.1 基础查询
// 创建查询
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
// 设置条件
query.processDefinitionKey("Process_TaskServiceTest")
.initiatorLike("user123")
.orderByStartTime().desc();
// 执行查询
List<String> instances = query.listPage(1, 5);
5.2 扩展查询
当内置查询不满足需求时,可以使用扩展查询:
// 创建扩展查询
QueryExpandTo expand = new QueryExpandTo();
// 添加扩展字段
expand.setFieldSql("fixflow_def_processdefinition.PROCESS_NAME");
// 添加JOIN语句
expand.setLeftJoinSql("left join fixflow_def_processdefinition on processdefinition_id = fixflow_def_processdefinition.process_id");
// 应用到查询
query.queryExpandTo(expand);
六、测试最佳实践
FixFlow提供了完善的测试支持,建议测试类继承AbstractFixFlowTestCase。
6.1 测试类示例
@Deployment(resources = {"test/process.bpmn"})
public class MyProcessTest extends AbstractFixFlowTestCase {
@Test
public void testProcess() {
// 测试代码
}
}
6.2 测试要点
- 继承
AbstractFixFlowTestCase自动处理引擎初始化和清理 - 使用
@Deployment注解简化流程部署 - 每个测试方法独立运行,互不影响
七、总结
FixFlow API设计兼顾了易用性和灵活性,通过本文的介绍,开发者可以掌握:
- 核心API的使用方法
- 数据库连接管理的最佳实践
- 完整流程的操作示例
- 强大的查询功能
- 高效的测试方法
对于更复杂的使用场景,建议参考官方提供的完整测试用例,它们覆盖了API的绝大多数功能点。
登录后查看全文
热门项目推荐
PaddleOCR-VLPaddleOCR-VL 是一款顶尖且资源高效的文档解析专用模型。其核心组件为 PaddleOCR-VL-0.9B,这是一款精简却功能强大的视觉语言模型(VLM)。该模型融合了 NaViT 风格的动态分辨率视觉编码器与 ERNIE-4.5-0.3B 语言模型,可实现精准的元素识别。Python00- DDeepSeek-OCR暂无简介Python00
openPangu-Ultra-MoE-718B-V1.1昇腾原生的开源盘古 Ultra-MoE-718B-V1.1 语言模型Python00
HunyuanWorld-Mirror混元3D世界重建模型,支持多模态先验注入和多任务统一输出Python00
AI内容魔方AI内容专区,汇集全球AI开源项目,集结模块、可组合的内容,致力于分享、交流。03
Spark-Scilit-X1-13BFLYTEK Spark Scilit-X1-13B is based on the latest generation of iFLYTEK Foundation Model, and has been trained on multiple core tasks derived from scientific literature. As a large language model tailored for academic research scenarios, it has shown excellent performance in Paper Assisted Reading, Academic Translation, English Polishing, and Review Generation, aiming to provide efficient and accurate intelligent assistance for researchers, faculty members, and students.Python00
GOT-OCR-2.0-hf阶跃星辰StepFun推出的GOT-OCR-2.0-hf是一款强大的多语言OCR开源模型,支持从普通文档到复杂场景的文字识别。它能精准处理表格、图表、数学公式、几何图形甚至乐谱等特殊内容,输出结果可通过第三方工具渲染成多种格式。模型支持1024×1024高分辨率输入,具备多页批量处理、动态分块识别和交互式区域选择等创新功能,用户可通过坐标或颜色指定识别区域。基于Apache 2.0协议开源,提供Hugging Face演示和完整代码,适用于学术研究到工业应用的广泛场景,为OCR领域带来突破性解决方案。00- HHowToCook程序员在家做饭方法指南。Programmer's guide about how to cook at home (Chinese only).Dockerfile013
Spark-Chemistry-X1-13B科大讯飞星火化学-X1-13B (iFLYTEK Spark Chemistry-X1-13B) 是一款专为化学领域优化的大语言模型。它由星火-X1 (Spark-X1) 基础模型微调而来,在化学知识问答、分子性质预测、化学名称转换和科学推理方面展现出强大的能力,同时保持了强大的通用语言理解与生成能力。Python00- PpathwayPathway is an open framework for high-throughput and low-latency real-time data processing.Python00
项目优选
收起
deepin linux kernel
C
24
6
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
243
2.4 K
React Native鸿蒙化仓库
JavaScript
216
291
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。
Cangjie
353
1.61 K
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
9
1
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
1.02 K
405
暂无简介
Dart
540
118
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.01 K
591
仓颉编程语言运行时与标准库。
Cangjie
123
99
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
592
117