feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置 新增收料报表管理的前端页面、路由和侧边栏入口 新增后端收料报表配置接口、数据库模型和RPA脚本 优化发货通知流程的重试策略,将shipping相关job默认不自动重试 移除废弃的库存源确认相关逻辑,更新流程门禁规则 重构订单模板的值适配器模块,新增坐标OCR值适配器 清理前端shipping菜单和action的废弃选项 更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
1 parent
260465b72d
commit
1b6483a4ea
466 files changed
+32115
-33796
No files matched your search
@@ -62,7 +62,6 @@ from app.services.shipping_notice.query_service import (
|
||||
)
|
||||
from app.services.shipping_notice.state_machine import (
|
||||
CheckpointKind,
|
||||
inventory_source_action_buttons,
|
||||
resolve_task_ui_state,
|
||||
)
|
||||
from app.services.shipping_notice.user_facing_status import user_facing_task_stage
|
||||
@@ -125,7 +124,7 @@ _PAUSE_REASON_BY_CHECKPOINT: dict[str, tuple[str, str]] = {
|
||||
CP_RSV_REQ: ("rsv_required", "缺少后续匹配必需字段"),
|
||||
CP_CUSTOMER_REVIEW: ("customer_ambiguous", "客户未唯一确认"),
|
||||
CP_UPLOAD_REQ: ("inventory_unavailable", "需要提供库存数据或重试库存获取"),
|
||||
CP_INVENTORY_SOURCE_REVIEW: ("inventory_source_unresolved", "库存源尚未唯一确定"),
|
||||
CP_INVENTORY_SOURCE_REVIEW: ("inventory_source_unresolved", "库存源规则正在重新裁决"),
|
||||
CP_ORDER_FREEZE: ("order_freeze_pending", "订单待冻结后进入库存履约"),
|
||||
RS_SHORTAGE_REVIEW: ("shortage", "库存存在缺口"),
|
||||
CP_NOTICE_TEXT_EXTRACTION_FAILED: ("notice_text_extraction_failed", "通知文本解析失败"),
|
||||
@@ -192,7 +191,11 @@ def _business_stage(lifecycle: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def _unified_action(action: dict[str, Any], *, default_kind: str = "recovery") -> dict[str, Any]:
|
||||
"""规范 Gate/旧状态机动作,前端只渲染该统一结构。"""
|
||||
"""规范 Gate/旧状态机动作,前端只渲染该统一结构。
|
||||
|
||||
``target_surface`` / ``target_anchor`` 均由 Gate 或 Artifact 授权来源声明;
|
||||
生命周期页面只能按它们放置动作,禁止再从 action code、Excel 文件或上传状态推断。
|
||||
"""
|
||||
item = dict(action or {})
|
||||
code = str(item.get("code") or item.get("id") or "").strip()
|
||||
dispatch = str(item.get("dispatch") or "").strip()
|
||||
@@ -203,18 +206,20 @@ def _unified_action(action: dict[str, Any], *, default_kind: str = "recovery") -
|
||||
"code": code,
|
||||
"label": item.get("label") or item.get("label_key") or code,
|
||||
"kind": kind,
|
||||
# Gate 合同决定执行分派;前端不得再依据动作码猜测是 POST、跳转还是弹窗。
|
||||
"dispatch": dispatch or "mutation",
|
||||
"ui_handler": item.get("ui_handler"),
|
||||
"enabled": bool(item.get("enabled", True)),
|
||||
"requires_confirmation": bool(item.get("requires_confirmation", False)),
|
||||
"target_surface": item.get("target_surface") or ("shipping_task_workbench" if dispatch == "navigation" else None),
|
||||
"target_surface": item.get("target_surface"),
|
||||
"target_anchor": item.get("target_anchor"),
|
||||
"disabled_reason": item.get("disabled_reason"),
|
||||
"expected_gate_version": item.get("expected_gate_version"),
|
||||
}
|
||||
|
||||
|
||||
def _unified_actions(
|
||||
*, process_gate: dict[str, Any] | None, action_buttons: list[dict[str, str]],
|
||||
) -> dict[str, Any]:
|
||||
"""统一输出唯一主动作与次动作;动作来源优先为 Gate。"""
|
||||
def _unified_actions(*, process_gate: dict[str, Any] | None) -> dict[str, Any]:
|
||||
"""统一输出唯一主动作与次动作;用户动作只允许来自 Gate。"""
|
||||
gate_actions = list((process_gate or {}).get("action_presentation") or [])
|
||||
if process_gate and (process_gate.get("primary_action") or gate_actions):
|
||||
primary_raw = process_gate.get("primary_action") or gate_actions[0]
|
||||
@@ -224,8 +229,8 @@ def _unified_actions(
|
||||
if str((item or {}).get("code") or (item or {}).get("id") or "").strip() != primary_code
|
||||
]
|
||||
else:
|
||||
primary_raw = action_buttons[0] if action_buttons else None
|
||||
secondary_raw = action_buttons[1:] if action_buttons else []
|
||||
primary_raw = None
|
||||
secondary_raw = []
|
||||
gate_view = (process_gate or {}).get("current_blocking_gate") or (process_gate or {}).get("current_gate") or {}
|
||||
expected_version = gate_view.get("evaluation_version") or (process_gate or {}).get("lock_version")
|
||||
|
||||
@@ -329,52 +334,6 @@ def build_shipping_workflow_steps(
|
||||
return steps
|
||||
|
||||
|
||||
def _action_buttons_for_task(task: ShippingNotice) -> list[dict[str, str]]:
|
||||
"""
|
||||
从状态机解析当前任务可用动作按钮;多源匹配阻断时前置「人工指定库存源」。
|
||||
|
||||
核心逻辑:库存源确认场景补充 source_code;shortage + multi_source/multi_file 冲突时
|
||||
注入 confirm_inventory_source,使工作台可打开候选选择对话框。
|
||||
"""
|
||||
from app.services.shipping_notice.state_machine import ACTION_SPECS
|
||||
from app.services.shipping_notice.stp_line_inventory_match import (
|
||||
multi_source_recovery_source_codes,
|
||||
needs_multi_source_manual_recovery,
|
||||
)
|
||||
|
||||
ui = resolve_task_ui_state(task)
|
||||
if ui.checkpoint == CP_INVENTORY_SOURCE_REVIEW:
|
||||
return inventory_source_action_buttons(task)
|
||||
if ui.checkpoint == RS_SHORTAGE_REVIEW and needs_multi_source_manual_recovery(task):
|
||||
codes = multi_source_recovery_source_codes(task)
|
||||
confirm_spec = dict(ACTION_SPECS.get('confirm_inventory_source') or {})
|
||||
confirm_btn: dict[str, str] = {
|
||||
'id': 'confirm_inventory_source',
|
||||
'label': str(confirm_spec.get('label') or '人工指定库存源'),
|
||||
'message': '请选择单一库存源后继续匹配',
|
||||
'variant': str(confirm_spec.get('variant') or 'primary'),
|
||||
}
|
||||
if len(codes) == 1:
|
||||
confirm_btn['source_code'] = codes[0]
|
||||
confirm_btn['label'] = f"指定库存源:{codes[0]}"
|
||||
confirm_btn['message'] = f"使用库存源 {codes[0]} 重新匹配"
|
||||
else:
|
||||
confirm_btn['label'] = '人工指定库存源'
|
||||
# 保留重试/重匹配/驳回,但把指定源放在首位作为主恢复入口。
|
||||
rest = [btn for btn in (ui.action_buttons or []) if str(btn.get('id') or '') != 'confirm_inventory_source']
|
||||
return [confirm_btn, *rest]
|
||||
action_buttons = list(ui.action_buttons or [])
|
||||
# [AUTHORITY] ``export_file_name`` 只是历史字段,不能作为下载授权或文件存在的证据。
|
||||
# 只有任务当前 Artifact 已由后端解析为可下载文件时,才把 download_excel 下发给
|
||||
# 任一前端;下载 API 仍会在真正读取文件时再次校验,抵御页面快照过期。
|
||||
if any(str((button or {}).get('id') or '') == 'download_excel' for button in action_buttons):
|
||||
if resolve_task_export_download(task) is None:
|
||||
action_buttons = [
|
||||
button for button in action_buttons
|
||||
if str((button or {}).get('id') or '') != 'download_excel'
|
||||
]
|
||||
return action_buttons
|
||||
|
||||
_PARSE_STAGE_CHECKPOINTS = {
|
||||
CP_PARSE_REVIEW,
|
||||
CP_RSV_REQ,
|
||||
@@ -501,14 +460,10 @@ def _entry_surface_for(checkpoint: str | None, kind: CheckpointKind) -> str:
|
||||
return "none"
|
||||
|
||||
|
||||
def _current_todo_label(checkpoint: str | None, action_buttons: list[dict[str, str]]) -> str | None:
|
||||
"""从当前动作按钮推导「当前待办」文案;无人工动作时返回 None。"""
|
||||
if not action_buttons:
|
||||
pause = _PAUSE_REASON_BY_CHECKPOINT.get(str(checkpoint or ""))
|
||||
return pause[1] if pause else None
|
||||
primary = next((b for b in action_buttons if b.get("variant") == "primary"), action_buttons[0])
|
||||
label = str(primary.get("label") or "").strip()
|
||||
return label or None
|
||||
def _current_todo_label(checkpoint: str | None) -> str | None:
|
||||
"""从内部 checkpoint 提取只读待办说明,不派生用户动作。"""
|
||||
pause = _PAUSE_REASON_BY_CHECKPOINT.get(str(checkpoint or ""))
|
||||
return pause[1] if pause else None
|
||||
|
||||
|
||||
def _build_stp_facts(task: ShippingNotice) -> dict[str, Any] | None:
|
||||
@@ -611,7 +566,6 @@ def _build_task_summary(
|
||||
checkpoint: str | None,
|
||||
*,
|
||||
checkpoint_kind: CheckpointKind,
|
||||
action_buttons: list[dict[str, str]],
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
输出可解释任务摘要,供通知卡、人工复核与任务工作台同源消费。
|
||||
@@ -627,7 +581,7 @@ def _build_task_summary(
|
||||
CP_CUSTOMER_REVIEW: "客户尚未唯一确认,请在任务处理中选择标准客户。",
|
||||
CP_UPLOAD_REQ: "当前需要提供库存数据或重试库存获取。",
|
||||
CP_INVENTORY_PENDING: "发货通知已就绪,系统将自动准备库存数据。",
|
||||
CP_INVENTORY_SOURCE_REVIEW: "库存源尚未确定,请先选择正式库存源。",
|
||||
CP_INVENTORY_SOURCE_REVIEW: "库存源规则正在重新裁决。",
|
||||
CP_ORDER_FREEZE: "订单已复核,系统将自动冻结后进入库存履约。",
|
||||
RS_SHORTAGE_REVIEW: "库存存在缺口,当前不能继续上传货代。",
|
||||
CP_READY_MATCH: "库存已就绪,系统将自动执行匹配。",
|
||||
@@ -664,7 +618,6 @@ def _build_task_summary(
|
||||
if checkpoint_kind == CheckpointKind.AUTO_CONTINUE and not (stp_facts and stp_facts.get('multi_source_excel_block')):
|
||||
pause_reason = None
|
||||
pause_reason_code = None
|
||||
allowed_actions = [str(btn.get("id")) for btn in action_buttons if btn.get("id")]
|
||||
event_at = None
|
||||
if task.updated_at is not None:
|
||||
event_at = task.updated_at.isoformat()
|
||||
@@ -681,7 +634,7 @@ def _build_task_summary(
|
||||
else (
|
||||
pause_reason
|
||||
if stp_facts and stp_facts.get('multi_source_excel_block')
|
||||
else _current_todo_label(checkpoint, action_buttons)
|
||||
else _current_todo_label(checkpoint)
|
||||
)
|
||||
),
|
||||
"pause_reason": pause_reason,
|
||||
@@ -693,7 +646,7 @@ def _build_task_summary(
|
||||
),
|
||||
"event_at": event_at,
|
||||
"entry_surface": _entry_surface_for(checkpoint, checkpoint_kind),
|
||||
"allowed_actions": allowed_actions,
|
||||
"allowed_actions": [],
|
||||
}
|
||||
if stp_facts is not None:
|
||||
summary['stp_facts'] = stp_facts
|
||||
@@ -937,23 +890,11 @@ def build_task_ui_state(
|
||||
构建单票任务 UI State。
|
||||
|
||||
核心逻辑:所有 UI 入口只消费这里输出的 stage/checkpoint/todo/actions/summary,
|
||||
禁止 Chat、通知卡与任务中心分别推导状态;有 Execution 时附带统一 Gate 用户摘要;
|
||||
存在 current_blocking_gate 时只输出 Gate actions,禁止旧动作列表穿透。
|
||||
禁止 Chat、通知卡与任务中心分别推导状态;checkpoint 仅保留内部状态/自动推进,
|
||||
可点击用户动作只由 Gate 与已验证 Artifact 授权产生。
|
||||
"""
|
||||
ui = resolve_task_ui_state(task)
|
||||
action_buttons = _action_buttons_for_task(task)
|
||||
process_gate = _process_gate_user_summary_for_task(task)
|
||||
# [STEP] 存在 ProcessExecution 时恢复动作仅由 process_gate 驱动;
|
||||
# 仅保留非恢复类 STP 动作(下载 Excel / 人工上传凭据 / 刷新)。
|
||||
_non_recovery_action_ids = frozenset({'download_excel', 'mark_manual_uploaded', 'refresh'})
|
||||
if isinstance(process_gate, dict):
|
||||
if process_gate.get('current_blocking_gate'):
|
||||
action_buttons = []
|
||||
else:
|
||||
action_buttons = [
|
||||
button for button in action_buttons
|
||||
if str((button or {}).get('id') or '') in _non_recovery_action_ids
|
||||
]
|
||||
lifecycle = _task_lifecycle(task=task, checkpoint=ui.checkpoint, process_gate=process_gate)
|
||||
stage = _business_stage(lifecycle)
|
||||
steps = build_shipping_workflow_steps(task, ui.checkpoint, lifecycle_stage=stage['code'])
|
||||
@@ -963,7 +904,6 @@ def build_task_ui_state(
|
||||
task,
|
||||
ui.checkpoint,
|
||||
checkpoint_kind=ui.checkpoint_kind,
|
||||
action_buttons=action_buttons,
|
||||
)
|
||||
if process_gate is not None:
|
||||
summary['process_gate'] = process_gate
|
||||
@@ -976,7 +916,7 @@ def build_task_ui_state(
|
||||
summary['diagnostic_hint'] = process_gate['diagnostic_hint']
|
||||
if process_gate.get('current_blocking_gate'):
|
||||
summary['allowed_actions'] = []
|
||||
actions = _unified_actions(process_gate=process_gate, action_buttons=action_buttons)
|
||||
actions = _unified_actions(process_gate=process_gate)
|
||||
# [AUTHORITY] Gate 负责当前可写恢复动作;Excel 下载是已产出文件的只读动作,
|
||||
# 两者不能相互覆盖。即使当前 Gate 阻断并清空旧 checkpoint 动作,也只在
|
||||
# Artifact 已通过 resolve_task_export_download 校验时补入下载授权。
|
||||
@@ -985,7 +925,13 @@ def build_task_ui_state(
|
||||
'id': 'download_excel',
|
||||
'label': '下载 Excel',
|
||||
'kind': 'view',
|
||||
'dispatch': 'view',
|
||||
'ui_handler': 'excel_download',
|
||||
'enabled': True,
|
||||
# Artifact 已验证是下载授权的唯一来源;它直接声明展示位置,
|
||||
# 不依赖旧 checkpoint 或 action code 位置映射。
|
||||
'target_surface': 'upload_complete',
|
||||
'target_anchor': 'excel_artifact',
|
||||
}, default_kind='view')
|
||||
action_codes = {
|
||||
str((action or {}).get('code') or '')
|
||||
@@ -993,6 +939,12 @@ def build_task_ui_state(
|
||||
}
|
||||
if download_action['code'] not in action_codes:
|
||||
actions['secondary'].append(download_action)
|
||||
# summary 仅作为 ui_state.actions 的只读镜像,禁止由 checkpoint 或任务字段另行推导。
|
||||
summary['allowed_actions'] = [
|
||||
str(item.get('code'))
|
||||
for item in [actions.get('primary'), *(actions.get('secondary') or [])]
|
||||
if isinstance(item, dict) and str(item.get('code') or '').strip()
|
||||
]
|
||||
stage_context = (
|
||||
_build_stage_context(
|
||||
task,
|
||||
|
||||
Reference in new issue
Block a user