- 退役 erp_adapter/gateway_adapter:外部查询/写经 capability_client 走集成连接器,端点凭据与并发超时由客户端实例管理 - 域能力代码注册 capabilities:入参出参 Schema、幂等语义与读写标志随域代码版本化,组合根 create_app 幂等注册 - 新增调拨业务类型 transfer_type(在途仓至HUB/HUB维修出/HUB间)冻结枚举,迁移落 CheckConstraint 数据库兜底 - 外部仓库映射新增 in_transit_warehouse_code 拨出库位来源,管理端库存映射页同步维护 - 单据命名外部化:erp_* 字段与索引改称 external_*,单据号格式交由连接器映射,测试数据同步换牌 - 收料归档文件可用性判定收敛 receipt_file_gate 单一事实来源(当天抓取/保留期/清理态) - 同步 chat 调拨卡片、useChatTransfer、e2e、全套服务/API/Job 测试与域文档
104 lines
3.8 KiB
Python
104 lines
3.8 KiB
Python
"""services/in_transit_transfer/capabilities.py
|
|
|
|
用途:在途调拨域的能力声明——本域经集成连接器暴露的能力契约(入参/出参 Schema、
|
|
幂等语义、读写标志),代码注册、禁止管理端动态定义。
|
|
依赖:integration_connector.capability(机制层:CapabilitySpec/注册表)。
|
|
逻辑:本模块属于领域包而非连接器框架——框架只提供注册/校验机制,域契约随域代码
|
|
版本化;应用组合根(app/__init__.py)在每次 create_app 时调用
|
|
register_transfer_capabilities()(幂等),保证管理端「能力清单」冷启动即可见,
|
|
测试 reset 注册表后也能重建。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.services.integration_connector.capability import (
|
|
CapabilitySpec,
|
|
list_capabilities,
|
|
register_capability,
|
|
)
|
|
|
|
# 在途调拨能力输入/输出 Schema(JSON Schema 最小子集,供入参/出参校验)。
|
|
# 查询契约:按组织批量查库存,目标为 (料号, 拨出库位, 拨出批号) 元组列表;
|
|
# external_org 取自仓库映射(external_organization_code),由绑定参数映射翻译为接口的 organization。
|
|
_QUERY_INPUT_SCHEMA: dict = {
|
|
"type": "object",
|
|
"required": ["external_org", "targets"],
|
|
"properties": {
|
|
"external_org": {"type": "string"},
|
|
"targets": {"type": "array", "items": {
|
|
"type": "object",
|
|
"required": ["material_no", "from_warehouse", "lot_no"],
|
|
"properties": {
|
|
"material_no": {"type": "string"},
|
|
"from_warehouse": {"type": "string"},
|
|
"lot_no": {"type": "string"},
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
_QUERY_OUTPUT_SCHEMA: dict = {
|
|
"type": "object",
|
|
"required": ["rows"],
|
|
"properties": {
|
|
"rows": {"type": "array", "items": {
|
|
"type": "object",
|
|
"required": ["material_no", "from_warehouse", "lot_no", "quantity"],
|
|
"properties": {
|
|
"material_no": {"type": "string"},
|
|
"from_warehouse": {"type": "string"},
|
|
"lot_no": {"type": "string"},
|
|
"quantity": {"type": "number"},
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
_WRITE_OUTPUT_SCHEMA: dict = {
|
|
"type": "object",
|
|
"required": ["status"],
|
|
"properties": {
|
|
"status": {
|
|
"type": "string",
|
|
"enum": ["success", "business_failed", "technical_failed", "timeout", "result_unknown"],
|
|
},
|
|
"document_no": {"type": ["string", "null"]},
|
|
"verified_posted": {"type": ["boolean", "null"]},
|
|
},
|
|
}
|
|
|
|
|
|
def register_transfer_capabilities() -> None:
|
|
"""注册在途调拨域的三个能力(幂等:已注册的同名跳过)。
|
|
|
|
幂等是硬要求:组合根每次 create_app 都会调用;测试 reset 注册表后(模块缓存导致
|
|
import 副作用不再执行)也依赖本函数重建,故不能依赖「只注册一次」。
|
|
"""
|
|
registered = {spec.name for spec in list_capabilities()}
|
|
for spec in (
|
|
CapabilitySpec(
|
|
name="in_transit_transfer.query_inventory",
|
|
input_schema=_QUERY_INPUT_SCHEMA,
|
|
output_schema=_QUERY_OUTPUT_SCHEMA,
|
|
idempotency="none",
|
|
write=False,
|
|
),
|
|
CapabilitySpec(
|
|
name="in_transit_transfer.create_transfer",
|
|
input_schema=_QUERY_INPUT_SCHEMA,
|
|
output_schema=_WRITE_OUTPUT_SCHEMA,
|
|
idempotency="invoice",
|
|
write=True,
|
|
),
|
|
CapabilitySpec(
|
|
name="in_transit_transfer.verify_duplicate",
|
|
input_schema=_QUERY_INPUT_SCHEMA,
|
|
output_schema=_WRITE_OUTPUT_SCHEMA,
|
|
idempotency="invoice",
|
|
write=False,
|
|
),
|
|
):
|
|
if spec.name not in registered:
|
|
register_capability(spec)
|
|
|
|
|
|
register_transfer_capabilities()
|