66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""
|
|
backend/app/services/shipping_notice/reservation_gate.py
|
|
|
|
用途:为库存、RPA、匹配、导出和上传入口提供统一的订单侧 Reservation ID 门禁判断。
|
|
依赖:reservation_id.is_valid_reservation_id。
|
|
逻辑:各推进服务在产生外部或下游副作用前调用本模块,确保任何直接入口都不能绕过订单字段门禁。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.services.shipping_notice.reservation_id import is_valid_reservation_id
|
|
|
|
|
|
def reservation_gate_issues(lines: list[Any] | None) -> list[dict[str, Any]]:
|
|
"""
|
|
返回缺失或格式非法的订单行 Reservation ID 问题。
|
|
|
|
Args:
|
|
lines: ShippingTask 订单行数组。
|
|
|
|
Returns:
|
|
含行号、内部料号、原值和原因的 blocking issue;全部合法时返回空列表。
|
|
"""
|
|
if not lines:
|
|
return [
|
|
{
|
|
"line_index": None,
|
|
"part_number": "",
|
|
"field": "reservation_id",
|
|
"reason": "missing_order_lines",
|
|
"severity": "blocking",
|
|
"raw_value": "",
|
|
}
|
|
]
|
|
|
|
issues: list[dict[str, Any]] = []
|
|
for index, raw_line in enumerate(lines):
|
|
if not isinstance(raw_line, dict):
|
|
issues.append(
|
|
{
|
|
"line_index": index,
|
|
"part_number": "",
|
|
"field": "reservation_id",
|
|
"reason": "invalid_order_line",
|
|
"severity": "blocking",
|
|
"raw_value": "",
|
|
}
|
|
)
|
|
continue
|
|
raw_value = str(raw_line.get("reservation_id") or "").strip()
|
|
if is_valid_reservation_id(raw_value):
|
|
continue
|
|
issues.append(
|
|
{
|
|
"line_index": index,
|
|
"part_number": str(raw_line.get("part_number") or "").strip(),
|
|
"field": "reservation_id",
|
|
"reason": "invalid_format" if raw_value else "missing",
|
|
"severity": "blocking",
|
|
"raw_value": raw_value,
|
|
}
|
|
)
|
|
return issues
|