feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -2,8 +2,9 @@
|
||||
backend/app/services/shipping_notice/candidate_validation.py
|
||||
|
||||
用途:统一校验并标准化人工修订或建批前的订单 Candidate 业务摘要。
|
||||
依赖:notice_lines、po_number、reservation_id、core.errors。
|
||||
逻辑:Candidate API 与建批门禁共用,确保至少一条 SKU+Qty 有效订单行,避免空摘要绕过审核。
|
||||
依赖:notice_lines、po_number、reservation_id、field_rules、core.errors。
|
||||
逻辑:Candidate API 与建批门禁共用,确保至少一条 SKU+Qty 有效订单行,避免空摘要绕过审核;
|
||||
流程门禁使用有效 Reservation(行 ?? 头),库存源候选由资格服务另行裁决。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,6 +13,7 @@ from typing import Any
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice.notice_lines import non_atomic_part_number_field, normalize_notice_line
|
||||
from app.services.shipping_notice.order_schema.field_rules import compute_effective_reservation_id
|
||||
from app.services.shipping_notice.po_number import normalize_atomic_po_number
|
||||
from app.services.shipping_notice.reservation_id import validated_reservation_id
|
||||
|
||||
@@ -23,8 +25,8 @@ def assess_candidate_business_summary(summary: dict[str, Any] | None) -> dict[st
|
||||
"""
|
||||
评估规则/LLM订单结果是否达到自动建单最低条件,同时保留不完整内容供自然对话修订。
|
||||
|
||||
核心逻辑:原子 part_number + 正数 Qty 是建单硬条件;Reservation ID 是唯一流程门禁字段。
|
||||
inventory_source_hint 仅保留为可选库存源路由线索,缺失时不阻断建单或后续流程。
|
||||
核心逻辑:原子 part_number + 正数 Qty 是建单硬条件;有效 Reservation(行优先回退头)
|
||||
是流程门禁字段。inventory_source_hint 仅保留为可选路由线索,缺失时不阻断本评估。
|
||||
|
||||
Args:
|
||||
summary: 单个订单的业务摘要。
|
||||
@@ -34,6 +36,7 @@ def assess_candidate_business_summary(summary: dict[str, Any] | None) -> dict[st
|
||||
missing_process_fields、invalid_lines 与 blocking_issues 的评估结果。
|
||||
"""
|
||||
raw = dict(summary) if isinstance(summary, dict) else {}
|
||||
header_reservation = raw.get('reservation_id')
|
||||
raw_lines = raw.get('lines') if isinstance(raw.get('lines'), list) else []
|
||||
normalized_lines: list[dict[str, Any]] = []
|
||||
invalid_lines: list[dict[str, Any]] = []
|
||||
@@ -55,6 +58,13 @@ def assess_candidate_business_summary(summary: dict[str, Any] | None) -> dict[st
|
||||
if raw_reservation and not validated_reservation_id(raw_reservation):
|
||||
invalid_lines.append({'line_index': index, 'reason': 'invalid_reservation_id'})
|
||||
continue
|
||||
effective = compute_effective_reservation_id(
|
||||
line_reservation_id=normalized.get('reservation_id'),
|
||||
header_reservation_id=header_reservation,
|
||||
)
|
||||
if effective:
|
||||
normalized['reservation_id'] = effective
|
||||
normalized['effective_reservation_id'] = effective
|
||||
normalized_lines.append(normalized)
|
||||
|
||||
normalized_summary = dict(raw)
|
||||
@@ -66,18 +76,22 @@ def assess_candidate_business_summary(summary: dict[str, Any] | None) -> dict[st
|
||||
normalized_summary['reservation_ids'] = sorted({
|
||||
normalized
|
||||
for line in normalized_lines
|
||||
if (normalized := validated_reservation_id(line.get('reservation_id')))
|
||||
if (normalized := validated_reservation_id(
|
||||
line.get('effective_reservation_id') or line.get('reservation_id')
|
||||
))
|
||||
})
|
||||
|
||||
missing_required: list[str] = []
|
||||
if not normalized_lines:
|
||||
missing_required.extend(BUILD_REQUIRED_FIELDS)
|
||||
# Reservation 是逐行匹配键;任一有效订单行缺失都必须保留流程字段门禁。
|
||||
# 有效 Reservation 是逐行匹配键;头级可回填行级缺失。
|
||||
missing_process = [
|
||||
field
|
||||
for field in PROCESS_FIELDS
|
||||
if any(
|
||||
not validated_reservation_id(line.get(field))
|
||||
not validated_reservation_id(
|
||||
line.get('effective_reservation_id') or line.get(field)
|
||||
)
|
||||
for line in normalized_lines
|
||||
)
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user