feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

@@ -2,7 +2,7 @@
backend/app/services/shipping_notice/reference_context.py
用途:从发货通知批次/任务/事件构建 shipping_notice 专用 reference_context。
依赖:models.ShippingBatch/ShippingTask/ShippingTaskEvent、agent_runtime_context.reference。
依赖:models.ShippingNotice/ShippingTaskEvent、agent_runtime_context.reference。
逻辑:runtime_context 在调用 Dify 前经本模块提炼当前 focus、最近动作、最近失败和候选对象,避免把全量事件流水直接暴露给 Runtime。
"""
@@ -12,7 +12,7 @@ from dataclasses import dataclass
from datetime import datetime
from typing import Any
from app.models import ShippingBatch, ShippingTask, ShippingTaskEvent
from app.models import ShippingNotice, ShippingTaskEvent
from app.services.agent_runtime_context.reference import build_object_ref, build_reference_context
MAX_REFERENCE_EVENT_SCAN = 8
@@ -45,12 +45,12 @@ def _clean_text(value: Any) -> str:
return str(value or "").strip()
def _task_no(task: ShippingTask | None) -> str:
def _task_no(task: ShippingNotice | None) -> str:
"""提取任务号并统一成大写。"""
return _clean_text(getattr(task, "task_no", None)).upper()
def _task_recency_key(task: ShippingTask) -> tuple[datetime, int]:
def _task_recency_key(task: ShippingNotice) -> tuple[datetime, int]:
"""
构造任务最近性排序键。
@@ -60,30 +60,18 @@ def _task_recency_key(task: ShippingTask) -> tuple[datetime, int]:
return updated_at, int(getattr(task, "id", 0) or 0)
def _collect_batch_tasks(batch: ShippingBatch | None, focus_task: ShippingTask | None) -> list[ShippingTask]:
def _collect_batch_tasks(batch: Any | None, focus_task: ShippingNotice | None) -> list[ShippingNotice]:
"""
汇总当前 reference_context 可见的任务集合。
核心逻辑:优先读取当前批次任务;若 focus_task 尚未包含则补入,避免后台单票 run 丢失最近失败/焦点判断。
核心逻辑:shipping_batches 已删除;仅保留 focus_task 单票上下文。
"""
tasks: list[ShippingTask] = []
seen: set[str] = set()
for task in list(getattr(batch, "tasks", None) or []):
task_no = _task_no(task)
if not task_no or task_no in seen:
continue
tasks.append(task)
seen.add(task_no)
focus_task_no = _task_no(focus_task)
if focus_task is not None and focus_task_no and focus_task_no not in seen:
tasks.append(focus_task)
return sorted(tasks, key=_task_recency_key, reverse=True)
if focus_task is None:
return []
return [focus_task]
def _recent_events(tasks: list[ShippingTask]) -> list[ShippingTaskEvent]:
def _recent_events(tasks: list[ShippingNotice]) -> list[ShippingTaskEvent]:
"""
查询最近关键事件。
@@ -100,7 +88,7 @@ def _recent_events(tasks: list[ShippingTask]) -> list[ShippingTaskEvent]:
)
def _task_failure_descriptor(task: ShippingTask | None) -> dict[str, str] | None:
def _task_failure_descriptor(task: ShippingNotice | None) -> dict[str, str] | None:
"""
提取任务失败/异常摘要。
@@ -146,7 +134,7 @@ def _task_failure_descriptor(task: ShippingTask | None) -> dict[str, str] | None
def _last_action_target(
*,
events: list[ShippingTaskEvent],
task_by_id: dict[int, ShippingTask],
task_by_id: dict[int, ShippingNotice],
) -> tuple[dict[str, str], str]:
"""
根据最近事件提取最后动作对象。
@@ -182,7 +170,7 @@ def _last_action_target(
return best_match[1], best_match[2]
def _last_failed_target(tasks: list[ShippingTask]) -> tuple[dict[str, str], str]:
def _last_failed_target(tasks: list[ShippingNotice]) -> tuple[dict[str, str], str]:
"""
提取最近失败或异常的目标对象。
@@ -200,7 +188,7 @@ def _last_failed_target(tasks: list[ShippingTask]) -> tuple[dict[str, str], str]
return {}, ""
def _candidate_refs(tasks: list[ShippingTask], focus_task_no: str) -> list[dict[str, str]]:
def _candidate_refs(tasks: list[ShippingNotice], focus_task_no: str) -> list[dict[str, str]]:
"""
生成模糊指代候选对象列表。
@@ -224,7 +212,7 @@ def _candidate_refs(tasks: list[ShippingTask], focus_task_no: str) -> list[dict[
def _build_recent_activity_summary(
*,
batch: ShippingBatch | None,
batch: Any | None,
focus_task_no: str,
last_action_summary: str,
last_failed_summary: str,
@@ -257,8 +245,8 @@ def _build_recent_activity_summary(
def build_shipping_reference_context(
*,
batch: ShippingBatch | None,
focus_task: ShippingTask | None,
batch: Any | None,
focus_task: ShippingNotice | None,
) -> dict[str, Any]:
"""
构建发货通知 Agent 专用 reference_context。