# schedule-engine **Repository Path**: galoisx/schedule-engine ## Basic Information - **Project Name**: schedule-engine - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2026-03-20 - **Last Updated**: 2026-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Schedule Engine - API 编排引擎系统 一个基于 Spring Boot 3.x 的 API 接口串并联编排系统,用于将已有的 API 接口通过编排方式建设成面向业务的业务资产。 ## 技术栈 - **框架**: Spring Boot 3.2.4 - **构建工具**: Maven 3.x - **Java 版本**: 17+ - **数据库**: MySQL 8.0+ / PostgreSQL - **配置格式**: JSON - **脚本执行**: Python (外部进程), Groovy (内置引擎) - **文档**: OpenAPI 3.0 (Swagger) ## 核心功能 1. **编排执行**: 解析编排配置,自动执行串并联接口调用 2. **超时控制**: 按接口设定超时时间 3. **容错处理**: 单个接口异常不影响整体流程,结果中标识异常 4. **参数映射**: 支持字符串、常量、日期等数据类型的映射处理 5. **循环节点**: 支持固定次数、集合遍历、条件循环 6. **脚本节点**: 支持 Python(外部进程)、Groovy 脚本 7. **条件分支**: 支持条件配置节点 8. **接口鉴权**: 支持 Bearer Token、API Key、JWT、Basic Auth 9. **调试功能**: Web 可视化调试(单接口 + 工作流) 10. **元数据管理**: 接口用途、业务含义、出入参字段的完整元数据 ## 项目结构 ``` schedule-engine/ ├── interfaces/ # 接口层 │ ├── api/ # REST Controllers │ ├── dto/ # 数据传输对象 │ ├── websocket/ # WebSocket 处理器 │ └── handler/ # 全局异常处理 ├── application/ # 应用层 │ ├── service/ # 应用服务 │ ├── command/ # 命令对象 │ ├── query/ # 查询对象 │ └── event/ # 领域事件 ├── domain/ # 领域层 │ ├── model/ # 领域模型 │ ├── node/ # 节点类型 │ ├── repository/ # 仓储接口 │ ├── service/ # 领域服务 │ └── exception/ # 领域异常 ├── infrastructure/ # 基础设施层 │ ├── persistence/ # JPA 实现 │ ├── http/ # HTTP 客户端 │ ├── script/ # 脚本执行 │ ├── auth/ # 鉴权模块 │ ├── engine/ # 执行引擎 │ ├── mapping/ # 参数映射 │ └── config/ # 配置类 └── test/ # 测试代码 ``` ## 快速开始 ### 前置条件 - JDK 17+ - Maven 3.x - MySQL 8.0+ 或 PostgreSQL 14+ ### 安装 1. 克隆项目 ```bash git clone cd schedule-engine ``` 2. 创建数据库 ```sql CREATE DATABASE schedule_engine CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ``` 3. 修改配置 编辑 `src/main/resources/application.yml`,配置数据库连接信息 4. 构建项目 ```bash mvn clean install ``` 5. 运行应用 ```bash mvn spring-boot:run ``` 6. 访问 Swagger UI ``` http://localhost:8080/swagger-ui.html ``` ## API 使用示例 ### 1. 创建工作流 ```bash POST /api/workflows Content-Type: application/json { "name": "用户订单查询工作流", "version": "1.0.0", "description": "整合用户信息、订单信息、物流信息查询", "inputParameters": [ { "name": "userId", "type": "string", "required": true, "description": "用户 ID" } ], "outputParameters": [ { "name": "orderInfo", "type": "object", "description": "订单信息" } ], "definition": { "workflow": { "nodes": [ { "id": "start", "type": "START", "name": "开始" }, { "id": "node-1", "type": "API", "name": "获取用户信息", "config": { "method": "GET", "url": "http://api.example.com/users/${input.userId}", "timeout": 3000, "auth": { "type": "BEARER_TOKEN", "token": "your-token" } }, "inputMapping": { "userId": "${input.userId}" } }, { "id": "end", "type": "END", "name": "结束" } ], "edges": [ {"from": "start", "to": "node-1"}, {"from": "node-1", "to": "end"} ] } } } ``` ### 2. 执行工作流 ```bash POST /api/executions/{workflowId} Content-Type: application/json { "input": { "userId": "user-123" } } ``` ### 3. 调试节点 ```bash POST /api/debug/node Content-Type: application/json { "nodeType": "API", "nodeConfig": { "method": "GET", "url": "http://api.example.com/users/123" }, "input": { "userId": "123" } } ``` ### 4. 测试参数映射 ```bash POST /api/debug/mapping Content-Type: application/json { "expression": "${input.name} + ' is ' + ${input.age} + ' years old'", "context": { "name": "John", "age": 25 } } ``` ## 节点类型 | 节点类型 | 描述 | |---------|------| | START | 开始节点 | | END | 结束节点 | | API | API 调用节点 | | PARALLEL | 并行节点 | | CONDITION | 条件分支节点 | | LOOP | 循环节点 | | SCRIPT | 脚本节点 (Groovy/Python) | ## 参数映射语法 | 类型 | 语法 | 示例 | |-----|------|------| | 常量 | 直接值 | `42`, `"hello"`, `true` | | 变量引用 | `${variable}` | `${input.userId}` | | 表达式 | SpEL | `${input.price} * 2` | | JSON Path | `${$.path}` | `${$.data[*].name}` | | 字符串模板 | 混合 | `Hello, ${input.name}!` | | 函数 | `${func()}` | `${concat(a, b)}` | | 日期 | `${now()}` | `${format(now(), 'yyyy-MM-dd')}` | ## 内置函数 ### 字符串函数 - `concat(a, b, ...)` - 连接字符串 - `substring(str, start, end)` - 截取字符串 - `upper(str)` - 转大写 - `lower(str)` - 转小写 - `trim(str)` - 去除空白 - `length(str)` - 获取长度 - `split(str, delimiter)` - 分割字符串 - `join(array, delimiter)` - 连接数组 ### 集合函数 - `sum(array)` - 求和 - `avg(array)` - 求平均 - `size(collection)` - 获取大小 ### 日期函数 - `now()` - 当前时间 - `format(date, pattern)` - 格式化日期 - `addDays(date, days)` - 增加天数 - `diffDays(date1, date2)` - 计算天数差 ## 配置说明 ### application.yml 主要配置项 ```yaml workflow-engine: executor: max-parallelism: 50 # 最大并行度 default-timeout: 30s # 默认超时时间 max-loop-iterations: 1000 # 最大循环次数 http-client: connect-timeout: 5s read-timeout: 30s script: python: interpreter: python3 timeout: 60s groovy: sandbox-enabled: true timeout: 30s ``` ## 开发指南 ### 添加新的节点类型 1. 在 `domain/node/` 创建新的节点类 2. 在 `domain/enumeration/NodeType` 添加枚举值 3. 在 `infrastructure/engine/` 创建对应的执行器 4. 在 `NodeExecutorRegistry` 注册执行器 ### 添加新的鉴权方式 1. 实现 `AuthProvider` 接口 2. 在 `AuthProviderRegistry` 注册 ## 测试 ### 运行单元测试 ```bash mvn test ``` ### 运行集成测试 ```bash mvn verify -P integration ``` ## License MIT License