16. Flow 服务
通过 client.flow() 访问。用于查询 PlantPulse 的可视化工作流(Flow)及其内部节点(Flow Node)。这是 V5 新增的服务。
参考:V5 的 Flow 服务为只读。Flow 的创建/修改/执行请通过 UI 或 Flow 引擎专用 API 完成。有关 Flow 引擎的详细工作原理,请参阅流程引擎文档。
16.1 方法一览
| 方法 | 返回类型 | HTTP | 端点 |
|---|---|---|---|
get(flow_id) | FlowResponseV5 或 null | GET | /api/v5/flow/{id} |
list() | List<FlowResponseV5> (含统计) | GET | /api/v5/flow |
listNodes(flow_id) | List<FlowNodeResponseV5> | GET | /api/v5/flow/{id}/node |
16.2 FlowResponseV5 DTO
| 字段 | 类型 | 说明 |
|---|---|---|
flow_id | String | Flow ID (PK) |
flow_name | String | Flow 名称 |
description | String | 说明 |
enabled | boolean | 是否启用 |
is_root | boolean | 是否为根 Flow |
debug_mode | boolean | 调试模式 |
insert_user / insert_date | String | 注册人/时间 |
update_user / update_date | String | 修改人/时间 |
node_count | int | 节点数(统计) |
trigger_count | int | 触发器数(统计) |
error_count | long | 累计错误数(统计) |
16.3 FlowNodeResponseV5 DTO
| 字段 | 类型 | 说明 |
|---|---|---|
flow_node_id | String | 节点 ID (PK) |
flow_id | String | 所属 Flow |
type | String | 节点类型(trigger、function、action 等) |
name | String | 节点名称 |
configuration_json | String | 节点配置 JSON 字符串 |
position_x / position_y | int | 画布位置 |
debug_mode | boolean | 节点级调试 |
16.4 使用示例
Flow 列表(含统计)
import java.util.List;
import plantpulse.api.v5.dto.response.FlowResponseV5;
List<FlowResponseV5> flows = client.flow().list();
for (FlowResponseV5 f : flows) {
System.out.printf("[%s] %s — 노드 %d개, 트리거 %d개, 에러 %d건%n",
f.isEnabled() ? "ON" : "OFF",
f.getFlow_name(),
f.getNode_count(),
f.getTrigger_count(),
f.getError_count());
}
输出示例:
[ON] 생산 카운트 집계 — 노드 8개, 트리거 1개, 에러 0건
[ON] 알람 알림 라우팅 — 노드 12개, 트리거 3개, 에러 2건
[OFF] (실험) ML 예측 — 노드 5개, 트리거 0개, 에러 0건
单个 Flow 查询
FlowResponseV5 flow = client.flow().get("flow_001");
if (flow != null && !flow.isEnabled()) {
System.err.println("Flow가 비활성 상태: " + flow.getFlow_name());
}
Flow 的节点列表
import plantpulse.api.v5.dto.response.FlowNodeResponseV5;
String flowId = "flow_001";
List<FlowNodeResponseV5> nodes = client.flow().listNodes(flowId);
for (FlowNodeResponseV5 n : nodes) {
System.out.printf(" [%s] %s (%s)%n",
n.getType(), n.getName(), n.getFlow_node_id());
}
识别发生错误的 Flow
import java.util.stream.Collectors;
List<FlowResponseV5> errored = client.flow().list().stream()
.filter(f -> f.getError_count() > 0)
.collect(Collectors.toList());
System.out.println("에러 발생 Flow: " + errored.size() + "개");
for (FlowResponseV5 f : errored) {
System.out.printf(" %s: %d건%n", f.getFlow_name(), f.getError_count());
}
16.5 应用场景
场景 — Flow 健康状态仪表板
while (running) {
List<FlowResponseV5> all = client.flow().list();
long total = all.size();
long enabled = all.stream().filter(FlowResponseV5::isEnabled).count();
long errored = all.stream().filter(f -> f.getError_count() > 0).count();
long triggers = all.stream().mapToInt(FlowResponseV5::getTrigger_count).sum();
updateUI(total, enabled, errored, triggers);
Thread.sleep(5_000);
}
后续步骤
- 流程引擎指南 — Flow 工作原理(独立文档)
- 集成示例 — Flow 与 API 联动示例