feat(in-transit-transfer): 外部调用切换集成连接器并新增调拨类型与在途仓编码

- 退役 erp_adapter/gateway_adapter:外部查询/写经 capability_client 走集成连接器,端点凭据与并发超时由客户端实例管理
- 域能力代码注册 capabilities:入参出参 Schema、幂等语义与读写标志随域代码版本化,组合根 create_app 幂等注册
- 新增调拨业务类型 transfer_type(在途仓至HUB/HUB维修出/HUB间)冻结枚举,迁移落 CheckConstraint 数据库兜底
- 外部仓库映射新增 in_transit_warehouse_code 拨出库位来源,管理端库存映射页同步维护
- 单据命名外部化:erp_* 字段与索引改称 external_*,单据号格式交由连接器映射,测试数据同步换牌
- 收料归档文件可用性判定收敛 receipt_file_gate 单一事实来源(当天抓取/保留期/清理态)
- 同步 chat 调拨卡片、useChatTransfer、e2e、全套服务/API/Job 测试与域文档
This commit is contained in:
hugo committed 2026-09-23 00:49:38 +08:00
1 parent 31591e663e
commit 9959b06acd
97 files changed
+3525 -1489

No files matched your search

@@ -346,10 +346,11 @@
<template v-else-if="activeTab === 'mappings'">
<label><span>{{ t('admin.shippingInventory.source') }}</span><select v-model.number="mapping.inventory_source_id" class="select-field" required><option :value="0">{{ t('admin.shippingInventory.chooseSource') }}</option><option v-for="item in sources" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.source_code }}</option></select></label>
<label><span>{{ t('admin.shippingInventory.freightWarehouse') }}</span><input v-model="mapping.freight_warehouse_id" class="input-field" required></label>
<label><span>{{ t('admin.shippingInventory.freightWarehouse') }}</span><input v-model="mapping.freight_warehouse_id" class="input-field"></label>
<label><span>{{ t('admin.shippingInventory.externalSystem') }}</span><input v-model="mapping.external_system_code" class="input-field" required></label>
<label><span>{{ t('admin.shippingInventory.externalOrganization') }}</span><input v-model="mapping.external_organization_code" class="input-field"></label>
<label><span>{{ t('admin.shippingInventory.externalSite') }}</span><input v-model="mapping.external_site_code" class="input-field"></label>
<label><span>{{ t('admin.shippingInventory.inTransitWarehouseCode') }}</span><input v-model="mapping.in_transit_warehouse_code" class="input-field" required></label>
<label><span>{{ t('admin.shippingInventory.externalWarehouseCode') }}</span><input v-model="mapping.external_warehouse_code" class="input-field" required></label>
<label><span>{{ t('admin.shippingInventory.externalWarehouseName') }}</span><input v-model="mapping.external_warehouse_name" class="input-field" required></label>
<div class="switch-field"><span>{{ t('admin.shippingInventory.enabled') }}</span><button type="button" class="status-switch" :class="{ on: mapping.enabled }" role="switch" :aria-checked="mapping.enabled" @click="mapping.enabled = !mapping.enabled"><i></i><b>{{ mapping.enabled ? t('admin.shippingInventory.enabledState') : t('admin.shippingInventory.disabledState') }}</b></button></div>
@@ -663,7 +664,7 @@ const inventoryPathOpen = ref(true);
const receiptBaseline = ref('');
const sourceBaseline = ref('');
const rule = reactive({ rule_code: '', rule_name: '', scope: 'line', priority: 100, conditions: [{ source_kind: 'order_field', order_field_id: '', operator: 'prefix', expected: '' }] as RuleCondition[], source_codes: [] as string[] });
const mapping = reactive({ inventory_source_id: 0, freight_warehouse_id: '', external_system_code: 'TOPGP', external_organization_code: '', external_site_code: '', external_warehouse_code: '', external_warehouse_name: '', enabled: true });
const mapping = reactive({ inventory_source_id: 0, freight_warehouse_id: '', external_system_code: 'TOPGP', external_organization_code: '', external_site_code: '', in_transit_warehouse_code: '', external_warehouse_code: '', external_warehouse_name: '', enabled: true });
const compatibleRoutingFields = computed(() => routingFields.value.filter((item) => item.scope === (rule.scope === 'task' ? 'header' : 'line')));
const activeInventoryFields = computed(() => inventoryFields.value.filter((item) => item.status === 'active'));
const matchingInventoryFields = computed(() => activeInventoryFields.value.filter((item) => item.usage_type === 'match_identity'));
@@ -979,7 +980,7 @@ function createNew(): void {
sourceBaseline.value = '';
}
if (activeTab.value === 'rules') Object.assign(rule, { rule_code: '', rule_name: '', scope: 'line', priority: 100, conditions: [{ source_kind: 'order_field', order_field_id: '', operator: 'prefix', expected: '' }], source_codes: [] });
if (activeTab.value === 'mappings') Object.assign(mapping, { inventory_source_id: 0, freight_warehouse_id: '', external_system_code: 'TOPGP', external_organization_code: '', external_site_code: '', external_warehouse_code: '', external_warehouse_name: '', enabled: true });
if (activeTab.value === 'mappings') Object.assign(mapping, { inventory_source_id: 0, freight_warehouse_id: '', external_system_code: 'TOPGP', external_organization_code: '', external_site_code: '', in_transit_warehouse_code: '', external_warehouse_code: '', external_warehouse_name: '', enabled: true });
drawerOpen.value = true;
}
@@ -1039,7 +1040,7 @@ function selectItem(item: Item): void {
})),
source_codes: item.action_payload_json?.source_codes || [],
});
if (activeTab.value === 'mappings') Object.assign(mapping, { ...item, freight_warehouse_id: item.freight_warehouse_id || '', external_organization_code: item.external_organization_code || '', external_site_code: item.external_site_code || '' });
if (activeTab.value === 'mappings') Object.assign(mapping, { ...item, freight_warehouse_id: item.freight_warehouse_id || '', external_organization_code: item.external_organization_code || '', external_site_code: item.external_site_code || '', in_transit_warehouse_code: item.in_transit_warehouse_code || '' });
drawerOpen.value = true;
}
@@ -16,6 +16,7 @@ import type {
TransferRunResult,
TransferSourceFileStatus,
TransferSourceOption,
TransferType,
} from '../types/transfer.types';
const BASE = '/api/in-transit-transfer';
@@ -28,6 +29,8 @@ export interface CreatePrecheckPayload {
business_date?: string;
receipt_date_from?: string;
receipt_date_to?: string;
/** 调拨业务类型;缺省为在途仓至HUB仓 */
transfer_type?: TransferType;
}
/** 创建预检(只读) */
@@ -88,7 +91,7 @@ export const downloadTransferReceiptFiles = (runNo: string) =>
/** 下载预检冻结的 ERP 库存表(csv) */
export const downloadTransferErpInventory = (runNo: string) =>
requestBlob(`${BASE}/runs/${runNo}/erp-inventory`, { headers: getAuthHeaders() });
requestBlob(`${BASE}/runs/${runNo}/external-inventory`, { headers: getAuthHeaders() });
/** 下载七 Sheet 异常 Excel */
export const downloadTransferExceptions = (runNo: string) =>
@@ -64,14 +64,14 @@ describe('TransferHomePanel chat home entry', () => {
precheck_id: 'TPC-1', status: 'ready_to_execute', business_date: '2026-08-06',
eligible_receipt_date_to: '2026-08-05', expires_at: '',
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
estimated_transfer_quantity: '1200', estimated_erp_write_count: 1, precheck_hash: 'sha256:x',
estimated_transfer_quantity: '1200', estimated_external_write_count: 1, precheck_hash: 'sha256:x',
});
api.getTransferPrecheck.mockResolvedValue({
summary: {
precheck_id: 'TPC-1', status: 'ready_to_execute', business_date: '2026-08-06',
eligible_receipt_date_to: '2026-08-05', expires_at: '',
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
estimated_transfer_quantity: '1200', estimated_erp_write_count: 1, precheck_hash: 'sha256:x',
estimated_transfer_quantity: '1200', estimated_external_write_count: 1, precheck_hash: 'sha256:x',
},
items: [{
source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A',
@@ -38,7 +38,7 @@ const payload = {
expires_at: '',
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
estimated_transfer_quantity: '1200',
estimated_erp_write_count: 1,
estimated_external_write_count: 1,
precheck_hash: 'sha256:x',
},
items: [{
@@ -57,7 +57,7 @@ const runPayload = {
run_no: 'RUN-1',
status: 'success',
result: {
erp_documents: [{
external_documents: [{
document_no: 'TRF-10001', from_warehouse: 'DBS-TRANSIT', to_warehouse: 'HUB-CN01',
material_count: 1, total_quantity: '1200', posting_status: 'posted',
lines: [{ material_no: 'MAT-1', material_name: '连接器组件', specification: 'A', invoice_no: 'INV-001', quantity: '1200' }],
@@ -167,7 +167,7 @@ describe('TransferMessageView self-driving wiring', () => {
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
await flushPromises();
expect(api.createTransferPrecheck).toHaveBeenCalledWith({ source_codes: ['DBS-AWSBI'] });
expect(api.createTransferPrecheck).toHaveBeenCalledWith({ source_codes: ['DBS-AWSBI'], transfer_type: 'in_transit_to_hub' });
expect(wrapper.find('[data-testid="transfer-precheck-card"]').exists()).toBe(true);
});
});
@@ -25,6 +25,7 @@ import type {
TransferPrecheckSummary,
TransferRunResult,
TransferSourceProgress,
TransferType,
} from '../../types/transfer.types';
const props = defineProps<{
@@ -195,14 +196,15 @@ async function onCloseConfirm(reason: string) {
}
}
/** 来源实例选择确认 → 创建预检并切换预检卡(决策 4:两步第一步;收料日期范围为查询范围) */
/** 来源实例选择确认 → 创建预检并切换预检卡(决策 4:两步第一步;收料日期范围为查询范围;调拨类型决定数据范围) */
async function onSourceConfirm(
sourceCodes: string[],
dateRange?: { from?: string; to?: string },
transferType?: TransferType,
) {
busy.value = true;
try {
await transfer.createPrecheck(sourceCodes, undefined, dateRange);
await transfer.createPrecheck(sourceCodes, undefined, dateRange, transferType);
mode.value = 'precheck';
summaryRef.value = transfer.precheck.value;
items.value = transfer.items.value;
@@ -3,14 +3,18 @@
用途:预检卡——计数 + 来源失败提示 + 调拨明细表(含筛选)+ 勾选 + “直接生成调拨单”按钮。
依赖:props(summary/items/sources/selected/busy)、i18n chat.transfer.*。
逻辑:明细表渲染 filtered(关键字/结果筛选生效);阻断/未成熟项 checkbox 禁用;
重查范围含可恢复阻断与可执行行;阻断原因经结果徽标 title 悬浮透出不占行高;
无选择或 busy 时生成按钮禁用;emit execute(invoiceNos)(决策 4/5:无独立确认页);
来源级解析/文件失败经 sources.error_code 透出(防"安静全 0")。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { deriveBatchNo } from './transferBatch';
import type { TransferPrecheckItem, TransferPrecheckSummary, TransferSourceProgress } from '../../types/transfer.types';
const { t } = useI18n();
const props = defineProps<{
summary: TransferPrecheckSummary;
items: TransferPrecheckItem[];
@@ -54,6 +58,11 @@ function isCheckable(item: TransferPrecheckItem): boolean {
return isSelectable(item) || isBlocked(item);
}
/** 可重查行:可恢复阻断 + 可执行(已可执行也允许重查核对最新库存)。 */
function isRequeryable(item: TransferPrecheckItem): boolean {
return isBlocked(item) || item.result === 'executable';
}
const filtered = computed(() =>
props.items.filter((item) => {
const kw = keyword.value.trim().toLowerCase();
@@ -73,8 +82,8 @@ const filteredInvoiceNos = computed(() => filtered.value.map((item) => item.invo
const allFilteredSelected = computed(() =>
filteredInvoiceNos.value.length > 0 && filteredInvoiceNos.value.every((no) => props.selected.has(no)),
);
const selectedBlockedCount = computed(() =>
filtered.value.filter((item) => isBlocked(item) && props.selected.has(item.invoice_no)).length,
const selectedRequeryableCount = computed(() =>
filtered.value.filter((item) => isRequeryable(item) && props.selected.has(item.invoice_no)).length,
);
function toggleAll(): void {
@@ -83,7 +92,7 @@ function toggleAll(): void {
function requerySelected(): void {
const nos = filtered.value
.filter((item) => isBlocked(item) && props.selected.has(item.invoice_no))
.filter((item) => isRequeryable(item) && props.selected.has(item.invoice_no))
.map((item) => item.invoice_no);
if (nos.length) emit('requery', nos);
}
@@ -99,11 +108,31 @@ function resultLabel(result: string): string {
blocked_quantity_mismatch: 'chat.transfer.resultBlocked',
blocked_inventory_not_found: 'chat.transfer.resultBlocked',
blocked_future_date: 'chat.transfer.resultBlocked',
erp_query_timeout: 'chat.transfer.resultUnknown',
external_query_timeout: 'chat.transfer.resultUnknown',
result_unknown: 'chat.transfer.resultUnknown',
};
return map[result] ?? 'chat.transfer.resultBlocked';
}
/** 阻断原因悬浮文案:已知结果码走 i18n 本地化;带明细后缀(如查询失败的底层原因)原样保留追加。 */
const REASON_I18N_KEYS: Record<string, string> = {
blocked_quantity_mismatch: 'chat.transfer.reasonQuantityMismatch',
blocked_inventory_not_found: 'chat.transfer.reasonInventoryNotFound',
blocked_external_query_failed: 'chat.transfer.reasonExternalQueryFailed',
blocked_future_date: 'chat.transfer.reasonFutureDate',
};
function reasonTitle(item: TransferPrecheckItem): string | undefined {
if (!isBlocked(item) || !item.reason) return undefined;
const key = REASON_I18N_KEYS[item.result];
if (!key) return item.reason;
const base = t(key);
const marker = ': ';
const detail = item.reason.includes(marker)
? item.reason.slice(item.reason.indexOf(marker) + marker.length).trim()
: '';
return detail ? `${base}:${detail}` : base;
}
</script>
<template>
@@ -131,8 +160,8 @@ function resultLabel(result: string): string {
<div class="text-[11px] text-muted">{{ $t('chat.transfer.estimatedQuantity') }}</div>
</div>
<div class="rounded-lg bg-surface-soft p-2 text-center">
<div class="text-lg font-black text-brand-600">{{ summary.estimated_erp_write_count }}</div>
<div class="text-[11px] text-muted">{{ $t('chat.transfer.estimatedErpWrites') }}</div>
<div class="text-lg font-black text-brand-600">{{ summary.estimated_external_write_count }}</div>
<div class="text-[11px] text-muted">{{ $t('chat.transfer.estimatedExternalWrites') }}</div>
</div>
</div>
@@ -164,11 +193,11 @@ function resultLabel(result: string): string {
<button
type="button"
class="rounded-lg border border-brand-200 bg-brand-50 px-3 py-1 text-xs font-bold text-brand-700 transition hover:bg-brand-100 disabled:cursor-not-allowed disabled:opacity-40"
:disabled="props.requeryBusy || selectedBlockedCount === 0"
:disabled="props.requeryBusy || selectedRequeryableCount === 0"
data-testid="transfer-precheck-requery-selected"
@click="requerySelected"
>
{{ $t('chat.transfer.requerySelected') }}{{ selectedBlockedCount ? `(${selectedBlockedCount})` : '' }}
{{ $t('chat.transfer.requerySelected') }}{{ selectedRequeryableCount ? `(${selectedRequeryableCount})` : '' }}
</button>
</div>
<div class="overflow-x-auto">
@@ -224,26 +253,31 @@ function resultLabel(result: string): string {
<td class="p-2">{{ item.to_warehouse }}</td>
<td class="p-2">{{ item.to_quantity }}</td>
<td class="p-2">
<span
class="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',
'bg-red-50 text-red-700': !isSelectable(item) && item.result !== 'not_matured',
}"
>
{{ $t(resultLabel(item.result)) }}
</span>
<button
v-if="isBlocked(item)"
type="button"
class="ml-1 rounded border border-brand-200 px-1 text-[10px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:disabled="props.requeryBusy"
:data-testid="`transfer-requery-${item.invoice_no}`"
@click="emit('requery', [item.invoice_no])"
>
{{ $t('chat.transfer.requeryRow') }}
</button>
<div class="flex items-center gap-1">
<!-- 阻断原因经悬浮提示(title)透出:不占行高;可执行行也提供重查入口 -->
<span
class="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',
'bg-red-50 text-red-700': !isSelectable(item) && item.result !== 'not_matured',
}"
:title="reasonTitle(item)"
data-testid="transfer-item-result"
>
{{ $t(resultLabel(item.result)) }}
</span>
<button
v-if="isRequeryable(item)"
type="button"
class="ml-1 rounded border border-brand-200 px-1 text-[10px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
:disabled="props.requeryBusy"
:data-testid="`transfer-requery-${item.invoice_no}`"
@click="emit('requery', [item.invoice_no])"
>
{{ $t('chat.transfer.requeryRow') }}
</button>
</div>
</td>
</tr>
</tbody>
@@ -253,7 +287,7 @@ function resultLabel(result: string): string {
<div class="mt-3 flex items-center justify-end gap-3 border-t border-subtle pt-3">
<span class="text-xs text-muted">
{{ $t('chat.transfer.selectedCount', { count: selectedCount }) }} ·
{{ $t('chat.transfer.estimatedErpWrites') }}:{{ summary.estimated_erp_write_count }}
{{ $t('chat.transfer.estimatedExternalWrites') }}:{{ summary.estimated_external_write_count }}
</span>
<button
type="button"
@@ -39,9 +39,9 @@ function reasonLabel(reason: string): string {
</div>
<!-- 已生成 ERP 单据:按单号聚合 + 可展开物料明细 -->
<div v-if="run.result.erp_documents.length" class="flex flex-col gap-2">
<div v-if="run.result.external_documents.length" class="flex flex-col gap-2">
<details
v-for="doc in run.result.erp_documents"
v-for="doc in run.result.external_documents"
:key="doc.document_no"
class="rounded-lg border border-default"
data-testid="transfer-erp-document"
@@ -58,7 +58,7 @@ describe('TransferSourceSelectCard', () => {
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'DBS-AWSSG', 'CRANE-SZ']);
});
it('“清空”清空已选实例', async () => {
it('“清空选择”清空已选实例', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-visible"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-clear"]').trigger('click');
@@ -66,6 +66,28 @@ describe('TransferSourceSelectCard', () => {
expect(wrapper.emitted('confirm')).toBeUndefined();
});
it('选中后上下文操作条原位替换选择辅助区,清空选择后还原', async () => {
// [断言意图] 未选中零死按钮(仅辅助区);有选中时批量操作条同槽位出现并带计数;
// 清空选择后还原辅助区——Gmail/Linear 式批量操作栏切换行为。
const wrapper = mountCard();
expect(wrapper.find('[data-testid="transfer-source-aids"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').exists()).toBe(false);
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
expect(wrapper.find('[data-testid="transfer-source-aids"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').text()).toContain('已选 1');
await wrapper.find('[data-testid="transfer-source-clear"]').trigger('click');
expect(wrapper.find('[data-testid="transfer-source-aids"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').exists()).toBe(false);
expect(wrapper.emitted('confirm')).toBeUndefined();
});
it('D+1 规则提示收进 ⓘ 悬浮(title),不再平铺占宽', () => {
// [断言意图] 长规则文案通过原生 title 渐进披露,紧凑日期行不换行错位。
const wrapper = mountCard();
expect(wrapper.find('[data-testid="transfer-source-date-hint"]').attributes('title')).toBe('截止不超出 D+1 规则(业务日期前一天)');
});
it('“只选可重试”勾选无文件/失败来源', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-retryable"]').trigger('click');
@@ -86,4 +108,33 @@ describe('TransferSourceSelectCard', () => {
await wrapper.find('[data-testid="transfer-source-batch-retry"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSSG']);
});
it('已过期来源显示「文件已过期」徽标且可重试', async () => {
// [断言意图] 保留期已到的来源不得误报就绪(has_ready_file=false);
// expired 状态与 none/failed 一样允许重新触发收料 RPA。
const wrapper = mountCard({}, [
{ source_code: 'CRANE-EXP', display_name: '过期在途仓', platform: 'crane', enabled: true, has_ready_file: false, file_status: 'expired' },
]);
expect(wrapper.find('[data-testid="transfer-source-status-CRANE-EXP"]').text()).toBe('文件已过期');
expect((wrapper.find('[data-testid="transfer-source-retry-CRANE-EXP"]').element as HTMLButtonElement).disabled).toBe(false);
await wrapper.find('[data-testid="transfer-source-option-CRANE-EXP"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-batch-retry"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['CRANE-EXP']);
});
it('确认默认携带调拨类型 in_transit_to_hub', async () => {
// [断言意图] 类型 1 为缺省选中值,确认事件第三参回传类型。
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')?.[0][2]).toBe('in_transit_to_hub');
});
it('调拨类型 2/3 占位禁用且不可选中', async () => {
// [断言意图] 一期仅开放类型 1;占位类型按钮 disabled,防止发起未支持链路。
const wrapper = mountCard();
expect((wrapper.find('[data-testid="transfer-type-option-hub_repair_out"]').element as HTMLButtonElement).disabled).toBe(true);
expect((wrapper.find('[data-testid="transfer-type-option-hub_to_hub"]').element as HTMLButtonElement).disabled).toBe(true);
expect((wrapper.find('[data-testid="transfer-type-option-in_transit_to_hub"]').element as HTMLButtonElement).disabled).toBe(false);
});
});
@@ -1,15 +1,19 @@
<!--
features/chat/components/messages/TransferSourceSelectCard.vue
用途:来源实例选择卡(决策 2/3/4:手工两步第一步)——按平台 DBS/Crane 分组勾选实例,
“确认范围并预检”发起预检。
选择调拨类型后“确认范围并预检”发起预检。
依赖:props.sources、i18n chat.transfer.*。
逻辑:平台仅分组不可直接执行;未选任何实例时确认按钮禁用。
逻辑:预检参数区(调拨类型 + 收料日期,确认时一并提交)→ 选择辅助/上下文操作条
(有选中时原位替换辅助区,承载批量重试/下载/清空选择)→ 平台分组来源列表
(平台仅分组不可直接执行)→ 底部唯一实心主按钮「确认范围并预检」(未选禁用);
调拨类型决定收料数据范围(类型 1 仅纳入 INVOICE 前缀 HOM/HOX/WTP),
类型 2/3 一期占位(禁用,后端同样 fail-closed)。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useMessage } from '@/shared/composables/useMessage';
import type { TransferSourceOption } from '../../types/transfer.types';
import type { TransferSourceOption, TransferType } from '../../types/transfer.types';
const props = defineProps<{
sources: TransferSourceOption[];
@@ -19,7 +23,7 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
confirm: [sourceCodes: string[], dateRange?: { from?: string; to?: string }];
confirm: [sourceCodes: string[], dateRange?: { from?: string; to?: string }, transferType?: TransferType];
/** 批量重试收料 RPA:传来源编码列表 */
retry: [sourceCodes: string[]];
download: [sourceCodes: string[]];
@@ -32,13 +36,26 @@ const selected = ref<Set<string>>(new Set());
/** 收料日期范围(预检查询范围);截止不得超出 D+1 规则(后端卡控)。 */
const dateFrom = ref('');
const dateTo = ref('');
/** 调拨业务类型:决定本次预检纳入哪些收料数据;一期仅类型 1 开放。 */
const transferType = ref<TransferType>('in_transit_to_hub');
/** 类型选项元数据;enabled=false 为占位类型(UI 禁用 + 后端 fail-closed 双保险)。 */
const transferTypeOptions: Array<{ value: TransferType; enabled: boolean }> = [
{ value: 'in_transit_to_hub', enabled: true },
{ value: 'hub_repair_out', enabled: false },
{ value: 'hub_to_hub', enabled: false },
];
function transferTypeLabel(value: TransferType): string {
return t(`chat.transfer.transferType.${value}`);
}
const platforms = computed(() => [...new Set(props.sources.map((source) => source.platform))]);
const selectedCount = computed(() => selected.value.size);
/** 可重试判定:仅 待抓取(none) / 抓取失败(failed) 的来源可重试(ready/fetching 不重复触发)。 */
/** 可重试判定:仅 待抓取(none) / 抓取失败(failed) / 已过期(expired) 的来源可重试(ready/fetching 不重复触发)。 */
function isRetryable(source: TransferSourceOption): boolean {
return source.file_status === 'none' || source.file_status === 'failed';
return source.file_status === 'none' || source.file_status === 'failed' || source.file_status === 'expired';
}
/** 全部可重试来源。 */
@@ -117,7 +134,7 @@ function confirm() {
notifyWarning(t('chat.transfer.needReadyFile'), t('chat.transfer.sourceSelectTitle'));
return;
}
emit('confirm', [...selected.value], { from: dateFrom.value || undefined, to: dateTo.value || undefined });
emit('confirm', [...selected.value], { from: dateFrom.value || undefined, to: dateTo.value || undefined }, transferType.value);
}
</script>
@@ -126,7 +143,54 @@ function confirm() {
<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>
<div class="mb-3 flex flex-wrap items-center gap-2">
<!-- [ZONE 1] 预检参数区:调拨类型 + 收料日期同组(确认预检时一并提交,参数先行定范围)。 -->
<div class="mb-3 rounded-lg border border-subtle p-3" data-testid="transfer-source-params">
<p class="mb-2 text-[11px] font-bold text-muted">{{ $t('chat.transfer.precheckParams') }}</p>
<div class="flex flex-wrap items-center gap-2">
<span class="text-xs font-bold text-secondary">{{ $t('chat.transfer.transferTypeLabel') }}</span>
<button
v-for="option in transferTypeOptions"
:key="option.value"
type="button"
class="rounded-full border px-3 py-1 text-xs font-bold disabled:cursor-not-allowed disabled:opacity-40"
:class="transferType === option.value
? 'border-brand-600 bg-brand-600 text-white hover:bg-brand-700'
: 'border-brand-200 text-brand-700 hover:bg-brand-50'"
:disabled="busy || !option.enabled"
:title="option.enabled ? undefined : t('chat.transfer.transferTypeComingSoon')"
:data-testid="`transfer-type-option-${option.value}`"
@click="transferType = option.value"
>
{{ transferTypeLabel(option.value) }}
<span v-if="!option.enabled" class="ml-1 font-normal opacity-70">{{ t('chat.transfer.transferTypeComingSoon') }}</span>
</button>
</div>
<div class="mt-2 flex flex-wrap items-center gap-2">
<span class="text-xs font-bold text-secondary">{{ $t('chat.transfer.receiptDateLabel') }}</span>
<input
v-model="dateFrom"
type="date"
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
data-testid="transfer-source-date-from"
/>
<span class="text-xs text-muted">~</span>
<input
v-model="dateTo"
type="date"
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
data-testid="transfer-source-date-to"
/>
<!-- D+1 规则属低频说明:收进原生 title 悬浮(渐进披露),避免长文案挤压布局。 -->
<span
class="cursor-help text-xs text-muted"
:title="$t('chat.transfer.receiptDateHint')"
data-testid="transfer-source-date-hint"
>ⓘ</span>
</div>
</div>
<!-- [ZONE 2] 选择辅助/上下文操作条:有选中时原位替换辅助区(批量操作惯例),未选中零死按钮。 -->
<div v-if="selectedCount === 0" class="mb-3 flex flex-wrap items-center gap-2" data-testid="transfer-source-aids">
<button
type="button"
class="rounded-lg border border-brand-200 px-3 py-1.5 text-xs font-bold text-brand-700 hover:bg-brand-50 disabled:opacity-50"
@@ -145,58 +209,45 @@ function confirm() {
>
{{ $t('chat.transfer.selectRetryable') }}
</button>
<button
type="button"
class="rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-bold text-white hover:bg-brand-700 disabled:opacity-50"
:disabled="batchRetryDisabled"
data-testid="transfer-source-batch-retry"
@click="batchRetry"
>
{{ $t('chat.transfer.batchRetry') }}
</button>
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft disabled:opacity-50"
:disabled="busy || downloadDisabled"
data-testid="transfer-source-download"
@click="downloadSelected"
>
{{ $t('chat.transfer.downloadFiles') }}
</button>
<div class="ml-auto flex flex-wrap items-center gap-2">
<label class="flex items-center gap-1 text-xs text-secondary">
<span>{{ $t('chat.transfer.receiptDateFrom') }}</span>
<input
v-model="dateFrom"
type="date"
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
data-testid="transfer-source-date-from"
/>
</label>
<label class="flex items-center gap-1 text-xs text-secondary">
<span>~</span>
<input
v-model="dateTo"
type="date"
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
data-testid="transfer-source-date-to"
/>
</label>
<span class="text-xs text-muted">{{ $t('chat.transfer.receiptDateHint') }}</span>
</div>
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft disabled:opacity-50"
:disabled="busy"
data-testid="transfer-source-clear"
@click="clearSelected"
>
{{ $t('chat.transfer.clearSources') }}
</button>
<span class="ml-auto text-xs text-muted">
</div>
<div
v-else
class="mb-3 flex flex-wrap items-center gap-2 rounded-lg border border-brand-200 bg-brand-50 px-3 py-2"
data-testid="transfer-source-action-bar"
>
<span class="text-xs font-bold text-secondary">
{{ $t('chat.transfer.selectedSourceCount', { count: selectedCount }) }}
<span v-if="selectedRetryableCount > 0" class="text-amber-600"> · {{ $t('chat.transfer.selectedRetryableCount', { count: selectedRetryableCount }) }}</span>
</span>
<span class="ml-auto flex flex-wrap items-center gap-2">
<button
type="button"
class="rounded-lg border border-brand-200 px-3 py-1.5 text-xs font-bold text-brand-700 hover:bg-brand-50 disabled:opacity-50"
:disabled="batchRetryDisabled"
data-testid="transfer-source-batch-retry"
@click="batchRetry"
>
{{ $t('chat.transfer.batchRetry') }}
</button>
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft disabled:opacity-50"
:disabled="busy || downloadDisabled"
data-testid="transfer-source-download"
@click="downloadSelected"
>
{{ $t('chat.transfer.downloadFiles') }}
</button>
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft disabled:opacity-50"
:disabled="busy"
data-testid="transfer-source-clear"
@click="clearSelected"
>
{{ $t('chat.transfer.clearSources') }}
</button>
</span>
</div>
<div v-for="platform in platforms" :key="platform" class="mb-3 rounded-lg border border-subtle">
@@ -250,6 +301,13 @@ function confirm() {
>
{{ t('chat.transfer.fileFailed') }}
</span>
<span
v-else-if="source.file_status === 'expired'"
class="inline-flex items-center gap-1 rounded-full bg-orange-50 px-2 py-0.5 text-[10px] font-bold text-orange-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileExpired') }}
</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"
@@ -272,8 +330,7 @@ function confirm() {
</div>
</div>
<div class="flex items-center justify-end gap-3 border-t border-subtle pt-3">
<span class="text-xs text-muted">{{ $t('chat.transfer.selectedCount', { count: selectedCount }) }}</span>
<div class="flex items-center justify-end border-t border-subtle pt-3">
<button
type="button"
class="rounded-lg bg-brand-600 px-4 py-1.5 text-sm font-bold text-white hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-40"
@@ -23,7 +23,7 @@ const summary = {
expires_at: '',
counts: { file_invoice_count: 3, not_matured_count: 1, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
estimated_transfer_quantity: '2400',
estimated_erp_write_count: 2,
estimated_external_write_count: 2,
precheck_hash: 'sha256:x',
};
@@ -110,7 +110,7 @@ describe('TransferResultCard', () => {
run_no: 'RUN-1',
status: 'partial_failed',
result: {
erp_documents: [{
external_documents: [{
document_no: 'TRF-10001',
from_warehouse: 'DBS-TRANSIT',
to_warehouse: 'HUB-CN01',
@@ -31,7 +31,7 @@ const summary = {
expires_at: '',
counts: { file_invoice_count: 2, not_matured_count: 0, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
estimated_transfer_quantity: '2400',
estimated_erp_write_count: 2,
estimated_external_write_count: 2,
precheck_hash: 'sha256:abc',
};
@@ -54,7 +54,7 @@ describe('useChatTransfer', () => {
api.getTransferRun.mockResolvedValue({
run_no: 'RUN-20260806-1',
status: 'success',
result: { erp_documents: [], exceptions: [] },
result: { external_documents: [], exceptions: [] },
});
});
@@ -33,6 +33,7 @@ import type {
TransferRunResult,
TransferSourceOption,
TransferSourceProgress,
TransferType,
} from '../types/transfer.types';
export function useChatTransfer() {
@@ -59,11 +60,12 @@ export function useChatTransfer() {
const selectedCount = computed(() => selected.value.size);
const estimatedQuantity = computed(() => precheck.value?.estimated_transfer_quantity ?? '0');
/** 创建预检(缺文件时来源级阶段展示等待/失败) */
/** 创建预检(缺文件时来源级阶段展示等待/失败);transferType 决定收料数据范围,缺省在途仓至HUB仓 */
async function createPrecheck(
sourceCodes: string[],
businessDate?: string,
dateRange?: { from?: string; to?: string },
transferType?: TransferType,
) {
busy.value = true;
error.value = '';
@@ -73,6 +75,7 @@ export function useChatTransfer() {
business_date: businessDate,
receipt_date_from: dateRange?.from,
receipt_date_to: dateRange?.to,
transfer_type: transferType,
});
precheckId.value = summary.precheck_id;
await refreshPrecheck();
@@ -174,7 +177,7 @@ export function useChatTransfer() {
async function downloadErpInventory() {
if (!runNo.value) return null;
const result = await downloadTransferErpInventory(runNo.value);
saveBlob(result.blob, result.filename ?? `erp-inventory-${runNo.value}.csv`);
saveBlob(result.blob, result.filename ?? `external-inventory-${runNo.value}.csv`);
return result;
}
@@ -34,7 +34,7 @@ const detail: TransferPrecheckDetail = {
expires_at: '',
counts: { file_invoice_count: 3, not_matured_count: 1, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
estimated_transfer_quantity: '2400',
estimated_erp_write_count: 2,
estimated_external_write_count: 2,
precheck_hash: 'sha256:abc',
},
sources: [{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1', file_version: 'v3' }],
@@ -49,7 +49,7 @@ const runResult = {
run_no: 'RUN-20260806-001',
status: 'success',
result: {
erp_documents: [{
external_documents: [{
document_no: 'TRF-10001',
from_warehouse: 'DBS-TRANSIT',
to_warehouse: 'HUB-CN01',
@@ -85,7 +85,7 @@ describe('in-transit-transfer e2e contract', () => {
transfer.toggleSelect('INV-002', false);
await transfer.execute();
expect(api.executeTransferPrecheck).toHaveBeenCalledWith('TPC-20260806-001', ['INV-001']);
expect(transfer.run.value?.result.erp_documents[0].document_no).toBe('TRF-10001');
expect(transfer.run.value?.result.external_documents[0].document_no).toBe('TRF-10001');
});
it('刷新恢复:重建 composable 后按 run_no 恢复最终结果(决策 17)', async () => {
@@ -93,7 +93,7 @@ describe('in-transit-transfer e2e contract', () => {
transfer.runNo.value = 'RUN-20260806-001';
await transfer.refreshRun();
expect(transfer.run.value?.status).toBe('success');
expect(transfer.run.value?.result.erp_documents[0].material_count).toBe(2);
expect(transfer.run.value?.result.external_documents[0].material_count).toBe(2);
});
it('下载:收料来源文件与 ERP 库存表(决策 21/22 前端入口)', async () => {
@@ -5,6 +5,9 @@
* 逻辑:卡片/组合式函数只消费这些稳定类型;状态与后端 13 状态集对齐。
*/
/** 调拨业务类型(与后端 TransferType 枚举一致;类型 2/3 一期占位未开放) */
export type TransferType = 'in_transit_to_hub' | 'hub_repair_out' | 'hub_to_hub';
/** 预检计数 */
export interface TransferPrecheckCounts {
file_invoice_count: number;
@@ -30,7 +33,7 @@ export interface TransferPrecheckSummary {
expires_at: string;
counts: TransferPrecheckCounts;
estimated_transfer_quantity: string;
estimated_erp_write_count: number;
estimated_external_write_count: number;
precheck_hash: string;
}
@@ -105,7 +108,7 @@ export interface TransferRunResult {
run_no: string;
status: string;
result: {
erp_documents: ErpDocument[];
external_documents: ErpDocument[];
exceptions: TransferExceptionItem[];
};
}
@@ -157,8 +160,8 @@ export interface TransferSourceOption {
display_name: string;
platform: string;
enabled: boolean;
/** 收料文件状态:ready / fetching / failed / none(只读投影货代收料事实) */
file_status?: 'ready' | 'fetching' | 'failed' | 'none';
/** 收料文件状态:ready / fetching / failed / expired / none(只读投影货代收料事实) */
file_status?: 'ready' | 'fetching' | 'failed' | 'expired' | 'none';
/** 是否已有当前可用的收料文件(门禁:无 ready 文件禁止确认预检) */
has_ready_file?: boolean;
file_no?: string | null;
@@ -168,7 +171,7 @@ export interface TransferSourceOption {
/** 来源收料文件状态(门禁 + 状态标识 + 重试返回) */
export interface TransferSourceFileStatus {
source_code: string;
file_status: 'ready' | 'fetching' | 'failed' | 'none';
file_status: 'ready' | 'fetching' | 'failed' | 'expired' | 'none';
has_ready_file: boolean;
file_no?: string | null;
file_sha256?: string | null;