Files
syops/frontend/src/features/chat/components/messages/TransferMessageView.vue
T
hugo 9959b06acd 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 测试与域文档
2026-09-23 00:49:38 +08:00

290 lines
9.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/chat/components/messages/TransferMessageView.vue
用途:在途调拨消息卡片的自驱动挂载视图——按 payload 形态渲染卡片,并把卡片按钮
(直接生成调拨单 / 下载 / 重试 / 关闭)经 useChatTransfer 真实调用 API。
依赖:Transfer*Card、useChatTransfer、i18n chat.transfer.*。
逻辑:payload 作为初始状态(ChatLog 回放);执行后切换为结果卡;下载走 requestBlob;
不展示执行审计入口(决策 19)。
-->
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import TransferPrecheckCard from './TransferPrecheckCard.vue';
import TransferFileProgressCard from './TransferFileProgressCard.vue';
import TransferProgressCard from './TransferProgressCard.vue';
import TransferResultCard from './TransferResultCard.vue';
import TransferBacklogSummaryCard from './TransferBacklogSummaryCard.vue';
import TransferManualCloseDialog from './TransferManualCloseDialog.vue';
import TransferSourceSelectCard from './TransferSourceSelectCard.vue';
import { useChatTransfer } from '../../composables/useChatTransfer';
import { downloadTransferSourceFiles, getTransferPrecheck, requeryTransferItems } from '../../api/transfer.api';
import { triggerBlobDownload } from '@/shared/utils/download';
import { useMessage } from '@/shared/composables/useMessage';
import type {
TransferBacklogItem,
TransferPrecheckItem,
TransferPrecheckSummary,
TransferRunResult,
TransferSourceProgress,
TransferType,
} from '../../types/transfer.types';
const props = defineProps<{
payload?: Record<string, unknown> | null;
}>();
const { error: notifyError } = useMessage();
/** 统一错误提示:BusinessError 带本地化 message,其余回退到 String(e)。 */
function reportError(e: unknown) {
notifyError(e instanceof Error ? e.message : String(e));
}
const kind = computed(() => String(props.payload?.kind ?? 'precheck'));
const mode = ref(kind.value);
const summaryRef = ref<TransferPrecheckSummary | null>((props.payload?.summary as TransferPrecheckSummary) ?? null);
const items = ref<TransferPrecheckItem[]>((props.payload?.items as TransferPrecheckItem[]) ?? []);
const runNo = ref(String(props.payload?.run_no ?? ''));
const status = ref(String(props.payload?.status ?? 'executing'));
const run = ref<TransferRunResult | null>((props.payload?.run as TransferRunResult) ?? null);
const busy = ref(false);
const closeTarget = ref<TransferBacklogItem | null>(null);
/** 正在重试收料 RPA 的来源编码集合(按来源独立展示重试中)。 */
const retryingSource = ref<Set<string>>(new Set());
const transfer = useChatTransfer();
/** 待处理异常视图:进入时拉取列表与汇总 */
onMounted(() => {
if (kind.value === 'backlog') {
void transfer.loadBacklog();
}
if (kind.value === 'source-select') {
void transfer.loadSources();
}
});
/** payload 更新时重置本地状态(历史回放/刷新);初始化组合式函数上下文 */
function applyPayload(payload?: Record<string, unknown> | null) {
if (!payload) return;
mode.value = String(payload.kind ?? 'precheck');
summaryRef.value = (payload.summary as TransferPrecheckSummary) ?? null;
items.value = (payload.items as TransferPrecheckItem[]) ?? [];
runNo.value = String(payload.run_no ?? '');
status.value = String(payload.status ?? 'executing');
run.value = (payload.run as TransferRunResult) ?? null;
const summaryValue = (payload.summary as TransferPrecheckSummary) ?? null;
if (summaryValue) {
transfer.precheckId.value = summaryValue.precheck_id;
transfer.selected.value = new Set(
(payload.items as TransferPrecheckItem[] ?? [])
.filter((item) => item.result === 'executable')
.map((item) => item.invoice_no),
);
}
if (runNo.value) {
transfer.runNo.value = runNo.value;
}
}
applyPayload(props.payload);
watch(() => props.payload, applyPayload);
/** 打包下载选中来源的最新归档收料文件 */
async function onDownloadSources(sourceCodes: string[]) {
if (!sourceCodes.length) return;
busy.value = true;
try {
const result = await downloadTransferSourceFiles(sourceCodes);
triggerBlobDownload(result.blob, result.filename ?? `receipt-files-${sourceCodes.length}.zip`);
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
/** 重新获取 ERP 库存:批量重查后用服务端明细原位刷新(保留勾选中仍阻断的行) */
async function onRequery(invoiceNos: string[]) {
if (!invoiceNos.length || !transfer.precheckId.value) return;
busy.value = true;
try {
await requeryTransferItems(transfer.precheckId.value, invoiceNos);
const detail = await getTransferPrecheck(transfer.precheckId.value);
items.value = detail.items;
if (detail.summary) summaryRef.value = detail.summary;
const stillBlocked = new Set(
items.value.filter((item) => String(item.result).startsWith('blocked_')).map((item) => item.invoice_no),
);
transfer.selected.value = new Set([...transfer.selected.value].filter((no) => stillBlocked.has(no)));
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
/** 直接生成调拨单(决策 4/5:无独立确认页) */
async function onExecute(invoiceNos: string[]) {
busy.value = true;
try {
transfer.selected.value = new Set(invoiceNos);
const outcome = await transfer.execute();
if (outcome) {
mode.value = 'result';
runNo.value = outcome.run_no;
status.value = outcome.status;
run.value = transfer.run.value;
}
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
async function onDownloadReceipt() {
try {
await transfer.downloadReceiptFiles();
} catch (e) {
reportError(e);
}
}
async function onDownloadErp() {
try {
await transfer.downloadErpInventory();
} catch (e) {
reportError(e);
}
}
async function onDownloadExceptions() {
try {
await transfer.downloadExceptions();
} catch (e) {
reportError(e);
}
}
async function onBacklogRetry(itemId: number) {
busy.value = true;
try {
await transfer.retry(itemId);
await transfer.loadBacklog();
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
function onBacklogClose(item: TransferBacklogItem) {
closeTarget.value = item;
}
async function onCloseConfirm(reason: string) {
if (!closeTarget.value) return;
busy.value = true;
try {
await transfer.manualClose(closeTarget.value.item_id, reason);
closeTarget.value = null;
await transfer.loadBacklog();
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
/** 来源实例选择确认 → 创建预检并切换预检卡(决策 4:两步第一步;收料日期范围为查询范围;调拨类型决定数据范围) */
async function onSourceConfirm(
sourceCodes: string[],
dateRange?: { from?: string; to?: string },
transferType?: TransferType,
) {
busy.value = true;
try {
await transfer.createPrecheck(sourceCodes, undefined, dateRange, transferType);
mode.value = 'precheck';
summaryRef.value = transfer.precheck.value;
items.value = transfer.items.value;
run.value = null;
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
/** 对来源(单个或批量)重新触发收料 RPA 抓取,重试期间标记该来源(busy 独立于 confirm busy)。 */
async function onSourceRetry(sourceCodes: string[]) {
const codes = Array.isArray(sourceCodes) ? sourceCodes : [sourceCodes];
retryingSource.value = new Set([...retryingSource.value, ...codes]);
try {
// 逐来源触发,避免一次并发 EPR/RPA 竞态;失败中断剩余。
for (const code of codes) {
await transfer.retrySourceRpa(code);
}
} catch (e) {
reportError(e);
} finally {
const next = new Set(retryingSource.value);
for (const code of codes) next.delete(code);
retryingSource.value = next;
}
}
</script>
<template>
<div>
<TransferFileProgressCard
v-if="mode === 'file-progress'"
:sources="(props.payload?.sources as TransferSourceProgress[]) ?? []"
/>
<TransferSourceSelectCard
v-else-if="mode === 'source-select'"
:sources="transfer.sourceOptions.value"
:busy="busy"
:retrying="retryingSource"
@confirm="onSourceConfirm"
@download="onDownloadSources"
@retry="onSourceRetry"
/>
<TransferPrecheckCard
v-else-if="mode === 'precheck' && summaryRef"
:summary="summaryRef"
:items="items"
:sources="transfer.sources.value"
:selected="transfer.selected.value"
:requery-busy="busy"
:busy="busy"
@toggle="(invoiceNo, checked) => transfer.toggleSelect(invoiceNo, checked)"
@toggle-all="(invoiceNos, checked) => invoiceNos.forEach((no) => transfer.toggleSelect(no, checked))"
@requery="onRequery"
@execute="onExecute"
/>
<TransferProgressCard v-else-if="mode === 'progress'" :run-no="runNo" :status="status" :busy="busy" />
<TransferResultCard
v-else-if="mode === 'result' && run"
:run="run"
@download-receipt="onDownloadReceipt"
@download-erp="onDownloadErp"
@download-exceptions="onDownloadExceptions"
/>
<TransferBacklogSummaryCard
v-else-if="mode === 'backlog'"
:items="transfer.backlog.value"
@retry="onBacklogRetry"
@close="onBacklogClose"
@refresh="() => transfer.loadBacklog()"
/>
<TransferManualCloseDialog
v-if="closeTarget"
:open="Boolean(closeTarget)"
:invoice-no="closeTarget.invoice_no"
@confirm="onCloseConfirm"
@cancel="closeTarget = null"
/>
</div>
</template>