Files
hugo abf3d48927 feat(in-transit-transfer): 自动调拨联动收料就绪并分层来源错误
- 调度整合:退役 in_transit_receipt_file_job,收料归档收敛 shipping_receipt_rpa_archive,排程注册表统一
- 自动调拨 Job:调拨前确保各来源当日收料文件就绪(缺失自动触发收料 RPA),严格等量匹配后生成 ERP 调拨单
- worker 手动唤醒:排程工作台支持手动唤醒与 runs 透视,heartbeat 协议同步
- 收料缺失幸存 T2:parse_failed 状态落库(迁移 q4c5)
- 来源错误分层与 stale 时钟换源:改挂 inventory_checked_at 库存查得时刻,展示阈值与执行门禁解耦(迁移 t5a6)
- 新增 wecom_sender 企微通知:每非空 Run 汇总一条,通知失败不影响 ERP 结果
- 同步排程工作台/调拨卡片前端、chat/admin 文案四语言、RPA 脚本与测试全家
2026-09-30 00:20:06 +08:00

74 lines
3.1 KiB
Python
Raw Permalink 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.
"""在途调拨策略硬门禁。
用途:一期策略禁止部分数量调拨、数量容差与 外部系统 自动重试;
confirm_ttl_seconds 与 inventory_stale_ttl_seconds 均为纯展示阈值
(stale 徽标判定窗口,不再作为执行门禁——2026-09-25 退役);
2026-09-29 起 stale 时钟换源:挂 inventory_checked_at(库存查得
时刻),阈值默认 24 小时——证据同步换戳不续期该时钟。
依赖:app.core.errors.AppError、standard decimal。
逻辑:任何策略变体触碰三项禁令之一即抛 StrategyViolationError,
阻止发布/执行(fail-closed)。
"""
from __future__ import annotations
from dataclasses import dataclass
from decimal import Decimal
from app.core.errors import AppError
STRATEGY_VIOLATION_CODE = "TRANSFER.STRATEGY_VIOLATION"
DEFAULT_CONFIRM_TTL_SECONDS = 600 # 10 分钟
DEFAULT_INVENTORY_STALE_TTL_SECONDS = 86400 # 24 小时
@dataclass(frozen=True)
class TransferStrategyPolicy:
"""调拨策略冻结快照;三项禁令默认关闭。"""
allow_partial: bool = False
quantity_tolerance: Decimal = Decimal("0")
allow_external_auto_retry: bool = False
# 纯展示阈值:行 stale 徽标(「库存数据已过期,请重查」提示)的判定窗口;
# 不再作为执行门禁(2026-09-25 退役)——防错由文件版本对账 + worker 写前
# 库存复查承担(见 execution_service)。
confirm_ttl_seconds: int = DEFAULT_CONFIRM_TTL_SECONDS
# 纯展示阈值:stale 徽标判定窗口,时钟=inventory_checked_at(库存查得
# 时刻,仅匹配评估/重查/写前复查写入;2026-09-29 起替换原 updated_at
# 时钟——后者被证据同步换戳每日续期,徽标对老行永不触发)。
inventory_stale_ttl_seconds: int = DEFAULT_INVENTORY_STALE_TTL_SECONDS
class StrategyViolationError(AppError):
"""策略触碰一期禁令。"""
def __init__(self, message: str, *, reason: str):
super().__init__(
code=STRATEGY_VIOLATION_CODE,
message=message,
http_status=409,
details={"reason": reason},
)
def validate_strategy(strategy: TransferStrategyPolicy) -> None:
"""校验策略是否违反一期硬门禁。
Args:
strategy: 待校验策略。
Raises:
StrategyViolationError: 开启部分调拨、非零容差或 外部系统 自动重试。
"""
if strategy.allow_partial:
raise StrategyViolationError("partial transfer is not supported in phase 1", reason="allow_partial")
if strategy.quantity_tolerance != Decimal("0"):
raise StrategyViolationError("quantity tolerance is not supported in phase 1", reason="quantity_tolerance")
if strategy.allow_external_auto_retry:
raise StrategyViolationError("External auto retry is forbidden in phase 1", reason="allow_external_auto_retry")
def default_strategy() -> TransferStrategyPolicy:
"""返回一期默认策略(全部禁令关闭;stale 展示阈值:行新鲜度 600 秒 /
库存查得时刻 24 小时)。"""
return TransferStrategyPolicy()