Merge branch 'hugo-auto-transfer' into dev

# Conflicts:
#	backend/app/api/shipping_notice_tools.py
This commit is contained in:
hugo committed 2026-09-30 00:34:28 +08:00
commit 6cf71679b7
143 files changed
+10145 -2132

No files matched your search

+11 -2
View File
@@ -221,9 +221,18 @@ export const getTransferBacklogSummary = () =>
export const listTransferSources = () =>
requestJson<TransferSourceOption[]>(`${BASE}/sources`, { headers: getAuthHeaders() });
/** 对指定来源重新触发一次收料 RPA 抓取 */
/** retry-rpa 响应:parse_failed 本地重解析路径返回 {ok, file_status, reparsed};RPA 触发路径返回原状态投影 */
export interface TransferRetryRpaReparseResult {
source_code: string;
ok: boolean;
file_status: TransferSourceFileStatus['file_status'];
reparsed: true;
}
/** 来源重试(解析失败分层 2026-09-29):parse_failed 先本地重解析返回 200 reparse 结果,
* 其余状态重新触发一次收料 RPA 抓取(202 + fetching / 配置缺失 fail-closed) */
export const retryTransferSourceRpa = (sourceCode: string) =>
requestJson<TransferSourceFileStatus>(`${BASE}/sources/${encodeURIComponent(sourceCode)}/retry-rpa`, {
requestJson<TransferRetryRpaReparseResult | TransferSourceFileStatus>(`${BASE}/sources/${encodeURIComponent(sourceCode)}/retry-rpa`, {
method: 'POST',
headers: jsonHeaders(),
});
@@ -3,15 +3,18 @@
* 用途:消息列表主区域(滚动容器、欢迎页、气泡与思考中占位)。
* 依赖:ChatMessageBubble、各类进度卡、chat.types。
* 逻辑:按 shouldRenderMessage 过滤;货代抽取卡按 run / upload_batch / client_submission 去重只留最后一张;
* 用户气泡在下方已有抽取进度卡时对附件启用 summaryOnly,避免与进度卡重复堆文件明细。
* 用户气泡在下方已有抽取进度卡时对附件启用 summaryOnly,避免与进度卡重复堆文件明细;
* 在途调拨 Agent 首页看板在会话引导期并行预取(prefetchTransferHomeBoard 单飞)。
*/
<script setup lang="ts">
import { watch } from 'vue';
import type { Ref } from 'vue';
import ChatWelcomePanel, { type WelcomeQuestionItem, type WelcomeQuestionSection } from './ChatWelcomePanel.vue';
import ChatThinkingBubble from './ChatThinkingBubble.vue';
import ChatMessageBubble, { type ChatMessageBubbleHandlers } from './messages/ChatMessageBubble.vue';
import TransferHomePanel from './messages/TransferHomePanel.vue';
import ToolRunProgressCard from './ToolRunProgressCard.vue';
import { prefetchTransferHomeBoard } from '../composables/useChatTransfer';
import type { LeaveMessageHandlers } from './messages/LeaveMessageBlock.vue';
import type { ShippingMessageHandlers } from './messages/shippingMessageHandlers';
import type { TrainingHandlers } from './messages/TrainingExamQuestionMessage.vue';
@@ -24,6 +27,7 @@ const {
messages,
shouldRenderMessage,
scrollContainerHolder,
isInTransitTransferAgent,
} = defineProps<{
messages: ChatMessage[];
agentName: string;
@@ -75,6 +79,15 @@ const bindScrollContainer = (node: unknown) => {
scrollContainerHolder.el.value = (node as HTMLElement | null) ?? null;
};
// 在途调拨首页看板预取:面板挂在消息流内(messages 空判),原先等会话消息返回才发
// 看板请求(串行白等会话引导 ~1.5s);这里在「该 Agent 且当前无消息」确立时即预取,
// 面板挂载后命中同一 Promise(consume-once 单飞,见 useChatTransfer.prefetchTransferHomeBoard)。
watch(
() => Boolean(isInTransitTransferAgent) && messages.length === 0,
(active) => { if (active) prefetchTransferHomeBoard(); },
{ immediate: true },
);
/**
* 生成稳定的消息 key,避免切换历史会话时仅因条数相同而复用旧气泡组件。
* 核心逻辑:优先使用服务端/本地消息 ID,其次拼接角色、run_id 与内容摘要。
@@ -2,7 +2,7 @@
features/chat/components/messages/TransferBacklogSummaryCard.vue
用途:待处理异常卡(可恢复/已关闭/结果未知三组)——列与匹配窗口一致,
支持关键字/结果筛选、多选批量操作(重查/恢复处理/标记无需处理)与行级快捷操作。
依赖:props.items、i18n chat.transfer.*、transferBatch.deriveBatchNo。
依赖:props.items、i18n chat.transfer.*、transferBatch.deriveBatchNo、transferFormat.formatQuantity。
逻辑:仅 blocked_recoverable 可勾选与操作;result_unknown / manually_closed 只读;
可恢复行按 result_code 细分徽标(blocked_file_removed=文件已移除);
blocked_file_removed 行行内仅留「标记无需继续处理」(重查不可恢复——消失证据
@@ -12,6 +12,7 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { deriveBatchNo } from './transferBatch';
import { formatQuantity } from './transferFormat';
import type { TransferBacklogItem } from '../../types/transfer.types';
const props = defineProps<{
@@ -199,7 +200,7 @@ function resultLabelKey(item: TransferBacklogItem): string {
</div>
<div v-if="filtered.length" class="overflow-x-auto">
<table class="w-full min-w-[1180px] text-xs" data-testid="transfer-backlog-table">
<table class="w-full min-w-[1360px] text-xs" data-testid="transfer-backlog-table">
<thead>
<tr class="border-b border-default bg-surface-soft text-left text-[11px] text-muted">
<th class="p-2">
@@ -210,19 +211,20 @@ function resultLabelKey(item: TransferBacklogItem): string {
@change="toggleAll(($event.target as HTMLInputElement).checked)"
/>
</th>
<th class="p-2">{{ $t('chat.transfer.colSource') }}</th>
<th class="p-2">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
<th class="p-2">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="p-2">{{ $t('chat.transfer.colName') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromQty') }}</th>
<th class="p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
<th class="p-2">{{ $t('chat.transfer.colToQty') }}</th>
<th class="p-2">{{ $t('chat.transfer.colResult') }}</th>
<th class="p-2">{{ $t('chat.transfer.colAging') }}</th>
<th class="p-2">{{ $t('chat.transfer.colAction') }}</th>
<!-- 表头全列 nowrap:防「拨出仓库/匹配结果」等折行;品名列吃剩余宽度 -->
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colSource') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colName') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromQty') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colToQty') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colResult') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colAging') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colAction') }}</th>
</tr>
</thead>
<tbody>
@@ -242,19 +244,21 @@ function resultLabelKey(item: TransferBacklogItem): string {
@change="toggleRow(item, ($event.target as HTMLInputElement).checked)"
/>
</td>
<td class="p-2">{{ item.source_code }}</td>
<td class="p-2 font-semibold">{{ item.invoice_no }}</td>
<td class="p-2">{{ item.receipt_date || '—' }}</td>
<td class="p-2">{{ item.material_no }}</td>
<!-- 除品名外全列 nowrap:日期/仓库/料号带连字符,列宽不足时从连字符处折行;
操作列三按钮保持一行 -->
<td class="whitespace-nowrap p-2">{{ item.source_code }}</td>
<td class="whitespace-nowrap p-2 font-semibold">{{ item.invoice_no }}</td>
<td class="whitespace-nowrap p-2">{{ item.receipt_date || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ item.material_no }}</td>
<td class="p-2">{{ item.material_name || '—' }}</td>
<td class="p-2">{{ item.from_warehouse || '—' }}</td>
<td class="p-2">{{ deriveBatchNo(item.lot_no ?? '') || '—' }}</td>
<td class="p-2">{{ item.external_quantity ?? '—' }}</td>
<td class="p-2">{{ item.to_warehouse || '—' }}</td>
<td class="p-2">{{ item.receipt_quantity ?? '—' }}</td>
<td class="whitespace-nowrap p-2">{{ item.from_warehouse || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ deriveBatchNo(item.lot_no ?? '') || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ formatQuantity(item.external_quantity) }}</td>
<td class="whitespace-nowrap p-2">{{ item.to_warehouse || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ formatQuantity(item.receipt_quantity) }}</td>
<td class="p-2">
<span
class="rounded-full px-2 py-0.5 font-bold"
class="whitespace-nowrap rounded-full px-2 py-0.5 font-bold"
:class="{
'bg-red-50 text-red-700': item.status === 'blocked_recoverable',
'bg-amber-50 text-amber-700': item.status === 'result_unknown',
@@ -268,8 +272,8 @@ function resultLabelKey(item: TransferBacklogItem): string {
}}
</span>
</td>
<td class="p-2">{{ $t(agingLabel(item.aging_level)) }}</td>
<td class="p-2">
<td class="whitespace-nowrap p-2">{{ $t(agingLabel(item.aging_level)) }}</td>
<td class="whitespace-nowrap p-2">
<template v-if="isActionable(item)">
<!-- 失效行(文件已移除)隐藏重查/恢复处理:重查会被后端拒绝
(TRANSFER.RETRY_NOT_ALLOWED),恢复处理也无济于事,只留关闭出口 -->
@@ -287,20 +291,22 @@ function resultLabelKey(item: TransferBacklogItem): string {
v-if="!isFileRemoved(item)"
type="button"
class="mr-1 rounded border border-brand-200 px-1 py-0.5 text-[10px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:title="$t('chat.transfer.resumeAction')"
:data-testid="`transfer-backlog-resume-${item.invoice_no}`"
:disabled="busy"
@click="emit('resume', [item.item_id])"
>
{{ $t('chat.transfer.resumeAction') }}
{{ $t('chat.transfer.resumeActionShort') }}
</button>
<button
type="button"
class="rounded border border-red-200 px-1 py-0.5 text-[10px] font-bold text-red-600 transition hover:bg-red-50 disabled:opacity-40"
:title="$t('chat.transfer.manualClose')"
:data-testid="`transfer-backlog-close-${item.invoice_no}`"
:disabled="busy"
@click="emit('close', item)"
>
{{ $t('chat.transfer.manualClose') }}
{{ $t('chat.transfer.manualCloseShort') }}
</button>
</template>
<span v-else-if="item.status === 'result_unknown'" class="text-[11px] text-muted">
@@ -9,6 +9,7 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { deriveBatchNo } from './transferBatch';
import { formatQuantity } from './transferFormat';
import type { TransferMatchingItem } from '../../types/transfer.types';
const props = defineProps<{
@@ -115,7 +116,7 @@ function checkedTime(item: TransferMatchingItem): string {
</div>
<div v-if="filtered.length" class="overflow-x-auto">
<table class="w-full min-w-[1100px] text-xs" data-testid="transfer-executable-table">
<table class="w-full min-w-[1240px] text-xs" data-testid="transfer-executable-table">
<thead>
<tr class="border-b border-default bg-surface-soft text-left text-[11px] text-muted">
<th class="p-2">
@@ -126,18 +127,19 @@ function checkedTime(item: TransferMatchingItem): string {
@change="toggleAll(($event.target as HTMLInputElement).checked)"
/>
</th>
<th class="p-2">{{ $t('chat.transfer.colSource') }}</th>
<th class="p-2">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
<th class="p-2">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="p-2">{{ $t('chat.transfer.colName') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromQty') }}</th>
<th class="p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
<th class="p-2">{{ $t('chat.transfer.colToQty') }}</th>
<th class="p-2">{{ $t('chat.transfer.colResult') }}</th>
<th class="p-2">{{ $t('chat.transfer.colAction') }}</th>
<!-- 表头全列 nowrap:防「拨出仓库/投入数量」等折行;品名列吃剩余宽度 -->
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colSource') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colName') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromQty') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colToQty') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colResult') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colAction') }}</th>
</tr>
</thead>
<tbody>
@@ -157,21 +159,22 @@ function checkedTime(item: TransferMatchingItem): string {
@change="toggleRow(item, ($event.target as HTMLInputElement).checked)"
/>
</td>
<td class="p-2">{{ item.source_code }}</td>
<td class="p-2 font-semibold">{{ item.invoice_no }}</td>
<td class="p-2">{{ item.receipt_date || '—' }}</td>
<td class="p-2">{{ item.material_no }}</td>
<!-- 除品名外全列 nowrap:日期/仓库/料号带连字符,列宽不足时从连字符处折行 -->
<td class="whitespace-nowrap p-2">{{ item.source_code }}</td>
<td class="whitespace-nowrap p-2 font-semibold">{{ item.invoice_no }}</td>
<td class="whitespace-nowrap p-2">{{ item.receipt_date || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ item.material_no }}</td>
<td class="p-2">{{ item.material_name }}</td>
<td class="p-2">{{ item.from_warehouse }}</td>
<td class="p-2">{{ deriveBatchNo(item.lot_no ?? '') || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ item.from_warehouse }}</td>
<td class="whitespace-nowrap p-2">{{ deriveBatchNo(item.lot_no ?? '') || '—' }}</td>
<td class="p-2">
{{ item.from_quantity ?? '—' }}
{{ formatQuantity(item.from_quantity) }}
<div v-if="checkedTime(item)" class="text-[10px] text-muted">{{ checkedTime(item) }}</div>
</td>
<td class="p-2">{{ item.to_warehouse }}</td>
<td class="p-2">{{ item.to_quantity }}</td>
<td class="whitespace-nowrap p-2">{{ item.to_warehouse }}</td>
<td class="whitespace-nowrap p-2">{{ formatQuantity(item.to_quantity) }}</td>
<td class="p-2">
<span class="rounded-full bg-emerald-50 px-2 py-0.5 font-bold text-emerald-700" data-testid="transfer-executable-result">
<span class="whitespace-nowrap rounded-full bg-emerald-50 px-2 py-0.5 font-bold text-emerald-700" data-testid="transfer-executable-result">
{{ $t('chat.transfer.resultExecutable') }}
</span>
<div v-if="item.stale" class="mt-0.5 text-[10px] text-amber-600">{{ $t('chat.transfer.staleRow') }}</div>
@@ -37,7 +37,7 @@ const FAILED_TICKET = {
created_at: '2026-09-20T08:00:00',
run_no: 'RUN-1',
items: [
{ invoice_no: 'INV-A', material_no: 'MAT-A', material_name: '物料A', lot_no: 'LOT-A', quantity: '500', unit: '个' },
{ invoice_no: 'INV-A', material_no: 'MAT-A', material_name: '物料A', lot_no: 'WTP26062302', quantity: '500', unit: '个' },
{ invoice_no: 'INV-B', material_no: 'MAT-B', material_name: '物料B', lot_no: 'LOT-B', quantity: '300', unit: 'PCS' },
],
};
@@ -161,6 +161,10 @@ describe('TransferExecutedOrders 已执行明细列表子视图', () => {
// [断言意图] 展开=invoice 粒度行明细(逐 Invoice 行可见)。
expect(items.text()).toContain('INV-A');
expect(items.text()).toContain('INV-B');
// [断言意图] 拨出批号上屏为外部形态(WTP→HOW 展示侧镜像,2026-09-29):
// 行数据保持文件原形 WTP26062302,展示必须转为 HOW26062302。
expect(items.text()).toContain('HOW26062302');
expect(items.text()).not.toContain('WTP26062302');
expect(wrapper.find('[data-testid="transfer-executed-retry-D-FAIL-1"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-executed-close-D-FAIL-1"]').exists()).toBe(true);
});
@@ -1,17 +1,20 @@
<!--
features/chat/components/messages/TransferExecutedOrders.vue
用途:「已执行调拨单」明细列表子视图(首页统计卡片下钻目标,与待办/可调拨
用途:「执行看板」明细列表子视图(首页统计卡片下钻目标,与待办/可调拨
子视图同模式)——工具栏(← 返回 + 全部 + 日期范围 + 刷新)+ 单分组列表
(单行点击展开 invoice 粒度明细;failed 行 [重查]+单据级 [关闭单];
result_unknown 行仅 [重新触发],D11 无关闭入口)+ 上一页/下一页分页;
result_unknown 行仅 [重新触发],D11 无关闭入口;动作按钮与状态徽标
同簇靠右、紧跟状态展示,2026-09-29 布局调整)+ 上一页/下一页分页;
无自动轮询(进入拉一次 + 手动刷新)。
依赖:transfer.api(fetchExecutedOrders/closeTransferDocument/retriggerTransferDocument)、
transferBatch.deriveBatchNo(拨出批号展示侧 WTP→HOW 镜像)、
useMessage、i18n chat.transfer.homeExecuted.*。
逻辑:props.initialGroup(首页卡片点击带入的初始分组,''=全部)→ mounted→load;
[全部] 点击→清 statusGroup+page=1;日期范围变更→page=1+load;[返回]→
emit('back') 由首页面板切回卡片视图;关闭单走 D18 原因必填弹窗(同单行
影响面 + 「关闭调拨单≠ERP 无单」红线)→close→load。行为与融合卡
(TransferResultCard)一致。分组计数恒全量由后端保证,本视图不消费计数
[全部] 点击→清 statusGroup+page=1;日期范围变更→page=1+load(后端按收料
日期过滤);[返回]→emit('back') 由首页面板切回卡片视图;关闭单走 D18
原因必填弹窗(同单行影响面 + 「关闭调拨单≠ERP 无单」红线)→close→load。
行为与融合卡(TransferResultCard)一致。列表排序(收料日期→数据源→库位
升序)与分组计数恒全量由后端保证,本视图不消费计数
(计数展示在首页 TransferExecutedCards)。
-->
<script setup lang="ts">
@@ -24,6 +27,7 @@ import {
retryTransferOrder,
retriggerTransferDocument,
} from '../../api/transfer.api';
import { deriveBatchNo } from './transferBatch';
import type {
TransferExecutedOrder,
} from '../../types/transfer.types';
@@ -255,55 +259,51 @@ onMounted(() => { void load(); });
{{ order.receipt_date || '—' }} · {{ order.from_warehouse }}→{{ order.to_warehouse }}
· {{ $t('chat.transfer.materialCount', { count: order.items.length }) }}
</span>
<span
class="rounded-full px-2 py-0.5 font-bold"
:class="{
'bg-emerald-50 text-emerald-700': order.status_group === 'success',
'bg-sky-50 text-sky-700': order.status_group === 'executing',
'bg-red-50 text-red-700': order.status_group === 'failed',
'bg-amber-50 text-amber-700': order.status_group === 'result_unknown',
}"
:data-testid="`transfer-executed-status-${order.doc_no}`"
>
{{ orderBadgeText(order) }}
</span>
</div>
<!-- 单据级行内动作(D11/D18:result_unknown 仅重新触发;failed 行重查 + 单据级关闭单) -->
<div
v-if="order.status === 'result_unknown' || isFailedOrder(order)"
class="flex flex-wrap gap-2 px-3 pb-2"
>
<button
v-if="order.status === 'result_unknown'"
type="button"
class="rounded border border-amber-300 px-2 py-0.5 text-[11px] font-bold text-amber-700 transition hover:bg-amber-50 disabled:opacity-40"
:data-testid="`transfer-executed-retrigger-${order.doc_no}`"
:disabled="actionBusy"
@click.stop="onRetrigger(order)"
>
{{ $t('chat.transfer.orderAction.retrigger') }}
</button>
<template v-if="isFailedOrder(order)">
<button
type="button"
class="rounded border border-brand-200 px-2 py-0.5 text-[11px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:data-testid="`transfer-executed-retry-${order.doc_no}`"
:disabled="actionBusy"
@click.stop="onRetry(order)"
<!-- 状态徽标与单据级行内动作(D11/D18)同簇靠右:处置动作紧跟状态,扫读动线「状态→处置」 -->
<div class="flex flex-wrap items-center gap-2">
<span
class="rounded-full px-2 py-0.5 font-bold"
:class="{
'bg-emerald-50 text-emerald-700': order.status_group === 'success',
'bg-sky-50 text-sky-700': order.status_group === 'executing',
'bg-red-50 text-red-700': order.status_group === 'failed',
'bg-amber-50 text-amber-700': order.status_group === 'result_unknown',
}"
:data-testid="`transfer-executed-status-${order.doc_no}`"
>
{{ $t('chat.transfer.orderAction.retry') }}
</button>
{{ orderBadgeText(order) }}
</span>
<button
v-if="order.status === 'result_unknown'"
type="button"
class="rounded border border-red-200 px-2 py-0.5 text-[11px] font-bold text-red-700 transition hover:bg-red-50 disabled:opacity-40"
:data-testid="`transfer-executed-close-${order.doc_no}`"
class="rounded border border-amber-300 px-2 py-0.5 text-[11px] font-bold text-amber-700 transition hover:bg-amber-50 disabled:opacity-40"
:data-testid="`transfer-executed-retrigger-${order.doc_no}`"
:disabled="actionBusy"
@click.stop="openCloseDialog(order)"
@click.stop="onRetrigger(order)"
>
{{ $t('chat.transfer.orderAction.closeOrder') }}
{{ $t('chat.transfer.orderAction.retrigger') }}
</button>
</template>
<template v-if="isFailedOrder(order)">
<button
type="button"
class="rounded border border-brand-200 px-2 py-0.5 text-[11px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:data-testid="`transfer-executed-retry-${order.doc_no}`"
:disabled="actionBusy"
@click.stop="onRetry(order)"
>
{{ $t('chat.transfer.orderAction.retry') }}
</button>
<button
type="button"
class="rounded border border-red-200 px-2 py-0.5 text-[11px] font-bold text-red-700 transition hover:bg-red-50 disabled:opacity-40"
:data-testid="`transfer-executed-close-${order.doc_no}`"
:disabled="actionBusy"
@click.stop="openCloseDialog(order)"
>
{{ $t('chat.transfer.orderAction.closeOrder') }}
</button>
</template>
</div>
</div>
<!-- 展开明细(invoice 粒度行集) -->
@@ -327,7 +327,9 @@ onMounted(() => { void load(); });
<td class="p-1">{{ item.invoice_no }}</td>
<td class="p-1">{{ item.material_no }}</td>
<td class="p-1">{{ item.material_name }}</td>
<td class="p-1">{{ item.lot_no || '—' }}</td>
<!-- 拨出批号展示外部形态(WTP→HOW 镜像转换,与匹配卡/可调拨明细/待办池同规则;
行上数据保持文件原形态,转换只发生在展示侧) -->
<td class="p-1">{{ deriveBatchNo(item.lot_no) || '—' }}</td>
<td class="p-1">{{ item.quantity }}<template v-if="item.unit"> {{ item.unit }}</template></td>
</tr>
</tbody>
@@ -57,15 +57,20 @@ describe('TransferHomePanel chat home entry', () => {
});
});
it('home 视图渲染标题、今日待办入口与三张历史待办计数卡', async () => {
it('home 视图渲染标题、今日待办入口与两张历史待办计数卡', async () => {
const wrapper = mountHome();
await flushPromises();
expect(wrapper.find('[data-testid="transfer-home"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-home-today"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-home-recoverable"]').text()).toContain('6');
expect(wrapper.find('[data-testid="transfer-home-closed"]').text()).toContain('2');
expect(wrapper.find('[data-testid="transfer-home-unknown"]').text()).toContain('1');
// [断言意图] 结果未知行不设首页卡(2026-09-29:行级只读无独立出口,统一走
// 执行看板的结果未知单据);待办池内筛选仍可达,首页不再渲染该卡。
expect(wrapper.find('[data-testid="transfer-home-unknown"]').exists()).toBe(false);
expect(api.getTransferBacklogSummary).toHaveBeenCalled();
// [断言意图] 首屏只取计数:计数卡不消费全量待办列表(68.5kB 级),
// /backlog 全量列表延迟到切片子视图(TransferMessageView backlog 挂载)自行加载。
expect(api.listTransferBacklog).not.toHaveBeenCalled();
});
it('点击“匹配可调拨库存”今日待办入口独立触发来源选择卡(复用 TransferMessageView)', async () => {
@@ -99,8 +104,9 @@ describe('TransferHomePanel chat home entry', () => {
});
it('点击历史待办计数卡独立触发 backlog 卡片,并按计数卡切片初始筛选', async () => {
// [断言意图] 三张计数卡不再落入同一份全量列表:可恢复/已关闭/结果未知
// 各自带对应 resultFilter 打开待处理池(否则 0 行的已关闭/结果未知被 50 行可恢复淹没)。
// [断言意图] 两张计数卡不再落入同一份全量列表:可恢复/已关闭
// 各自带对应 resultFilter 打开待处理池(否则 0 行的已关闭被 50 行可恢复淹没);
// 结果未知无首页卡(2026-09-29),unknown 切片仅池内筛选可达。
api.listTransferBacklog.mockResolvedValue([
{ item_id: 7, source_code: 'DBS-AWSBI', invoice_no: 'INV-001', material_no: 'MAT-1',
status: 'blocked_recoverable', reason: '收料 1200 / ERP 1000', age_days: 1, aging_level: 'normal' },
@@ -129,13 +135,6 @@ describe('TransferHomePanel chat home entry', () => {
expect((wrapper.find('[data-testid="transfer-backlog-result-filter"]').element as HTMLSelectElement).value).toBe('closed');
expect(wrapper.text()).toContain('INV-002');
expect(wrapper.text()).not.toContain('INV-001');
await wrapper.find('[data-testid="transfer-home-back"]').trigger('click');
await flushPromises();
await wrapper.find('[data-testid="transfer-home-unknown"]').trigger('click');
await flushPromises();
expect((wrapper.find('[data-testid="transfer-backlog-result-filter"]').element as HTMLSelectElement).value).toBe('unknown');
expect(wrapper.text()).toContain('INV-003');
});
it('点击已执行统计卡片进入明细列表子视图:initial-group 透传且 flow-active=true', async () => {
@@ -1,14 +1,17 @@
<!--
features/chat/components/messages/TransferHomePanel.vue
用途:在途仓自动调拨 Agent 的 Chat 首页入口区——上区「库存匹配」动作入口,
中区「待办看板」四队列(可调拨明细/待恢复异常/已人工关闭/结果未知),
下区「已执行」统计卡片入口(四张分组计数卡,点击跳转明细列表子视图),
中区「待办看板」三队列(可调拨明细/待恢复异常/已人工关闭;结果未知行
2026-09-29 起不再设首页卡——行级在待办池只读且无独立出口,统一走下方
执行看板的结果未知单据 [重新触发],池内仍可经结果筛选查看),
下区「执行看板」统计卡片入口(四张分组计数卡,点击跳转明细列表子视图),
点击进入对应处理视图(复用自驱动的 TransferMessageView / TransferExecutedOrders)。
依赖:TransferMessageView(复用自驱动卡片)、TransferExecutedCards(已执行卡片入口)、
TransferExecutedOrders(已执行明细列表子视图)、useChatTransfer、i18n chat.transfer.*。
逻辑:home 时拉取待办汇总与可调拨明细计数并挂载已执行卡片;'executed' 子视图由
openExecuted(group) 进入(卡片带入初始分组)并挂载列表组件;其余非 home 视图
渲染 TransferMessageView。卡片不注入消息流,因此无需后端 ChatLog 消息。
逻辑:home 时仅拉待办汇总计数与可调拨明细(首屏不拉全量待办列表,命中
首页预取单飞);'executed' 子视图由 openExecuted(group) 进入(卡片带入
初始分组)并挂载列表组件;其余非 home 视图渲染 TransferMessageView
(backlog 切片在其挂载时自拉全量列表)。卡片不注入消息流,因此无需后端 ChatLog 消息。
-->
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
@@ -37,7 +40,7 @@ const backlogFilter = ref<BacklogFilter>('all');
/** 已执行卡片带入的初始分组(''=全部)。 */
const executedGroup = ref<'success' | 'failed' | 'executing' | 'result_unknown' | ''>('');
/** 打开待处理池并按计数卡切片(recoverable/closed/unknown)。 */
/** 打开待处理池并按计数卡切片(recoverable/closed;unknown 切片仅池内筛选可达)。 */
function openBacklog(filter: BacklogFilter) {
backlogFilter.value = filter;
view.value = 'backlog';
@@ -49,11 +52,12 @@ function openExecuted(group: 'success' | 'failed' | 'executing' | 'result_unknow
view.value = 'executed';
}
/** home 视图需要待办汇总与可调拨明细计数;进入时拉取。 */
/** home 视图仅拉待办汇总计数与可调拨明细——计数卡只消费计数,
* 68.5kB 级全量待办列表延迟到切片子视图(TransferMessageView backlog)自行加载 */
async function loadHomeSummary() {
if (view.value !== 'home') return;
await Promise.all([
transfer.loadBacklog().catch(() => undefined),
transfer.loadBacklogSummary().catch(() => undefined),
transfer.loadExecutableItems().catch(() => undefined),
]);
}
@@ -109,7 +113,7 @@ function goBack() {
<!-- 待办看板 -->
<section aria-label="待办看板">
<p class="mb-2 text-sm font-bold text-secondary">{{ $t('chat.transfer.homeBoardLabel') }}</p>
<div class="grid grid-cols-2 gap-3 lg:grid-cols-4">
<div class="grid grid-cols-2 gap-3 lg:grid-cols-3">
<button
type="button"
data-testid="transfer-home-executable"
@@ -140,16 +144,6 @@ function goBack() {
<b class="mt-2 block text-sm font-bold text-primary">{{ $t('chat.transfer.homeClosed') }}</b>
<span class="mt-1 block text-xs text-secondary">{{ $t('chat.transfer.homeClosedHint') }}</span>
</button>
<button
type="button"
data-testid="transfer-home-unknown"
class="rounded-2xl border border-amber-200 bg-amber-50 p-4 text-left transition-colors hover:bg-amber-100"
@click="openBacklog('unknown')"
>
<b class="block text-2xl leading-none text-amber-600">{{ transfer.backlogSummary.value?.unknown ?? 0 }}</b>
<b class="mt-2 block text-sm font-bold text-primary">{{ $t('chat.transfer.homeUnknown') }}</b>
<span class="mt-1 block text-xs text-secondary">{{ $t('chat.transfer.homeUnknownHint') }}</span>
</button>
</div>
</section>
@@ -0,0 +1,72 @@
/**
* features/chat/components/messages/TransferMatchCard.spec.ts
* 用途:匹配卡顶栏「来源失败」横幅过滤——路由未解析失败只行内展示,不进顶栏。
* 依赖:@vue/test-utils、i18n。
* 逻辑:来源失败顶栏(sources[].error_code/error_message)防止“安静全 0”;
* 后端分层后路由失败保持行级(result=blocked_route_not_resolved),
* 顶栏需按 error_code 客户端排除(历史卡片回放同样生效)。
*/
import { mount } from '@vue/test-utils';
import { describe, expect, it } from 'vitest';
import i18n from '@/i18n';
import TransferMatchCard from './TransferMatchCard.vue';
import type { TransferMatchingSummary, TransferSourceProgress } from '../../types/transfer.types';
/** 最小合法匹配摘要(TransferMatchingSummary 全必填字段齐备,计数为 0) */
function buildSummary(): TransferMatchingSummary {
return {
matching_id: 'MTG-T',
status: 'completed',
business_date: '2026-08-06',
eligible_receipt_date_to: '2026-08-06',
expires_at: '2026-08-06T23:59:59',
counts: {
file_invoice_count: 0,
not_matured_count: 0,
matched_count: 0,
executable_count: 0,
blocked_count: 0,
pending_stock_check_count: 0,
invalid_count: 0,
},
estimated_transfer_quantity: '0',
estimated_external_write_count: 0,
matching_hash: 'hash-test',
};
}
function mountCard(sources: TransferSourceProgress[]) {
return mount(TransferMatchCard, {
props: {
summary: buildSummary(),
items: [],
selected: new Set<number>(),
sources,
},
global: { plugins: [i18n] },
});
}
describe('TransferMatchCard 来源失败顶栏', () => {
it('顶栏不展示 ROUTE_NOT_RESOLVED 来源失败(路由只行内)', () => {
// [断言意图] 路由失败不再升级为来源级 failed(后端分层),顶栏排除
// TRANSFER.ROUTE_NOT_RESOLVED(客户端按 error_code 过滤,历史回放同样生效);
// 其余来源级失败(如文件 schema 无效)仍必须在顶栏可见。
const wrapper = mountCard([
{ source_code: 'A', stage: 'failed', error_code: 'TRANSFER.ROUTE_NOT_RESOLVED', error_message: 'route not resolved' },
{ source_code: 'B', stage: 'failed', error_code: 'TRANSFER_FILE_SCHEMA_INVALID', error_message: 'schema' },
]);
const banner = wrapper.find('[data-testid="transfer-match-failed-sources"]');
expect(banner.exists()).toBe(true);
expect(banner.text()).not.toContain('route not resolved');
expect(banner.text()).toContain('schema');
});
it('仅路由失败时顶栏不渲染', () => {
// [断言意图] 唯一失败来源为路由未解析时,顶栏整体不出现(避免空横幅/全 0 误导)。
const wrapper = mountCard([
{ source_code: 'A', stage: 'blocked_route', error_code: 'TRANSFER.ROUTE_NOT_RESOLVED', error_message: 'route not resolved' },
]);
expect(wrapper.find('[data-testid="transfer-match-failed-sources"]').exists()).toBe(false);
});
});
@@ -13,12 +13,15 @@
可行动项;重查范围含可恢复阻断与可执行行(重查仍按 invoice_no 提交);
阻断原因经结果徽标 title 悬浮透出不占行高;无选择或 busy 时生成按钮禁用;
emit execute(itemIds);来源级解析/文件失败经 sources.error_code 透出
(防"安静全 0")。
(防"安静全 0"),但路由未解析失败(TRANSFER.ROUTE_NOT_RESOLVED)不进顶栏
——路由失败保持行级(result=blocked_route_not_resolved 行内展示),
顶栏按 error_code 客户端排除,历史卡片回放同样生效。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { deriveBatchNo } from './transferBatch';
import { formatQuantity } from './transferFormat';
import type { TransferMatchingItem, TransferMatchingSummary, TransferSourceProgress } from '../../types/transfer.types';
const { t } = useI18n();
@@ -50,9 +53,17 @@ const selectedCount = computed(() =>
);
const executeDisabled = computed(() => props.busy || selectedCount.value === 0);
/** 来源级失败(解析/文件/RPA 触发):必须可见,防止计数全 0 却无任何解释。 */
/** 不进顶栏的来源失败码:路由未解析失败由后端保持行级(result=blocked_route_not_resolved),
* 顶栏排除之(历史卡片 sources[].error_code 仍带该码,客户端过滤统一兜住)。 */
const HIDDEN_SOURCE_BANNER_CODES = new Set(['TRANSFER.ROUTE_NOT_RESOLVED']);
/** 来源级失败(解析/文件/RPA 触发):必须可见,防止计数全 0 却无任何解释;路由类失败仅行内展示不进顶栏。 */
const failedSources = computed(() =>
(props.sources ?? []).filter((source) => source.error_code || source.error_message),
(props.sources ?? []).filter(
(source) =>
(source.error_code || source.error_message) &&
!HIDDEN_SOURCE_BANNER_CODES.has(String(source.error_code || '')),
),
);
/** 筛选与全选状态(表格交互本地态,勾选集合仍由父级持有)。 */
@@ -224,7 +235,7 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
<div
v-if="failedSources.length"
class="mb-3 rounded-lg border border-red-200 bg-red-50 p-3 text-xs text-red-700"
data-testid="transfer-match-source-errors"
data-testid="transfer-match-failed-sources"
>
<div class="mb-1 font-bold">{{ $t('chat.transfer.sourceErrorTitle') }}</div>
<div v-for="source in failedSources" :key="source.source_code" class="leading-5">
@@ -257,7 +268,7 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
</button>
</div>
<div class="overflow-x-auto">
<table class="w-full min-w-[1100px] text-xs" data-testid="transfer-match-table">
<table class="w-full min-w-[1240px] text-xs" data-testid="transfer-match-table">
<thead>
<tr class="border-b border-default bg-surface-soft text-left text-[11px] text-muted">
<th class="p-2">
@@ -268,17 +279,18 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
@change="toggleAll"
/>
</th>
<th class="p-2">{{ $t('chat.transfer.colSource') }}</th>
<th class="p-2">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
<th class="p-2">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="p-2">{{ $t('chat.transfer.colName') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
<th class="p-2">{{ $t('chat.transfer.colFromQty') }}</th>
<th class="p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
<th class="p-2">{{ $t('chat.transfer.colToQty') }}</th>
<th class="p-2">{{ $t('chat.transfer.colResult') }}</th>
<!-- 表头全列 nowrap:防「拨出仓库/投入数量」等折行;品名列吃剩余宽度 -->
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colSource') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colName') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colFromQty') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colToQty') }}</th>
<th class="whitespace-nowrap p-2">{{ $t('chat.transfer.colResult') }}</th>
</tr>
</thead>
<tbody>
@@ -298,15 +310,16 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
@change="emit('toggle', item.item_id as number, ($event.target as HTMLInputElement).checked)"
/>
</td>
<td class="p-2">{{ item.source_code }}</td>
<td class="p-2 font-semibold">{{ item.invoice_no }}</td>
<td class="p-2">{{ item.receipt_date || '—' }}</td>
<td class="p-2">{{ item.material_no }}</td>
<!-- 除品名外全列 nowrap:日期/仓库/料号带连字符,列宽不足时从连字符处折行 -->
<td class="whitespace-nowrap p-2">{{ item.source_code }}</td>
<td class="whitespace-nowrap p-2 font-semibold">{{ item.invoice_no }}</td>
<td class="whitespace-nowrap p-2">{{ item.receipt_date || '—' }}</td>
<td class="whitespace-nowrap p-2">{{ item.material_no }}</td>
<td class="p-2">{{ item.material_name }}</td>
<td class="p-2">{{ item.from_warehouse }}</td>
<td class="p-2">{{ deriveBatchNo(item.lot_no) }}</td>
<td class="whitespace-nowrap p-2">{{ item.from_warehouse }}</td>
<td class="whitespace-nowrap p-2">{{ deriveBatchNo(item.lot_no) }}</td>
<td class="p-2">
<div>{{ item.from_quantity ?? '—' }}</div>
<div>{{ formatQuantity(item.from_quantity) }}</div>
<!-- 库存查询时刻小字:数据新鲜度溯源(stale 门禁的可见依据) -->
<div
v-if="checkedAtLabel(item)"
@@ -317,13 +330,13 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
{{ checkedAtLabel(item) }}
</div>
</td>
<td class="p-2">{{ item.to_warehouse }}</td>
<td class="p-2">{{ item.to_quantity }}</td>
<td class="whitespace-nowrap p-2">{{ item.to_warehouse }}</td>
<td class="whitespace-nowrap p-2">{{ formatQuantity(item.to_quantity) }}</td>
<td class="p-2">
<div class="flex flex-wrap items-center gap-1">
<!-- 阻断原因经悬浮提示(title)透出:不占行高;可执行行也提供重查入口 -->
<span
class="rounded-full px-2 py-0.5 font-bold"
class="whitespace-nowrap rounded-full px-2 py-0.5 font-bold"
:class="{
'bg-emerald-50 text-emerald-700': item.result === 'executable',
'bg-amber-50 text-amber-700': item.result === 'not_matured' || item.result === 'pending_stock_check',
@@ -159,13 +159,13 @@ async function onRequery(invoiceNos: string[]) {
}
}
/** 可调拨明细行重查:逐行核对最新库存后刷新队列(行级 retry 不依赖匹配) */
/** 可调拨明细行重查:批量核对最新库存后刷新队列(复用 batch-requery 唯一批量后端,
* 后端按组织一次外部查询——禁止逐行调单行 retry 把 N 行放大成 N 次外部调用) */
async function onExecutableRequery(itemIds: number[]) {
if (!itemIds.length) return;
busy.value = true;
try {
for (const itemId of itemIds) {
await transfer.retry(itemId);
}
await transfer.batchRequery(itemIds);
await transfer.loadExecutableItems();
} catch (e) {
reportError(e);
@@ -2,9 +2,11 @@
features/chat/components/messages/TransferResultCard.vue
用途:融合卡(D9:调拨单清单=进度=结果)——props { run_no } 自驱动轮询 GET /runs/{run_no},
逐单展示「收料日期 · 拨出→拨入 · N 物料 · 合计」与状态徽标(待处理/执行中/ERP 单号/失败),
行明细常驻展开;result_unknown 行 [重新触发](D11 唯一出口,幂等只触发末步);
失败行 [重查库存](emit 上抛,复用既有 batch-requery)+ [关闭单](D18:原因必填 +
同单行影响面 + 「关闭调拨单≠ERP 无单」红线确认);终态出下载区。无取消执行入口(D9)。
行明细常驻展开(Invoice | 料号 | 品名 | 拨出批号 | 投入数量,列序对齐可调拨明细);
单据级动作与状态徽标同排头部右侧(2026-09-29 方案A):result_unknown [重新触发]
(D11 唯一出口,幂等只触发末步);失败行 [重试](emit 上抛,复用既有 batch-requery)+
[关闭单](D18:原因必填 + 同单行影响面 + 「关闭调拨单≠ERP 无单」红线确认);
终态出下载区。无取消执行入口(D9)。
依赖:props.runNo/initialRun、useChatTransfer(自有实例轮询:startRunPolling/refreshRun)、
transfer.api(retriggerTransferDocument/closeTransferDocument)、useMessage、i18n chat.transfer.*。
逻辑:挂载即拉取打底一帧并按 4s 轮询直至 run 终态(onUnmounted 停止);单次失败保留旧值并显示
@@ -12,6 +14,8 @@
历史回放旧 payload(无 orders)把 result.external_documents 投影为成功单兼容展示。
失败/未知单的单据级 error_message 恒 null(T11 评审移交 + P2-3 契约扩充:后端失败/未知单行带
行级 reason=result_message):❌ 原因行级优先、无则仅展示状态文案,禁止渲染 undefined/null 字样。
「未生成 ERP 单据」区仅收未建单阻断行(2026-09-29 后端口径收窄,已建单失败行不重复展示),
行文案优先行级 message(人话原因)、状态码标签兜底。
-->
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue';
@@ -19,7 +23,7 @@ import { useI18n } from 'vue-i18n';
import { useMessage } from '@/shared/composables/useMessage';
import { isTerminalRunStatus, useChatTransfer } from '../../composables/useChatTransfer';
import { closeTransferDocument, retriggerTransferDocument } from '../../api/transfer.api';
import type { TransferRunResult, TransferOrder, TransferOrderLine } from '../../types/transfer.types';
import type { TransferRunResult, TransferOrder, TransferOrderLine, TransferExceptionItem } from '../../types/transfer.types';
const props = defineProps<{
/** Run 编号(必传):自驱动轮询与重新触发的目标 Run。 */
@@ -183,7 +187,12 @@ function lineKey(order: TransferOrder, line: TransferOrderLine, index: number):
return `${order.doc_no}|${line.material_no}|${line.lot_no}|${index}`;
}
/** 未入单异常行文案映射(口径不变:blocked/business/technical/unknown/matching_expired)。 */
/** 未入单异常行文案:行级 message(人话原因,如分组阻断单号)优先;无则回落
* 状态码标签映射(blocked/business/technical/unknown/matching_expired)。 */
function exceptionReasonText(exc: TransferExceptionItem): string {
return exc.message?.trim() || t(exceptionReasonLabel(exc.reason));
}
function exceptionReasonLabel(reason: string): string {
const map: Record<string, string> = {
blocked_quantity_mismatch: 'chat.transfer.resultBlocked',
@@ -314,13 +323,48 @@ async function confirmCloseOrder() {
· {{ $t('chat.transfer.materialCount', { count: order.lines.length }) }}
<template v-if="order.lines.length"> · {{ orderTotalQuantity(order) }} {{ orderUnit(order) }}</template>
</span>
<span
class="rounded-full px-2 py-0.5 font-bold"
:class="orderBadgeCls(order)"
:data-testid="`transfer-order-status-${order.doc_no}`"
>
{{ orderBadgeText(order) }}
</span>
<!-- 状态徽标 + 单据级动作同排头部右侧(2026-09-29 方案A):「失败→能做什么」
一眼完成,卡片主体回归纯信息展示;动作为单据级(D11 重新触发 / D18 重试+关闭单),
testid 不变供规格定位。 -->
<div class="flex flex-wrap items-center gap-2">
<span
class="rounded-full px-2 py-0.5 font-bold"
:class="orderBadgeCls(order)"
:data-testid="`transfer-order-status-${order.doc_no}`"
>
{{ orderBadgeText(order) }}
</span>
<button
v-if="order.status === 'result_unknown'"
type="button"
class="rounded border border-amber-300 px-2 py-0.5 text-[11px] font-bold text-amber-700 transition hover:bg-amber-50 disabled:opacity-40"
:data-testid="`transfer-order-retrigger-${order.doc_no}`"
:disabled="actionBusy"
@click="retriggerTarget = order"
>
{{ $t('chat.transfer.orderAction.retrigger') }}
</button>
<template v-if="isFailedOrder(order)">
<button
type="button"
class="rounded border border-brand-200 px-2 py-0.5 text-[11px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:data-testid="`transfer-order-retry-${order.doc_no}`"
:disabled="actionBusy"
@click="emit('retry', order)"
>
{{ $t('chat.transfer.orderAction.retry') }}
</button>
<button
type="button"
class="rounded border border-red-200 px-2 py-0.5 text-[11px] font-bold text-red-700 transition hover:bg-red-50 disabled:opacity-40"
:data-testid="`transfer-order-close-${order.doc_no}`"
:disabled="actionBusy"
@click="openCloseDialog(order)"
>
{{ $t('chat.transfer.orderAction.closeOrder') }}
</button>
</template>
</div>
</div>
<!-- 失败/未知单原因([P2-3 契约扩充] 行级 reason 优先;无则不渲染——状态文案兜底,禁 undefined/null) -->
@@ -332,48 +376,12 @@ async function confirmCloseOrder() {
{{ $t('chat.transfer.orderReasonPrefix', { reason: orderReason(order) }) }}
</div>
<!-- 单据级行内动作(D11/D18:result_unknown 仅重新触发;失败行重查+关闭单) -->
<div
v-if="order.status === 'result_unknown' || isFailedOrder(order)"
class="flex flex-wrap gap-2 px-3 pb-2"
>
<button
v-if="order.status === 'result_unknown'"
type="button"
class="rounded border border-amber-300 px-2 py-0.5 text-[11px] font-bold text-amber-700 transition hover:bg-amber-50 disabled:opacity-40"
:data-testid="`transfer-order-retrigger-${order.doc_no}`"
:disabled="actionBusy"
@click="retriggerTarget = order"
>
{{ $t('chat.transfer.orderAction.retrigger') }}
</button>
<template v-if="isFailedOrder(order)">
<button
type="button"
class="rounded border border-brand-200 px-2 py-0.5 text-[11px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:data-testid="`transfer-order-retry-${order.doc_no}`"
:disabled="actionBusy"
@click="emit('retry', order)"
>
{{ $t('chat.transfer.orderAction.retry') }}
</button>
<button
type="button"
class="rounded border border-red-200 px-2 py-0.5 text-[11px] font-bold text-red-700 transition hover:bg-red-50 disabled:opacity-40"
:data-testid="`transfer-order-close-${order.doc_no}`"
:disabled="actionBusy"
@click="openCloseDialog(order)"
>
{{ $t('chat.transfer.orderAction.closeOrder') }}
</button>
</template>
</div>
<!-- 行明细常驻展开(物料 × 批号聚合行) -->
<!-- 行明细常驻展开(物料 × 批号聚合行;Invoice 首列对齐可调拨明细列序) -->
<div class="border-t border-subtle px-3 py-2" :data-testid="`transfer-order-lines-${order.doc_no}`">
<table class="w-full text-xs">
<thead>
<tr class="text-left text-[11px] text-muted">
<th class="p-1">{{ $t('chat.transfer.colInvoice') }}</th>
<th class="p-1">{{ $t('chat.transfer.colMaterial') }}</th>
<th class="p-1">{{ $t('chat.transfer.colName') }}</th>
<th class="p-1">{{ $t('chat.transfer.colFromBatch') }}</th>
@@ -382,6 +390,7 @@ async function confirmCloseOrder() {
</thead>
<tbody>
<tr v-for="(line, index) in order.lines" :key="lineKey(order, line, index)" class="border-t border-subtle">
<td class="p-1">{{ line.invoice_no || '—' }}</td>
<td class="p-1">{{ line.material_no }}</td>
<td class="p-1">{{ line.material_name }}</td>
<td class="p-1">{{ line.lot_no || '—' }}</td>
@@ -393,7 +402,8 @@ async function confirmCloseOrder() {
</li>
</ul>
<!-- 未入单异常区(口径不变):早于建单被阻断的行不落在任何单内,fail-closed 单独展示 -->
<!-- 未入单异常区(2026-09-29 收窄:仅未建单被阻断的行——已建单失败行不重复展示;
文案行级 message 优先、状态码标签兜底) -->
<div
v-if="(run?.result?.exceptions?.length ?? 0) > 0"
class="mt-3"
@@ -407,7 +417,7 @@ async function confirmCloseOrder() {
class="rounded-lg bg-red-50 px-3 py-1.5 text-xs text-red-700"
>
<span class="font-bold">{{ exc.invoice_no }}</span>
<span class="mx-1 text-red-400">·</span>{{ exc.source_code }} · {{ $t(exceptionReasonLabel(exc.reason)) }}
<span class="mx-1 text-red-400">·</span>{{ exc.source_code }} · {{ exceptionReasonText(exc) }}
<div class="text-[11px] text-red-500">{{ exc.facts }}</div>
</li>
</ul>
@@ -4,7 +4,9 @@
* 确认提交、重试收料 RPA。
* 依赖:@vue/test-utils、i18n。
* 逻辑:平台 DBS/Crane 仅分组;实例为选择与执行边界(决策 2/3/4);
* 所选来源需至少一个 has_ready_file 才能确认匹配(决策:无 ready 文件禁止确认)。
* 确认需至少一个 has_ready_file(兜底告警),提交范围静默过滤为 ready-only
* (无 ready 文件的勾选项不进匹配,2026-09-29 来源错误分层);
* 重试门禁=仅 fetching 在途不可重试(ready 亦可强制重抓,2026-09-29 去管控)。
*/
import { mount } from '@vue/test-utils';
import { describe, expect, it } from 'vitest';
@@ -52,11 +54,37 @@ describe('TransferSourceSelectCard', () => {
expect(wrapper.emitted('confirm')).toBeUndefined();
});
it('“全选可见”勾选全部启用实例', async () => {
it('“全选可见”勾选全部启用实例,确认时静默剔除无 ready 文件来源', async () => {
// [断言意图] 门禁新语义:有 ready 文件的勾选项照常放行,无 ready 文件的勾选项
// (DBS-AWSSG none)静默剔除——确认范围只含可执行来源,不再整包提交。
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-visible"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'DBS-AWSSG', 'CRANE-SZ']);
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'CRANE-SZ']);
});
it('勾选 ready+parse_failed 确认时只提交 ready 来源', async () => {
// [断言意图] 解析失败来源(has_ready_file=false)勾选后不阻断确认,
// 但确认事件只携带具备 ready 文件的来源码。
const sources = [
{ source_code: 'DSV-OK', display_name: 'ok', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' as const },
{ source_code: 'DSV-BAD', display_name: 'bad', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'parse_failed' as const },
];
const wrapper = mountCard({}, sources);
await wrapper.find('[data-testid="transfer-source-option-DSV-OK"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-option-DSV-BAD"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DSV-OK']);
});
it('parse_failed 显示解析失败徽标且可重试', async () => {
// [断言意图] 当日收料文件解析失败(file_status=parse_failed)不得误报就绪;
// 与 none/failed/expired 一样允许重新触发收料 RPA。
const wrapper = mountCard({}, [
{ source_code: 'DSV-BAD', display_name: 'bad', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'parse_failed' as const },
]);
expect(wrapper.find('[data-testid="transfer-source-status-DSV-BAD"]').text()).toBe('解析失败');
expect((wrapper.find('[data-testid="transfer-source-retry-DSV-BAD"]').element as HTMLButtonElement).disabled).toBe(false);
});
it('“清空选择”清空已选实例', async () => {
@@ -115,12 +143,28 @@ describe('TransferSourceSelectCard', () => {
expect(wrapper.find('[data-testid="transfer-source-date-invalid"]').exists()).toBe(false);
});
it('“只选可重试”勾选无文件/失败来源', async () => {
it('文件已就绪来源行尾重试图标可用,可强制重抓', async () => {
// [断言意图] 2026-09-29 去管控:ready 不再禁用重试(文件内容异常时覆盖重抓),
// 点击行尾图标按单来源 emit retry。
const wrapper = mountCard();
expect((wrapper.find('[data-testid="transfer-source-retry-DBS-AWSBI"]').element as HTMLButtonElement).disabled).toBe(false);
await wrapper.find('[data-testid="transfer-source-retry-DBS-AWSBI"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSBI']);
});
it('抓取中来源重试图标保持禁用(在途去重防并发双跑)', async () => {
const wrapper = mountCard({}, [
{ source_code: 'DSV-FETCH', display_name: 'fetching', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'fetching' },
]);
expect((wrapper.find('[data-testid="transfer-source-retry-DSV-FETCH"]').element as HTMLButtonElement).disabled).toBe(true);
});
it('“只选可重试”包含 ready 来源(ready 亦可强制重抓)', async () => {
// [断言意图] 2026-09-29 去管控:可重试=除 fetching 外全部状态;全选可重试后
// 因含 ready 文件来源,确认按钮不再被「至少一 ready」门禁禁用。
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-retryable"]').trigger('click');
const selected = (wrapper.find('[data-testid="transfer-source-confirm"]').element as HTMLButtonElement).disabled;
// 可重试来源为 DBS-AWSSG(none);选中它但无 ready 文件 → 确认仍禁用(门禁)。
expect(selected).toBe(true);
expect((wrapper.find('[data-testid="transfer-source-confirm"]').element as HTMLButtonElement).disabled).toBe(false);
});
it('点击行尾重试图标 emit retry([sourceCode])', async () => {
@@ -129,11 +173,11 @@ describe('TransferSourceSelectCard', () => {
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSSG']);
});
it('批量重试仅传可重试来源', async () => {
it('批量重试传所选全部可重试来源(含 ready)', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-retryable"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-batch-retry"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSSG']);
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSBI', 'DBS-AWSSG', 'CRANE-SZ']);
});
it('已过期来源显示「文件已过期」徽标且可重试', async () => {
@@ -6,6 +6,9 @@
逻辑:匹配参数区(调拨类型 + 收料日期,确认时一并提交)→ 选择辅助/上下文操作条
(有选中时原位替换辅助区,承载批量重试/下载/清空选择)→ 平台分组来源列表
(平台仅分组不可直接执行)→ 底部唯一实心主按钮「确认范围并匹配」(未选禁用);
确认只提交具备 ready 文件的来源(勾选的无 ready 项如 parse_failed/none 静默剔除,
门禁「至少一 ready」保留为兜底告警);重试除抓取中(fetching)外均可触发
(ready 亦可强制重抓,2026-09-29 去管控),徽标独立文案;
调拨类型决定收料数据范围(类型 1 仅纳入 INVOICE 前缀 HOM/HOX/WTP),
类型 2/3 一期占位(禁用,后端同样 fail-closed)。
-->
@@ -63,9 +66,10 @@ function transferTypeLabel(value: TransferType): string {
const platforms = computed(() => [...new Set(props.sources.map((source) => source.platform))]);
const selectedCount = computed(() => selected.value.size);
/** 可重试判定:仅 待抓取(none) / 抓取失败(failed) / 已过期(expired) 的来源可重试(ready/fetching 不重复触发)。 */
/** 可重试判定:除抓取中(fetching)外均可重试(2026-09-29 去管控:ready 亦可强制重抓,
* 文件内容异常时覆盖重抓;后端 retry-rpa 本无状态门禁);fetching 在途去重防并发双跑。 */
function isRetryable(source: TransferSourceOption): boolean {
return source.file_status === 'none' || source.file_status === 'failed' || source.file_status === 'expired';
return source.file_status !== 'fetching';
}
/** 全部可重试来源。 */
@@ -108,7 +112,7 @@ function selectVisible() {
selected.value = new Set(props.sources.filter((source) => source.enabled).map((source) => source.source_code));
}
/** 只选可重试来源(待抓取/抓取失败),来源多时一键收敛。 */
/** 只选可重试来源(除抓取中外全部状态,含 ready 强制重抓),来源多时一键收敛。 */
function selectRetryable() {
selected.value = new Set(retryableSources.value.map((source) => source.source_code));
}
@@ -137,23 +141,28 @@ function downloadSelected(): void {
if (codes.length) emit('download', codes);
}
/** 确认范围并匹配:只提交具备 ready 文件的来源;无 ready 文件的勾选项(如 parse_failed/none)
* 静默剔除(历史上是「至少一 ready 则整包提交」,会把不可执行来源带进匹配);
* 「至少一 ready」门禁保留为兜底告警(全部无 ready 时拦截)。 */
function confirm() {
if (selectedCount.value === 0) {
notifyWarning(t('chat.transfer.needSelectSource'), t('chat.transfer.sourceSelectTitle'));
return;
}
if (!selectedHasReadyFile.value) {
const readyCodes = [...selected.value].filter(
(code) => props.sources.find((s) => s.source_code === code)?.has_ready_file,
);
if (readyCodes.length === 0) {
notifyWarning(t('chat.transfer.needReadyFile'), t('chat.transfer.sourceSelectTitle'));
return;
}
emit('confirm', [...selected.value], { from: dateFrom.value || undefined, to: dateTo.value || undefined }, transferType.value);
emit('confirm', readyCodes, { from: dateFrom.value || undefined, to: dateTo.value || undefined }, transferType.value);
}
</script>
<template>
<div class="my-2 rounded-2xl border border-brand-100 bg-surface p-4 shadow-sm" data-testid="transfer-source-select-card">
<h3 class="mb-1 text-sm font-bold text-primary">{{ $t('chat.transfer.sourceSelectTitle') }}</h3>
<p class="mb-3 text-xs text-muted">{{ $t('chat.transfer.sourceSelectHint') }}</p>
<h3 class="mb-3 text-sm font-bold text-primary">{{ $t('chat.transfer.sourceSelectTitle') }}</h3>
<!-- [ZONE 1] 匹配参数区:调拨类型 + 收料日期同组(确认匹配时一并提交,参数先行定范围)。 -->
<div class="mb-3 rounded-lg border border-subtle p-3" data-testid="transfer-source-params">
@@ -327,6 +336,14 @@ function confirm() {
>
{{ t('chat.transfer.fileExpired') }}
</span>
<!-- 解析失败(parse_failed):当日收料文件解析失败;重试按状态分层——parse_failed=本地重解析,其余状态=重新触发收料 RPA 重抓 -->
<span
v-else-if="source.file_status === 'parse_failed'"
class="inline-flex items-center gap-1 rounded-full bg-red-50 px-2 py-0.5 text-[10px] font-bold text-red-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileParseFailed') }}
</span>
<span
v-else
class="inline-flex items-center gap-1 rounded-full bg-surface-strong px-2 py-0.5 text-[10px] font-bold text-muted"
@@ -0,0 +1,24 @@
/**
* features/chat/components/messages/transferDate.spec.ts
* 用途:锁定 T+2 成熟口径的截止日计算(与后端 date_policy 同口径,默认 lag=2)。
* 依赖:被测纯函数 transferDate.ts。
* 逻辑:直接注入 UTC 时刻构造上海业务日,断言跨日/跨月边界不漂移。
*/
import { describe, expect, it } from 'vitest';
import { eligibleReceiptDateTo, shanghaiBusinessDate } from './transferDate';
describe('eligibleReceiptDateTo(T+2 口径)', () => {
it('T=2026-09-28 → 截止 2026-09-26(T-2,海外时差)', () => {
// 上海 9-28 13:00 = UTC 05:00。
expect(eligibleReceiptDateTo(new Date('2026-09-28T05:00:00Z'))).toBe('2026-09-26');
});
it('UTC 月末跨界仍按上海业务日回退 2 天', () => {
// 上海 10-01 00:30 = UTC 9-30 16:30 → T=10-01,截止 09-29。
expect(eligibleReceiptDateTo(new Date('2026-09-30T16:30:00Z'))).toBe('2026-09-29');
});
it('shanghaiBusinessDate 返回上海业务日(UTC 17:00 = 上海次日)', () => {
expect(shanghaiBusinessDate(new Date('2026-08-05T17:00:00Z'))).toBe('2026-08-06');
});
});
@@ -1,12 +1,16 @@
/**
* features/chat/components/messages/transferDate.ts
* 用途:在途调拨业务日期工具——按 Asia/Shanghai 计算业务日期(T)与
* D+1 成熟规则的可匹配截止日(T-1),与后端 date_policy 完全同口径。
* T+lag 成熟规则的可匹配截止日(T - lag,lag 默认 2 即 T+2),
* 与后端 date_policy 完全同口径。
* 依赖:无(纯函数,便于单测)。
* 逻辑:浏览器本地时区不可靠(部署/用户时区任意),必须固定上海时区口径,
* 否则前端日期上限与后端 TRANSFER.RECEIPT_DATE_RANGE_INVALID 卡控会漂移。
*/
/** 成熟滞后天数:与后端 IN_TRANSIT_TRANSFER_MATURITY_LAG_DAYS 默认值一致(T+2,海外时差余量)。 */
const MATURITY_LAG_DAYS = 2;
/** Asia/Shanghai 当前业务日期(YYYY-MM-DD)。 */
export function shanghaiBusinessDate(now: Date = new Date()): string {
// en-CA 输出恰为 ISO YYYY-MM-DD(locale 无关的稳定格式技巧)。
@@ -18,9 +22,9 @@ export function shanghaiBusinessDate(now: Date = new Date()): string {
}).format(now);
}
/** D+1 规则可匹配截止日(业务日期 T - 1 天,YYYY-MM-DD)。 */
/** T+lag 规则可匹配截止日(业务日期 T - lag 天,默认 T-2,YYYY-MM-DD)。 */
export function eligibleReceiptDateTo(now: Date = new Date()): string {
const business = new Date(`${shanghaiBusinessDate(now)}T00:00:00Z`);
business.setUTCDate(business.getUTCDate() - 1);
business.setUTCDate(business.getUTCDate() - MATURITY_LAG_DAYS);
return business.toISOString().slice(0, 10);
}
@@ -0,0 +1,32 @@
/** formatQuantity 单测:库存/投入数量列「无小数位显示整数、有小数保留原样」。 */
import { describe, expect, it } from 'vitest';
import { formatQuantity } from './transferFormat';
describe('formatQuantity', () => {
it('小数部分全为 0 → 整数展示(ERP 账面固定三位小数场景)', () => {
// [断言意图] "30.000" 展示为 "30",不再出现无意义尾零
expect(formatQuantity('30.000')).toBe('30');
expect(formatQuantity('0.000')).toBe('0');
});
it('有有效小数 → 原样保留,不缩位不舍入', () => {
// [断言意图] "30.250" 保持 "30.250"(展示层不得改写 ERP 原始精度)
expect(formatQuantity('30.250')).toBe('30.250');
expect(formatQuantity('30.5')).toBe('30.5');
});
it('整数字符串/数字原样返回', () => {
expect(formatQuantity('30')).toBe('30');
expect(formatQuantity(36)).toBe('36');
});
it('空值返回缺省占位符,非数值原样返回', () => {
expect(formatQuantity(null)).toBe('—');
expect(formatQuantity(undefined)).toBe('—');
expect(formatQuantity('')).toBe('—');
expect(formatQuantity('N/A')).toBe('N/A');
expect(formatQuantity(null, '0')).toBe('0');
});
});
@@ -0,0 +1,18 @@
/**
* 在途调拨卡片共用的数量展示格式化。
*
* 用途:库存数量/投入数量列来自后端 Decimal 原样字符串(ERP 账面常带固定小数位,
* 如 "30.000"),直接展示出现无意义尾零、显得与投入数量("30")口径不一。
* 依赖:无(纯函数);被 TransferMatchCard / TransferExecutableCard /
* TransferBacklogSummaryCard 的数量列使用。
* 逻辑:可解析为有限数值且无小数部分(小数全 0)→ 整数展示("30.000" → "30");
* 有有效小数 → 原样保留("30.250" → "30.250",不擅自缩位/四舍五入——
* 严格相等判定以 ERP 原始值为准,展示层不得改写精度);非数值/空值 → 原样。
*/
export function formatQuantity(value: string | number | null | undefined, fallback = '—'): string {
if (value === null || value === undefined || value === '') return fallback;
const num = Number(value);
if (!Number.isFinite(num)) return String(value);
return Number.isInteger(num) ? String(num) : String(value);
}
@@ -1,7 +1,8 @@
/**
* features/chat/composables/useChatTransfer.spec.ts
* 用途:验证匹配创建/恢复、选择范围、直接生成执行 Run、结果恢复与防重复;
* 另验证 D8 异步 202 提交后的 Run 轮询(4s 间隔、终态停止、单次失败保留旧值、清理)。
* 另验证 D8 异步 202 提交后的 Run 轮询(4s 间隔、终态停止、单次失败保留旧值、清理)
* 与首页看板预取单飞(幂等预取、consume-once、无预取现发)。
* 依赖:vi.mock(transfer.api)、useChatTransfer。
* 逻辑:用 Mock API 驱动组合式函数,断言状态流转与调用参数;
* 轮询用例用 fake timers 推进 4s 周期并断言终态/失败/清理分支。
@@ -23,11 +24,14 @@ const api = vi.hoisted(() => ({
downloadTransferExceptions: vi.fn(),
listTransferSources: vi.fn(),
retryTransferSourceRpa: vi.fn(),
listTransferBacklog: vi.fn(),
getTransferBacklogSummary: vi.fn(),
listExecutableTransferItems: vi.fn(),
}));
vi.mock('../api/transfer.api', () => api);
import { useChatTransfer } from './useChatTransfer';
import { useChatTransfer, prefetchTransferHomeBoard } from './useChatTransfer';
const summary = {
matching_id: 'MTG-20260806-001',
@@ -377,3 +381,53 @@ describe('useChatTransfer 来源状态轮询(收料 RPA 202 异步收口)',
expect(api.listTransferSources).toHaveBeenCalledTimes(2);
});
});
describe('useChatTransfer 首页看板预取(会话引导期单飞)', () => {
/** 标准看板载荷(供预取槽位消费;单飞槽位是模块级状态,用例结束前必须双槽消费完) */
const backlogSummaryPayload = {
recoverable: 3, closed: 1, unknown: 0,
aging: { warn_3d: 1, escalate_5d: 0, critical_7d: 0 },
};
const executablePayload = { items: [{ item_id: 21 }], counts: { executable_count: 1 } };
beforeEach(() => {
vi.clearAllMocks();
api.getTransferBacklogSummary.mockResolvedValue(backlogSummaryPayload);
api.listExecutableTransferItems.mockResolvedValue(executablePayload);
});
it('预取幂等:重复调用只发一次请求,挂载消费命中同一 Promise 不重发', async () => {
// [断言意图] ChatMessageList 预取与 HomePanel 挂载消费必须共享同一在途请求——
// 这是「会话引导 ∥ 看板数据」并行化的关键;任一槽位在途/未消费时不重复发。
prefetchTransferHomeBoard();
prefetchTransferHomeBoard();
const transfer = useChatTransfer();
await Promise.all([transfer.loadBacklogSummary(), transfer.loadExecutableItems()]);
expect(api.getTransferBacklogSummary).toHaveBeenCalledTimes(1);
expect(api.listExecutableTransferItems).toHaveBeenCalledTimes(1);
expect(transfer.backlogSummary.value?.recoverable).toBe(3);
expect(transfer.executableItems.value).toHaveLength(1);
});
it('consume-once:预取消费后回落现发路径(回到首页的刷新不走旧预取)', async () => {
// [断言意图] 预取只服务首次进首页;切片操作后返回首页的计数刷新必须拿新鲜数据,
// 复用已决 Promise 会展示过期计数。executable 首次消费的仍是预取槽位(1 次),
// 槽位清空后的再次加载才现发(第 2 次)。
prefetchTransferHomeBoard();
const transfer = useChatTransfer();
await transfer.loadBacklogSummary();
await transfer.loadBacklogSummary();
expect(api.getTransferBacklogSummary).toHaveBeenCalledTimes(2); // 预取 1 + 现发 1
await transfer.loadExecutableItems();
expect(api.listExecutableTransferItems).toHaveBeenCalledTimes(1); // 命中预取槽位
await transfer.loadExecutableItems();
expect(api.listExecutableTransferItems).toHaveBeenCalledTimes(2); // 槽位已空 → 现发
});
it('无预取时现发请求(预取是纯加速层,缺失不影响正确性)', async () => {
const transfer = useChatTransfer();
await transfer.loadBacklogSummary();
expect(api.getTransferBacklogSummary).toHaveBeenCalledTimes(1);
expect(transfer.backlogSummary.value?.recoverable).toBe(3);
});
});
@@ -10,7 +10,9 @@
* 4s 轮询 GET /sources 直至全部脱离 fetching(ready/failed/expired/none);
* 勾选集合以明细行 item_id 为键(历史回放行无 item_id 不可选);
* 恢复处理 = 按明细 id 重查库存(batch-requery 是唯一后端);
* 防重复点击(busy);错误统一 useMessage 展示 BusinessError。
* 防重复点击(busy);错误统一 useMessage 展示 BusinessError;
* 首页看板支持会话引导期预取(prefetchTransferHomeBoard 单飞,
* loadBacklogSummary/loadExecutableItems 挂载时消费同一 Promise)。
*/
import { computed, getCurrentScope, onScopeDispose, ref, type Ref } from 'vue';
import i18n from '@/i18n';
@@ -59,6 +61,29 @@ const SOURCE_POLL_INTERVAL_MS = 4000;
/** 来源轮询连续失败停止上限(口径同 Run 轮询):防后端持续不可用时无限空转 */
const SOURCE_POLL_MAX_CONSECUTIVE_FAILURES = 3;
/**
* 首页看板预取(模块级单飞,consume-once):看板卡原先等会话消息返回、
* TransferHomePanel 挂载后才发请求(串行白等会话引导 ~1.5s);ChatMessageList
* 识别到「在途调拨 Agent 且当前无消息」即预取,挂载后的 loadBacklogSummary /
* loadExecutableItems 命中同一 Promise——会话引导与看板数据并行。
* 已知降级(无正确性影响):预取后看板未挂载(如会话实为历史消息)时槽位滞留
* 已决 Promise,后续进入首页不再预取、回落挂载时现发,仅损失一次预取机会。
*/
let homeBoardPrefetchSummary: Promise<TransferBacklogSummary> | null = null;
let homeBoardPrefetchExecutable: ReturnType<typeof listExecutableTransferItems> | null = null;
/** 提前发起首页看板两请求(幂等:任一槽位在途/未消费时不重复发)。 */
export function prefetchTransferHomeBoard(): void {
if (homeBoardPrefetchSummary || homeBoardPrefetchExecutable) return;
const summary = getTransferBacklogSummary();
const executable = listExecutableTransferItems();
// 浮空兜底:预取无人消费时 rejection 不产生 unhandledrejection;消费方仍从原 Promise 拿真实错误
void summary.catch(() => undefined);
void executable.catch(() => undefined);
homeBoardPrefetchSummary = summary;
homeBoardPrefetchExecutable = executable;
}
/**
* Run 轮询终态集合(口径对齐后端 status.py RUN_TRANSITIONS 收尾):
* executing 只流向 success / partial_failed / failed / cancelled——
@@ -424,7 +449,8 @@ export function useChatTransfer() {
}
}
/** 对指定来源重新触发收料 RPA 抓取,并刷新来源状态(触发后 202 + fetching,
/** 对指定来源重试收料,并刷新来源状态(解析失败分层:parse_failed 先本地重解析
* 返回 200——ready/parse_failed,无轮询;其余状态仍触发收料 RPA 返回 202 + fetching,
* loadSources 观察到 fetching 即自动开始来源轮询,RPA 回调收口后状态自动刷新) */
async function retrySourceRpa(sourceCode: string) {
const status = await retryTransferSourceRpa(sourceCode);
@@ -440,9 +466,21 @@ export function useChatTransfer() {
return { items, summary };
}
/** 加载可调拨明细(全局可执行行队列;恢复后的行会出现在这里) */
/** 首页看板计数(仅汇总,不拉全量列表——列表延迟到切片子视图加载);
* 命中首页预取则复用在途请求,否则现发 */
async function loadBacklogSummary() {
const pending = homeBoardPrefetchSummary;
homeBoardPrefetchSummary = null;
const summary = await (pending ?? getTransferBacklogSummary());
backlogSummary.value = summary;
return summary;
}
/** 加载可调拨明细(全局可执行行队列;恢复后的行会出现在这里);命中首页预取则复用在途请求 */
async function loadExecutableItems() {
const payload = await listExecutableTransferItems();
const pending = homeBoardPrefetchExecutable;
homeBoardPrefetchExecutable = null;
const payload = await (pending ?? listExecutableTransferItems());
executableItems.value = payload.items;
return executableItems.value;
}
@@ -522,6 +560,7 @@ export function useChatTransfer() {
loadSources,
retrySourceRpa,
loadBacklog,
loadBacklogSummary,
loadExecutableItems,
batchRequery,
resume,
@@ -107,12 +107,17 @@ export interface ErpDocument {
lines: ErpDocumentLine[];
}
/** 未生成 ERP 单据的异常项 */
/**
* 未生成 ERP 单据的异常项(2026-09-29 口径收窄:仅未建单被阻断的行,已建单
* 失败/未知行的原因与动作由 orders 卡片承载)。
*/
export interface TransferExceptionItem {
source_code: string;
invoice_no: string;
material_no: string;
reason: string;
/** 行级人话原因(= 行 result_message,如分组阻断单号);展示优先于 reason 状态码标签。 */
message?: string;
facts: string;
}
@@ -127,6 +132,8 @@ export type TransferOrderStatus = 'pending' | 'executing' | 'success' | 'duplica
/** 单内行(ERP 写入行粒度聚合:物料+批号;quantity 为 6 位小数字符串,与 D14 快照口径一致) */
export interface TransferOrderLine {
/** 行级溯源收料通知号(2026-09-29 契约扩充;一行恒对应一张 invoice,旧 payload 缺省) */
invoice_no?: string;
material_no: string;
material_name: string;
lot_no: string;
@@ -238,8 +245,8 @@ export interface TransferSourceOption {
display_name: string;
platform: string;
enabled: boolean;
/** 收料文件状态:ready / fetching / failed / expired / none(只读投影货代收料事实) */
file_status?: 'ready' | 'fetching' | 'failed' | 'expired' | 'none';
/** 收料文件状态:ready / fetching / failed / parse_failed / expired / none(只读投影货代收料事实;parse_failed=当日可用收料文件解析失败) */
file_status?: 'ready' | 'fetching' | 'failed' | 'parse_failed' | 'expired' | 'none';
/** 是否已有当前可用的收料文件(门禁:无 ready 文件禁止确认匹配) */
has_ready_file?: boolean;
file_no?: string | null;
@@ -249,7 +256,7 @@ export interface TransferSourceOption {
/** 来源收料文件状态(门禁 + 状态标识 + 重试返回) */
export interface TransferSourceFileStatus {
source_code: string;
file_status: 'ready' | 'fetching' | 'failed' | 'expired' | 'none';
file_status: 'ready' | 'fetching' | 'failed' | 'parse_failed' | 'expired' | 'none';
has_ready_file: boolean;
file_no?: string | null;
file_sha256?: string | null;