fix(shipping-notice): 任务中心OT直链补case_no锚点并修复工作台装配期懒加载竞态

This commit is contained in:
hugo committed 2026-09-18 01:38:33 +08:00
1 parent 65f751daf4
commit 0333d713e0
6 files changed
+136 -26

No files matched your search

@@ -1468,8 +1468,8 @@ def _inject_unified_processing_fields(task: ShippingNotice, data: dict[str, Any]
order_task_id → ShippingOrderTask。有 OT 时用领域事实映射为
shipping_processing_status(与 shipping_processing_projection 同源),
并注入 shipping_processing_stage / progress_version / order_task_no;
另附带 review_run_no / owner_agent_id / conversation_id(经 OT.extraction_run),
供任务中心「进入订单处理」深链。
另附带 review_run_no / review_case_no / owner_agent_id / conversation_id(经 OT.extraction_run
与 OT 反查确认 Case),供任务中心「进入订单处理」深链。
Args:
task: ShippingNotice 或 ShippingOrderTask。
@@ -1517,6 +1517,19 @@ def _inject_unified_processing_fields(task: ShippingNotice, data: dict[str, Any]
data['conversation_id'] = cid
if data.get('owner_agent_id') is None and getattr(run, 'owner_agent_id', None) is not None:
data['owner_agent_id'] = int(run.owner_agent_id)
# [STEP 3] 注入确认 Case 号:工作台以 case_no 绑定工作项,OT 直链缺失该字段时
# 选法 2 不会拉 Case,任务详情身份链断裂、五阶段页签全锁(2026-09-17 工作台直链修复)。
# confirmed_task_id 唯一约束保证 OT→Case 至多一条,点查代价可忽略。
if order_task is not None and not str(data.get('review_case_no') or '').strip():
confirmed_case = (
ShippingOrderReviewCase.query
.filter_by(confirmed_task_id=int(order_task.id))
.first()
)
if confirmed_case is not None:
case_no = str(confirmed_case.case_no or '').strip()
if case_no:
data['review_case_no'] = case_no
def _enrich_task_center_fields(
@@ -1,11 +1,12 @@
"""
backend/tests/test_shipping_task_center_review_run_deep_link.py
用途:验收任务中心 Notice/OT 摘要注入 review_run_no 与 order_task_no,供 UI-04 深链
与工作台右卡 work-item 投影键。
用途:验收任务中心 Notice/OT 摘要注入 review_run_no / order_task_no / review_case_no,
供 UI-04 深链(run_no + case_no)与工作台右卡 work-item 投影键。
依赖:query_service._inject_unified_processing_fields、ShippingOrderTask、pytest。
逻辑:Notice 挂 OT 时 SUMMARY 必含 review_run_no;直接序列化 OT 时 order_task_no
必须等于自身 task_no(禁止 enrich 冲成 null)。
必须等于自身 task_no(禁止 enrich 冲成 null);OT 有确认 Case 时必须注入
review_case_no(缺它工作台选法 2 不拉 Case、身份链断裂、五阶段页签全锁)。
"""
from __future__ import annotations
@@ -98,3 +99,50 @@ def test_serialize_order_task_keeps_self_order_task_no_after_enrich(app):
assert detail['order_task_no'] == 'OT-TC-OT-SELF-1'
assert detail['task_no'] == 'OT-TC-OT-SELF-1'
assert detail['review_run_no'] == run.run_no
def test_serialize_order_task_injects_confirmed_review_case_no_for_workbench_deeplink(app):
"""
OT 摘要/详情必须携带确认 Case 号,任务中心 OT 直链才能绑定工作台工作项。
关键断言:无 case_no 的 OT 直链下,工作台对正式下游阶段任务走选法 2 不拉 Case,
activeCase/displayCase/confirmedNoticeTaskNo 全空、五阶段页签全锁;
review_case_no 是 openOrderProcessing 追加 case_no 深链参数的唯一来源,
SUMMARY 与 workbench DETAIL 都必须注入。
"""
with app.app_context():
from app.models import ShippingOrderReviewCase
from tests.test_shipping_order_extraction_runs import _seed_run_input
from tests.test_shipping_order_review_service import _materialized_run
user, agent, session, intake, document = _seed_run_input(suffix='TC-CASE-LINK')
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
order_task = ShippingOrderTask(
task_no='OT-TC-CASE-LINK-1',
user_id=user.id,
conversation_id=session.session_id,
extraction_run_id=int(run.id),
owner_agent_id=int(agent.id),
status='blocked',
stage='inventory_fetching',
progress_version=2,
)
db.session.add(order_task)
db.session.flush()
# 模拟 RPA 超时阻断的正式下游 OT:存在一条已确认绑定该 OT 的复核 Case。
case = ShippingOrderReviewCase(
case_no='SNRC-TC-CASE-LINK', run_id=int(run.id),
unit_id=int(run.extraction_plan.units[0].id),
document_id=int(document.id), owner_user_id=user.id,
status='confirmed', confirmed_task_id=int(order_task.id),
)
db.session.add(case)
db.session.commit()
summary = serialize_task_summary(order_task, viewer_user_id=user.id)
detail = serialize_task_detail(
order_task, viewer_user_id=user.id, include_stage_context=True, view='workbench',
)
# 关键断言:SUMMARY / workbench DETAIL 均注入确认 Case 号(深链 case_no 锚点)。
assert summary['review_case_no'] == 'SNRC-TC-CASE-LINK'
assert detail['review_case_no'] == 'SNRC-TC-CASE-LINK'
@@ -17,6 +17,16 @@
**批量操作**:仅「货代上传」阶段的正式 Notice 行有复选框(`isFreightUploadRow`),勾选 ≥1 后浮出深色操作条(下载 ZIP / 确认已上传 / 发起 RPA / 清除),无常驻工具栏;修复批量按钮 i18n 裸 key(`workspace.shippingNotice.batch.*` 此前误挂 `schedule.batch`,已在四语言归位补齐)。新增页面文案(表格/终态角标/子视图/抽屉/报表列头等)已同步 zh-CN / zh-TW / en / th。
## 任务中心 OT 直链工作台:深链补 Case 锚点 + 任务详情兜底(2026-09-17)
**背景缺陷**:我的待办抽屉对 task 类待办(OT/Notice)发出的「进入订单生命周期工作台」深链只有 `run_no + lifecycle_stage + conversation_id + task_no`,**没有 `case_no`**(后端 task 投影从不注入 `review_case_no`)。处于正式下游阶段(通知准备/货代上传)的 OT 进工作台后,队列项命中 `isFormalDownstreamNavItem`(选法 2)刻意不拉 Case → `activeCase` 恒空 → `displayCase/activeReviewNavItem/confirmedNoticeTaskNo` 全部解析为空 → `loadFormalTaskDetail` 空号早退、挂载时已按 `route.query.task_no` 预取的任务详情被丢弃 → `lifecycleUiState` 三级裁决(activeCase → formalTaskDetail → 队列项 entries)全部落空,五阶段页签全锁(「请先完成当前阶段」)+「当前步骤需要人工处理」空壳。处于订单复核阶段的任务不受影响(不命中选法 2,Case 正常加载),因此缺陷只在被 Gate 阻断的下游阶段任务上暴露。
**后端**(`query_service._inject_unified_processing_fields`,列表与详情同源):解析出权威 OT 后按 `ShippingOrderReviewCase.confirmed_task_id`(唯一约束)反查确认 Case,为 task 类待办注入 `review_case_no`;`openOrderProcessing` 既有逻辑检测到该字段即自动追加 `case_no` 深链参数,工作台由此可直接绑定工作项。
**前端**(`ShippingOrderReviewView`):新增 `deepLinkOrderTaskNo`(只认 `OT-` 前缀,SN 号不作 work-item 键);`loadFormalTaskDetail` 在 `confirmedNoticeTaskNo` 为空**且不存在任何 Case 上下文**(`displayCase` 为空,即选法 2 直链态)时回退深链 OT 号,使挂载预取被消费;`onMounted` 在深链携带 OT 号时显式触发一次(复用预取请求,不重复拉取)。已有 Case 上下文时禁止回退,防止深链 OT 串到用户切换后的其他文件。回看前置阶段(如订单复核)的 Case 数据由既有 `REVIEW_EDITOR_NEEDED_STAGES` 懒加载 watcher 按深链 `case_no` 补拉,不改变选法 2 的性能契约。
**连带修复(同日)——懒加载与初次装配的代际竞态**:上述修复让 `formalTaskDetail` 首次可在装配期落地,暴露一个既有缺陷——阶段懒加载 watcher 随之触发的 `loadReviewCase` 会自增 `caseLoadGeneration`,令在途 `load()` 的数据装配全部按代际失效,且其 `finally` 在代际守卫**之后**才清 `initialLoading`,首屏永久卡在「正在加载复核结果...」、run/queue 永不装配。两层收口:① 懒加载 watcher 源改为 `[lifecycleActiveStageCode, initialLoading, runLoading]`,装配期(任一旗为真)让位,装配完成后由旗标翻转重新触发、按当前 stage 补拉 Case;② `load()` 的 `finally` 中 `initialLoading` 清旗移到代际守卫之前(该旗仅由 `isInitialLoad` 的本次 load 置位,无条件收尾语义正确),即使未来出现新的代际接管方,壳也只会短暂缺数据而不会永久卡死。
## 阻塞原因具体化:资格快照回退 + 原因/动作语义分离(2026-09-17)
**背景**:批次中心与工作台「当前任务」对建单前 Review Case 一律显示兜底文案「当前步骤需要人工处理」(同卡重复两遍),而具体原因(如 `customer_unresolved`「客户尚未确认」)早已随资格评估持久化在 `draft.validation_result_json.issues[].explainability`,只是从未进入 `blocking_reason` 通道。
@@ -3064,6 +3074,10 @@ SHIPPING_NOTICE_RPA_RECEIPT_TIMEOUT_SECONDS=900
| Windows 本地联调 | 本地后端;默认 `backend/data/shipping_notice/freight_receipt_rpa/*` | 当前项目 `scripts/rpa/receipt/`;`dev` | 不连 test/prod、不用 test/prod Key;`-Mock` 可全链路演练 |
| Linux 测试服务器 | `/mnt/hxops-rpa-test-data/freight_receipt_rpa/*`;`.env.test` | `C:\HxopsRpaTest\data\freight_receipt_rpa`;`test` | 与库存测试共用同一 SMB 共享与挂载 |
| Linux 正式服务器 | `/mnt/hxops-rpa-prod-data/freight_receipt_rpa/*`;`.env.prod` | `C:\HxopsRpaProd\data\freight_receipt_rpa`;`prod` | 测试真实链路验收通过后再开启正式排程 |
| `SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR` | dev `data/shipping_notice/freight_receipt_rpa/receipt_triggers`;test `/mnt/hxops-rpa-test-data/freight_receipt_rpa/receipt_triggers`;prod `/mnt/hxops-rpa-prod-data/freight_receipt_rpa/receipt_triggers` | 与后端同一物理目录(test `C:\HxopsRpaTest\data\freight_receipt_rpa\receipt_triggers`;prod `C:\HxopsRpaProd\data\freight_receipt_rpa\receipt_triggers`) | 本地联调两端默认一致,无需配置 |
| `SHIPPING_NOTICE_RPA_SHARED_RECEIPT_DROP_DIR` | dev `data/shipping_notice/freight_receipt_rpa/receipt_drop`;test `/mnt/hxops-rpa-test-data/freight_receipt_rpa/receipt_drop`;prod `/mnt/hxops-rpa-prod-data/freight_receipt_rpa/receipt_drop` | 与后端同一物理目录(test `C:\HxopsRpaTest\data\freight_receipt_rpa\receipt_drop`;prod `C:\HxopsRpaProd\data\freight_receipt_rpa\receipt_drop`) | 本地联调两端默认一致,无需配置 |
收料 trigger/drop 目录必须与 Windows 收料 Worker 上 `start_receipt_worker.ps1` 读取的同名变量指向**同一物理目录**;目录内子结构(processing/processed/failed)由统一契约管理,见 `scripts/rpa/README.md`。
Windows 本地联调(项目根目录 PowerShell;本地后端默认目录与 Worker 指向一致,无需配置目录变量):
@@ -1186,8 +1186,11 @@ export function useShippingOrderReview(options: {
statusMessage.value = null;
}
} finally {
if (generation !== caseLoadGeneration) return;
// [2026-09-17] initialLoading 仅由 isInitialLoad 的本 load 置位,必须无条件收尾:
// 被 loadReviewCase 等懒加载路径接管代际时,代际守卫之后的清旗会被跳过,
// 首屏永久卡在「正在加载复核结果...」。
if (isInitialLoad) initialLoading.value = false;
if (generation !== caseLoadGeneration) return;
runLoading.value = false;
// 跨 Run 的 beginCrossRunSwitch 会提前打开 caseSwitchLoading;整页 load 收尾必须关掉。
caseSwitchLoading.value = false;
@@ -1363,6 +1363,9 @@ onMounted(() => {
document.addEventListener('keydown', onExceptionNavKeydown, true);
// [PERF] 深链进入时尽早并行发起任务详情,与 load() 重叠,削减首屏串行加载。
prefetchDeepLinkedTaskDetail();
// OT 直链(无 case_no)下 confirmedNoticeTaskNo 恒空、watch(hasFormalOt) 永不触发;
// 挂载即消费深链预取(复用同一请求,不重复拉取),任务详情才能落地驱动五阶段页签。
if (deepLinkOrderTaskNo.value) void loadFormalTaskDetail();
});
onBeforeUnmount(() => {
@@ -2430,6 +2433,15 @@ const confirmedNoticeTaskNo = computed(() => String(
|| '',
).trim());
/**
* 深链显式携带的 OT 号(任务中心抽屉等 OT 直链)。
* 仅认 OT- 前缀;Notice 的 SN 号不是 work-item 键,与 externalOrderTaskNo 同一口径。
*/
const deepLinkOrderTaskNo = computed(() => {
const taskNo = String(route.query.task_no || '').trim();
return taskNo.startsWith('OT-') ? taskNo : '';
});
const freightNoticeGroups = ref<ShippingFreightNoticeGroup[]>([]);
const freightNoticeGroupsLoading = ref(false);
const freightNoticeGroupsReason = ref<string | null>(null);
@@ -2845,7 +2857,12 @@ async function handleManualUploadSuccess() {
* 拉取确认后的 Notice 履约详情,供 Gate Action 与 Artifact 视图使用。
*/
async function loadFormalTaskDetail() {
const taskNo = confirmedNoticeTaskNo.value;
// 深链 OT 兜底:无 case_no 的 OT 直链下选法 2 不拉 Case,activeCase/displayCase
// 均为空、confirmedNoticeTaskNo 恒空;此时必须消费深链 task_no,否则挂载预取的
// 任务详情被丢弃、五阶段页签无身份可裁决(全锁死)。一旦存在任何 Case 上下文
// 则禁止回退,防止深链 OT 串到用户切换后的其他文件。
const taskNo = confirmedNoticeTaskNo.value
|| (displayCase.value ? '' : deepLinkOrderTaskNo.value);
const generation = ++formalTaskDetailGeneration;
if (!taskNo) {
formalTaskDetail.value = null;
@@ -4539,8 +4556,13 @@ watch(
// 用户查看面(含回看已完成阶段)驱动 Case 懒加载:选法 2 正式下游切 PDF 后 activeCase
// 为 null,回看接收解析/订单复核/通知准备时必须按需补拉目标 Case,否则这些工作面
// 只能渲染空白或残留上一份 PDF 的数据。
lifecycleActiveStageCode,
(stage) => {
// [2026-09-17] 初次装配(initialLoading/runLoading)未完成前必须让位:loadReviewCase
// 会自增 caseLoadGeneration,令在途 load() 的 finally 跳过 initialLoading 清旗,
// 首屏永久卡在「正在加载复核结果...」且 run/queue 永不装配。装配完成后由旗标
// 翻转重新触发本 watcher,按当前 stage 补拉 Case。
[lifecycleActiveStageCode, initialLoading, runLoading],
([stage]) => {
if (initialLoading.value || runLoading.value) return;
if (!stage || !REVIEW_EDITOR_NEEDED_STAGES.includes(stage)) return;
// 禁止使用 displayCase 兜底:它可能停留在上一份 PDF 的快照上造成串味;
// 目标一律取当前工作面的 activeCase 或切换管线的 requestedCaseNo。
@@ -142,6 +142,16 @@ const lineRows = computed(() => {
return Array.isArray(item?.notice_line_summary) ? item!.notice_line_summary : [];
});
/**
* 数量/缺口展示值:后端 Numeric(24,8) 透出形如 "24.00000000",
* 统一转 number 去尾零(24.00000000→24、2.50000000→2.5),缺失保持 —。
*/
function formatQty(value: unknown): string {
if (value === null || value === undefined || value === '') return '—';
const num = Number(value);
return Number.isFinite(num) ? String(num) : String(value);
}
watch(() => props.item, (item) => {
if (!item) return;
const stage = defaultLifecycleTarget(item);
@@ -173,7 +183,7 @@ onBeforeUnmount(() => document.removeEventListener('keydown', onEsc));
data-testid="my-todos-drawer-scrim"
@click="emit('close')"
/>
<aside class="flex w-[34rem] max-w-[94vw] flex-col bg-surface shadow-2xl">
<aside class="flex w-[52rem] max-w-[94vw] flex-col bg-surface shadow-2xl">
<div class="border-b border-default px-5 py-4">
<div class="flex items-start justify-between gap-3">
<h3 class="break-all font-mono text-base font-bold text-primary" data-testid="my-todos-drawer-title">
@@ -238,14 +248,14 @@ onBeforeUnmount(() => document.removeEventListener('keydown', onEsc));
<table class="w-full border-collapse text-xs" data-testid="my-todos-drawer-lines">
<thead>
<tr class="border-b border-default bg-surface-soft/60 text-left text-muted">
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.lineNo') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.partNumber') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.customerPartNumber') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.reservationId') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.shipmentQty') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.availableQty') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.shortageQty') }}</th>
<th class="px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.status') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.lineNo') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.partNumber') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.customerPartNumber') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.reservationId') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.shipmentQty') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.availableQty') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.shortageQty') }}</th>
<th class="whitespace-nowrap px-2.5 py-2 font-medium">{{ $t('workspace.shippingNotice.myTodos.drawer.lineTable.status') }}</th>
</tr>
</thead>
<tbody>
@@ -255,18 +265,18 @@ onBeforeUnmount(() => document.removeEventListener('keydown', onEsc));
class="border-b border-[#f0f3f8]"
>
<td class="px-2.5 py-2 font-mono">{{ line.line_no }}</td>
<td class="px-2.5 py-2 font-mono">{{ line.part_number || '—' }}</td>
<td class="px-2.5 py-2">{{ line.customer_part_number || '—' }}</td>
<td class="px-2.5 py-2 font-mono">{{ line.reservation_id || '—' }}</td>
<td class="px-2.5 py-2 tabular-nums">{{ line.shipment_qty ?? '—' }}</td>
<td class="px-2.5 py-2 tabular-nums">{{ line.available_qty ?? '—' }}</td>
<td class="whitespace-nowrap px-2.5 py-2 font-mono">{{ line.part_number || '—' }}</td>
<td class="whitespace-nowrap px-2.5 py-2">{{ line.customer_part_number || '—' }}</td>
<td class="whitespace-nowrap px-2.5 py-2 font-mono">{{ line.reservation_id || '—' }}</td>
<td class="whitespace-nowrap px-2.5 py-2 tabular-nums">{{ formatQty(line.shipment_qty) }}</td>
<td class="whitespace-nowrap px-2.5 py-2 tabular-nums">{{ formatQty(line.available_qty) }}</td>
<td
class="px-2.5 py-2 tabular-nums"
class="whitespace-nowrap px-2.5 py-2 tabular-nums"
:class="Number(line.shortage_qty || 0) > 0 ? 'font-bold text-red-600' : ''"
>
{{ line.shortage_qty ?? '—' }}
{{ formatQty(line.shortage_qty) }}
</td>
<td class="px-2.5 py-2">{{ line.inventory_status || '—' }}</td>
<td class="whitespace-nowrap px-2.5 py-2">{{ line.inventory_status || '—' }}</td>
</tr>
</tbody>
</table>