feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略
- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关 - 实现订单抽取运行的取消功能,允许管理员在运行中进行操作 - 引入审计事件的保留策略,支持三年保留期的自动清理 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
c85997884b
commit
95cdfe66b0
158 files changed
+19005
-1201
No files matched your search
@@ -1,9 +1,10 @@
|
||||
"""
|
||||
services/shipping_notice/tool_common.py
|
||||
|
||||
用途:发货通知 Tool 链共享配置、payload 合并与消息拼接(无阶段业务编排)。
|
||||
依赖:constants、models.ShippingTaskEvent。
|
||||
逻辑:task_workflow / inventory_workflow / fulfillment_workflow 共用,避免 tools 循环依赖。
|
||||
用途:发货通知 Tool 链共享配置、payload 合并、消息拼接与任务事件写入(无阶段业务编排)。
|
||||
依赖:constants、models.ShippingTaskEvent、fulfillment_audit(库存/RPA/导出双写,strict)。
|
||||
逻辑:task_workflow / inventory_workflow / fulfillment_workflow 共用;log_task_event 对
|
||||
inventory_rpa_/inventory_source_/export_ 前缀事件同步投影到 ShippingAuditEvent,失败阻断业务。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -292,6 +293,43 @@ def log_task_event(
|
||||
before_json=before,
|
||||
after_json=after,
|
||||
))
|
||||
# 库存/RPA/导出关键节点双写统一审计;失败必须阻断,保证审计中心可检索。
|
||||
if str(event_type or '').startswith(('inventory_rpa_', 'inventory_source_', 'export_')):
|
||||
from app.services.shipping_notice.fulfillment_audit import record_fulfillment_audit
|
||||
|
||||
safe_before = None
|
||||
safe_after = None
|
||||
if isinstance(before, dict):
|
||||
safe_before = {
|
||||
key: before[key]
|
||||
for key in ('status', 'phase', 'reason_code', 'error_code', 'attempt_count')
|
||||
if key in before
|
||||
} or None
|
||||
if isinstance(after, dict):
|
||||
safe_after = {
|
||||
key: after[key]
|
||||
for key in ('status', 'phase', 'reason_code', 'error_code', 'attempt_count')
|
||||
if key in after
|
||||
} or None
|
||||
meta: dict[str, Any] = {'dual_write': 'shipping_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
|
||||
record_fulfillment_audit(
|
||||
event_type=f'task_{event_type}'[:64],
|
||||
aggregate_type='shipping_task',
|
||||
aggregate_id=str(task.task_no),
|
||||
action=str(event_type)[:64],
|
||||
actor_type='user' if actor_id is not None else 'system',
|
||||
actor_id=actor_id,
|
||||
task_no=str(task.task_no),
|
||||
result='success',
|
||||
before=safe_before,
|
||||
after=safe_after or {'status': getattr(task, 'process_status', None)},
|
||||
metadata=meta,
|
||||
source=str(source or 'system')[:32],
|
||||
strict=True,
|
||||
)
|
||||
|
||||
|
||||
def log_task_action_event(
|
||||
|
||||
Reference in new issue
Block a user