feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验

- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全
- 引入审计事件的哈希链校验机制,支持数据完整性验证
- 增强订单抽取与审计功能,支持敏感快照的访问控制
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
hugo committed 2026-07-31 08:59:44 +08:00
1 parent 95cdfe66b0
commit d0fe084999
225 files changed
+25923 -6653

No files matched your search

@@ -2,9 +2,9 @@
services/shipping_notice/tool_common.py
用途:发货通知 Tool 链共享配置、payload 合并、消息拼接与任务事件写入(无阶段业务编排)。
依赖:constants、models.ShippingTaskEvent、fulfillment_audit(库存/RPA/导出双写,strict)。
依赖:constants、models.ShippingTaskEvent、fulfillment_audit、stp_progress_contract。
逻辑:task_workflow / inventory_workflow / fulfillment_workflow 共用;log_task_event 对
inventory_rpa_/inventory_source_/export_ 前缀事件同步投影到 ShippingAuditEvent,失败阻断业务。
inventory_rpa_/inventory_source_/export_/STP 事件同步投影到 ShippingAuditEvent,失败阻断业务。
"""
from __future__ import annotations
@@ -293,8 +293,15 @@ def log_task_event(
before_json=before,
after_json=after,
))
# 库存/RPA/导出关键节点双写统一审计;失败必须阻断,保证审计中心可检索。
if str(event_type or '').startswith(('inventory_rpa_', 'inventory_source_', 'export_')):
# 库存/RPA/导出/STP 关键节点双写统一审计;失败必须阻断,保证审计中心可检索。
from app.services.shipping_notice.stp_progress_contract import STP_AUDIT_DUAL_WRITE_PREFIXES
event_name = str(event_type or '')
dual_write = event_name.startswith(('inventory_rpa_', 'inventory_source_', 'export_')) or any(
event_name.startswith(prefix) or event_name == prefix
for prefix in STP_AUDIT_DUAL_WRITE_PREFIXES
)
if dual_write:
from app.services.shipping_notice.fulfillment_audit import record_fulfillment_audit
safe_before = None
@@ -315,6 +322,27 @@ def log_task_event(
attempt_count = int((detail or {}).get('attempts') or (detail or {}).get('attempt_no') or 0) or None
if attempt_count is not None:
meta['attempt_count'] = attempt_count
# 将关键操作内容(匹配结论、候选源、原因码等)写入 metadata,供审计中心检索。
detail_obj = detail if isinstance(detail, dict) else {}
for key in (
'match_status',
'resolved_ok_source_codes',
'source_code',
'connector_type',
'warehouse_id',
'reason_code',
'error_code',
'verification_id',
'disposition',
'confirmed_by',
):
if key not in detail_obj:
continue
value = detail_obj[key]
if isinstance(value, (str, int, float, bool)) or value is None:
meta[key] = value
elif isinstance(value, list) and all(isinstance(item, (str, int, float, bool)) or item is None for item in value):
meta[key] = value[:32]
record_fulfillment_audit(
event_type=f'task_{event_type}'[:64],
aggregate_type='shipping_task',