Files
syops/backend/app/services/shipping_notice/openapi_spec.py
T
hugo 5ef8329bd8 refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段
统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
2026-08-15 10:19:10 +08:00

107 lines
4.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
services/shipping_notice/openapi_spec.py
用途:构建发货通知 Tool API 的 OpenAPI 描述,供 Dify 导入和联调用。
依赖:标准 `typing` 类型。
逻辑:由 api/shipping_notice_tools.py 调用本文件生成 JSON/YAML OpenAPI 文档,再暴露给 Dify 或开发工具;
co8 起不再导出 get_batch_status(shipping_batches 已 DROP)。
"""
from __future__ import annotations
from typing import Any
def _str_prop(description: str, *, enum: list[str] | None = None) -> dict[str, Any]:
prop: dict[str, Any] = {"type": "string", "description": description}
if enum:
prop["enum"] = enum
return prop
def _int_prop(description: str) -> dict[str, Any]:
return {"type": "integer", "description": description}
def _post_op(
operation_id: str,
summary: str,
properties: dict[str, Any],
*,
required: list[str] | None = None,
description: str | None = None,
) -> dict[str, Any]:
schema: dict[str, Any] = {"type": "object", "properties": properties}
if required:
schema["required"] = required
return {
"post": {
"operationId": operation_id,
"summary": summary,
"description": str(description or summary),
"parameters": [],
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": schema,
}
},
},
"responses": {
"200": {
"description": (
"Tool response (status: ok|running|needs_human|failed). "
"May include checkpoint and human_options; business buttons are exposed only by ui_state.actions."
),
"content": {
"application/json": {
"schema": {"type": "object"},
}
},
}
},
}
}
def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
"""Build OpenAPI 3.0 spec for Dify Chatflow custom tools (agent-facing only)."""
server = str(base_url or "").strip().rstrip("/")
if not server.endswith("/api/shipping-notice"):
server = f"{server}/api/shipping-notice" if server else "/api/shipping-notice"
task_id = _str_prop("发货任务引用:技术任务号 SN-20260529-ABCD1234 或业务号 WYC26071501")
capability_token = _str_prop("HXOPS 每轮注入的短效只读能力令牌;必须原样透传")
return {
"openapi": "3.0.0",
"info": {
"title": "Shipping Notice Tools",
"version": "1.0.0",
"description": (
"货代 Chatflow 仅作自然语言只读解释。所有写操作必须由 HXOPS 确认卡和后端状态机执行;"
"本 OpenAPI 不包含改单、确认、冻结、库存、Excel 或上传接口。"
),
},
"servers": [{"url": server}],
"paths": {
"/tools/get_task_status": _post_op(
"get_task_status",
"查询任务当前状态与 human_options;响应含库存连接器独立字段与候选结构",
{
"task_id": task_id,
"conversation_id": _str_prop("Dify 会话 ID"),
"shipping_chat_capability_token": capability_token,
},
required=["task_id", "shipping_chat_capability_token"],
description=(
"返回 inventory_source_code、inventory_connector_type、"
"inventory_warehouse_id、inventory_source_status(unresolved|ambiguous|resolved|"
"user_confirmed|invalid|conflicted)、inventory_source_method、"
"inventory_source_config_version、inventory_routing_fingerprint、"
"inventory_source_confirmed_by、inventory_source_confirmed_at,"
"以及 step_payload.inventory_source_resolution.candidates。"
),
),
},
}