- 新增 TransferDocument 按票执行模型与单据号序列生成(document_id 独立模块,迁移 tt0d/tt8b) - 发票行新增单位字段、matching_id 放宽可空,支持行与票两级执行口径(迁移 tt9c/tt1a) - capability_client 新增 create_transfer 写契约与六态结果裁决,执行链补写前复查门禁 - 抽取/匹配/执行 Job 按 run/item/match 拆分并入 jobs store 队列,transfer 队列单实例 worker 配套本地启动脚本 - 首页新增「已执行调拨单」四统计卡入口与明细列表子视图,重查/重试/关闭/重新触发与筛选分页齐全 - 行评估新鲜度 TTL 从 10 分钟放宽为当日有效(86400s),跨日由文件版本对账门禁兜底 - 同步 chat/errors 文案四语言、测试全家与两份实施计划文档
472 lines
18 KiB
Vue
472 lines
18 KiB
Vue
<!--
|
||
features/chat/components/messages/TransferMessageView.vue
|
||
用途:在途调拨消息卡片的自驱动挂载视图——按 payload 形态渲染卡片,并把卡片按钮
|
||
(生成调拨单 / 下载 / 重查 / 恢复处理 / 关闭 / 重新触发 / 关闭单)经 useChatTransfer 真实调用 API。
|
||
依赖:Transfer*Card、useChatTransfer、i18n chat.transfer.*。
|
||
逻辑:payload 作为初始状态(ChatLog 回放;历史行无 item_id 仅展示不可选);仅携带
|
||
matching_id 时按 ID 恢复匹配卡(最近匹配入口);勾选/执行按明细 item_id;
|
||
来源选择卡重试收料 RPA 为 202 异步——存在抓取中来源时组合式函数自动轮询
|
||
GET /sources,RPA 回调收口后状态自动刷新,离开来源卡即停轮询;
|
||
恢复处理 = 按明细 id 重查库存(batch-requery 唯一后端),完成后刷新待处理池并
|
||
统计提示,不再跳转匹配卡;预检卡提交 202(D8)→ 切融合卡 kind='run'(run_no 传卡,
|
||
轮询由融合卡自驱动,父级停自身轮询),门禁 4xx → useMessage 行内报错 + 预检状态刷新;
|
||
融合卡失败单「重查库存」复用 batch-requery(会话明细行关联 item_id)、「关闭单」
|
||
上抛 closed 事件后刷新 run 调拨单清单与可执行池(D18 行脱离回 ready_to_execute);
|
||
下载走 requestBlob;不展示执行审计入口(决策 19);全程无取消执行入口(D9)。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, ref, watch } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import TransferMatchCard from './TransferMatchCard.vue';
|
||
import TransferFileProgressCard from './TransferFileProgressCard.vue';
|
||
import TransferProgressCard from './TransferProgressCard.vue';
|
||
import TransferResultCard from './TransferResultCard.vue';
|
||
import TransferBacklogSummaryCard from './TransferBacklogSummaryCard.vue';
|
||
import TransferExecutableCard from './TransferExecutableCard.vue';
|
||
import TransferManualCloseDialog from './TransferManualCloseDialog.vue';
|
||
import TransferSourceSelectCard from './TransferSourceSelectCard.vue';
|
||
import { useChatTransfer } from '../../composables/useChatTransfer';
|
||
import { downloadTransferSourceFiles, getTransferMatching, retryTransferOrder, requeryTransferMatchingItems } from '../../api/transfer.api';
|
||
import { triggerBlobDownload } from '@/shared/utils/download';
|
||
import { useMessage } from '@/shared/composables/useMessage';
|
||
import type {
|
||
TransferBacklogItem,
|
||
TransferMatchingItem,
|
||
TransferMatchingSummary,
|
||
TransferRunResult,
|
||
TransferSourceProgress,
|
||
TransferOrder,
|
||
TransferType,
|
||
} from '../../types/transfer.types';
|
||
|
||
const props = defineProps<{
|
||
payload?: Record<string, unknown> | null;
|
||
}>();
|
||
|
||
const { t } = useI18n();
|
||
const { error: notifyError, success: notifySuccess } = useMessage();
|
||
|
||
/** 统一错误提示:BusinessError 带本地化 message,其余回退到 String(e)。 */
|
||
function reportError(e: unknown) {
|
||
notifyError(e instanceof Error ? e.message : String(e));
|
||
}
|
||
|
||
const kind = computed(() => String(props.payload?.kind ?? 'match'));
|
||
const mode = ref(kind.value);
|
||
/** backlog 初始筛选(首页计数卡切片进入:recoverable/closed/unknown;白名单外回落 all)。 */
|
||
const backlogInitialFilter = computed<'all' | 'recoverable' | 'closed' | 'unknown'>(() => {
|
||
const value = String(props.payload?.filter ?? 'all');
|
||
const allowed = ['all', 'recoverable', 'closed', 'unknown'] as const;
|
||
return (allowed as readonly string[]).includes(value) ? (value as (typeof allowed)[number]) : 'all';
|
||
});
|
||
const summaryRef = ref<TransferMatchingSummary | null>((props.payload?.summary as TransferMatchingSummary) ?? null);
|
||
const items = ref<TransferMatchingItem[]>((props.payload?.items as TransferMatchingItem[]) ?? []);
|
||
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);
|
||
/** 批量标记无需处理的明细 id 集合(与单行关闭共用同一弹窗)。 */
|
||
const batchCloseIds = ref<number[]>([]);
|
||
/** 正在重试收料 RPA 的来源编码集合(按来源独立展示重试中)。 */
|
||
const retryingSource = ref<Set<string>>(new Set());
|
||
/** 上次提交执行的明细行快照(失败单「重查库存」按物料/收料日期关联 item_id 用)。 */
|
||
const lastExecutedItems = ref<TransferMatchingItem[]>([]);
|
||
|
||
const transfer = useChatTransfer();
|
||
|
||
/** 待处理异常视图:进入时拉取列表与汇总 */
|
||
onMounted(() => {
|
||
if (kind.value === 'backlog') {
|
||
void transfer.loadBacklog();
|
||
}
|
||
if (kind.value === 'source-select') {
|
||
void transfer.loadSources();
|
||
}
|
||
if (kind.value === 'executable') {
|
||
void transfer.loadExecutableItems();
|
||
}
|
||
});
|
||
|
||
/** payload 更新时重置本地状态(历史回放/刷新);初始化组合式函数上下文 */
|
||
function applyPayload(payload?: Record<string, unknown> | null) {
|
||
if (!payload) return;
|
||
mode.value = String(payload.kind ?? 'match');
|
||
summaryRef.value = (payload.summary as TransferMatchingSummary) ?? null;
|
||
items.value = (payload.items as TransferMatchingItem[]) ?? [];
|
||
runNo.value = String(payload.run_no ?? '');
|
||
status.value = String(payload.status ?? 'executing');
|
||
run.value = (payload.run as TransferRunResult) ?? null;
|
||
const summaryValue = (payload.summary as TransferMatchingSummary) ?? null;
|
||
if (summaryValue) {
|
||
transfer.matchingId.value = summaryValue.matching_id;
|
||
// 默认勾选可执行明细行(按 item_id);历史回放行无 item_id 不参与勾选
|
||
transfer.selected.value = new Set(
|
||
((payload.items as TransferMatchingItem[]) ?? [])
|
||
.filter((item) => item.result === 'executable' && item.item_id != null)
|
||
.map((item) => item.item_id as number),
|
||
);
|
||
}
|
||
if (runNo.value) {
|
||
transfer.runNo.value = runNo.value;
|
||
}
|
||
}
|
||
|
||
applyPayload(props.payload);
|
||
watch(() => props.payload, applyPayload);
|
||
|
||
// 离开来源选择卡即停来源轮询(确认匹配切匹配卡/回放替换 payload 后,
|
||
// 来源抓取状态与本卡无关;轮询实例由 useChatTransfer 作用域销毁兜底清理)
|
||
watch(mode, (value) => {
|
||
if (value !== 'source-select') transfer.stopSourcePolling();
|
||
});
|
||
|
||
/** 打包下载选中来源的最新归档收料文件 */
|
||
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.matchingId.value) return;
|
||
busy.value = true;
|
||
try {
|
||
await requeryTransferMatchingItems(transfer.matchingId.value, invoiceNos);
|
||
const detail = await getTransferMatching(transfer.matchingId.value);
|
||
items.value = detail.items;
|
||
if (detail.summary) summaryRef.value = detail.summary;
|
||
const stillBlockedIds = new Set(
|
||
items.value
|
||
.filter((item) => String(item.result).startsWith('blocked_') && item.item_id != null)
|
||
.map((item) => item.item_id as number),
|
||
);
|
||
transfer.selected.value = new Set(
|
||
[...transfer.selected.value].filter((id) => stillBlockedIds.has(id)),
|
||
);
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 可调拨明细行重查:逐行核对最新库存后刷新队列(行级 retry 不依赖匹配) */
|
||
async function onExecutableRequery(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
for (const itemId of itemIds) {
|
||
await transfer.retry(itemId);
|
||
}
|
||
await transfer.loadExecutableItems();
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 预检卡提交(匹配卡/可执行卡点「生成调拨单」):门禁在后端,失败抛 BusinessError。
|
||
* D8 异步 202:只拿 {run_no, status:'queued'} 即切融合卡(kind='run')——
|
||
* 融合卡自驱动轮询接管进度/结果,父级停掉本实例轮询防双打点;提交受理 toast 反馈。
|
||
* 门禁 4xx:useMessage 行内报错 + 预检状态刷新(匹配详情/可执行池可能已变化)。
|
||
*/
|
||
async function onExecute(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
transfer.selected.value = new Set(itemIds);
|
||
// 快照本次执行明细行(融合卡失败单「重查库存」关联 item_id 的数据源之一):
|
||
// 本地 items(匹配卡回放)/ composable 匹配与可执行池三处都可能持有行记录
|
||
const executedSet = new Set(itemIds);
|
||
lastExecutedItems.value = [...items.value, ...transfer.items.value, ...transfer.executableItems.value]
|
||
.filter((item) => item.item_id != null && executedSet.has(item.item_id));
|
||
const outcome = await transfer.execute();
|
||
if (outcome) {
|
||
transfer.stopRunPolling(); // 融合卡(自驱动轮询)接管,父级轮询停止
|
||
mode.value = 'run';
|
||
runNo.value = outcome.run_no;
|
||
status.value = outcome.status;
|
||
run.value = transfer.run.value;
|
||
notifySuccess(t('chat.transfer.execute.accepted'));
|
||
}
|
||
} catch (e) {
|
||
reportError(e);
|
||
await refreshPrecheckState();
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 门禁失败后的预检状态刷新(best-effort:匹配视图重拉详情、可执行池重拉队列,不掩盖原错误)。 */
|
||
async function refreshPrecheckState() {
|
||
try {
|
||
if (mode.value === 'match' && transfer.matchingId.value) {
|
||
await transfer.refreshMatching();
|
||
} else if (mode.value === 'executable') {
|
||
await transfer.loadExecutableItems();
|
||
}
|
||
} catch {
|
||
// 刷新失败静默:原门禁错误已经 useMessage 提示
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 融合卡失败单「重试」(一键恢复主路径):POST /documents/{doc_no}/retry——
|
||
* 后端按单圈行逐行重查,全部 ready 自动建新 Run 重跑(复用原单号,分支②);
|
||
* 部分行仍阻断则不重跑,阻断明细以 toast 摘要提示、行留恢复池。
|
||
*/
|
||
async function onOrderRetry(order: TransferOrder) {
|
||
busy.value = true;
|
||
try {
|
||
const result = await retryTransferOrder(order.doc_no);
|
||
if (result.rerun) {
|
||
notifySuccess(t('chat.transfer.orderAction.retryAccepted', { docNo: order.doc_no }));
|
||
} else {
|
||
notifyError(t('chat.transfer.orderAction.retryPartial', {
|
||
ready: result.ready,
|
||
blocked: result.blocked.length,
|
||
}));
|
||
}
|
||
await refreshPrecheckState();
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 融合卡关闭单完成(D18 上抛事件):行脱离单回 ready_to_execute——
|
||
* 父级刷新 run 调拨单清单与可执行池(best-effort,失败经 useMessage 提示)。
|
||
*/
|
||
async function onOrderClosed() {
|
||
try {
|
||
await transfer.refreshRun();
|
||
await transfer.loadExecutableItems();
|
||
} catch (e) {
|
||
reportError(e);
|
||
}
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
/** 批量重查(待处理池多选):逐行隔离,完成后刷新列表并弹汇总。 */
|
||
async function onBacklogRequery(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
const result = await transfer.batchRequery(itemIds);
|
||
const ok = result.results.filter((entry) => entry.ok).length;
|
||
notifySuccess(t('chat.transfer.toastRequeryDone', { ok, failed: result.total - ok }));
|
||
await transfer.loadBacklog();
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 恢复处理(行级/多选):恢复语义 = 按明细 id 重查库存(batch-requery 唯一后端);
|
||
* 完成后刷新待处理池,并按结果统计提示(ready_to_execute 计为已可执行,其余仍阻断);
|
||
* 不再跳转匹配卡(行式执行重构后恢复与匹配卡解耦)。 */
|
||
async function onBacklogResume(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
const result = await transfer.resume(itemIds);
|
||
await transfer.loadBacklog();
|
||
const recovered = result.results.filter((entry) => entry.status === 'ready_to_execute').length;
|
||
const still = result.total - recovered;
|
||
notifySuccess(t('chat.transfer.toastRequeryRecovered', { recovered, blocked: still }));
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
function onBacklogClose(item: TransferBacklogItem) {
|
||
closeTarget.value = item;
|
||
}
|
||
|
||
/** 批量标记无需处理:复用关闭弹窗(批量文案)。 */
|
||
function onBacklogBatchClose(itemIds: number[]) {
|
||
batchCloseIds.value = itemIds;
|
||
}
|
||
|
||
function onCancelClose() {
|
||
closeTarget.value = null;
|
||
batchCloseIds.value = [];
|
||
}
|
||
|
||
async function onCloseConfirm(reason: string) {
|
||
busy.value = true;
|
||
try {
|
||
if (batchCloseIds.value.length) {
|
||
const result = await transfer.batchManualClose(batchCloseIds.value, reason);
|
||
const ok = result.results.filter((entry) => entry.ok).length;
|
||
notifySuccess(t('chat.transfer.toastCloseDone', { ok, failed: result.total - ok }));
|
||
batchCloseIds.value = [];
|
||
} else if (closeTarget.value) {
|
||
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.createMatching(sourceCodes, undefined, dateRange, transferType);
|
||
mode.value = 'match';
|
||
summaryRef.value = transfer.matching.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"
|
||
/>
|
||
<TransferMatchCard
|
||
v-else-if="mode === 'match' && summaryRef"
|
||
:summary="summaryRef"
|
||
:items="items"
|
||
:sources="transfer.sources.value"
|
||
:selected="transfer.selected.value"
|
||
:requery-busy="busy"
|
||
:busy="busy"
|
||
@toggle="(itemId, checked) => transfer.toggleSelect(itemId, checked)"
|
||
@toggle-all="(itemIds, checked) => itemIds.forEach((id) => transfer.toggleSelect(id, checked))"
|
||
@requery="onRequery"
|
||
@execute="onExecute"
|
||
/>
|
||
<TransferExecutableCard
|
||
v-else-if="mode === 'executable'"
|
||
:items="transfer.executableItems.value"
|
||
:busy="busy"
|
||
@refresh="() => transfer.loadExecutableItems()"
|
||
@requery="onExecutableRequery"
|
||
@execute="onExecute"
|
||
/>
|
||
<TransferProgressCard v-else-if="mode === 'progress'" :run-no="runNo" :status="status" :busy="busy" />
|
||
<!-- 融合卡(D9:调拨单清单=进度=结果):run_no 自驱动轮询;kind='run' 为 202 新流程,'result' 兼容历史回放 -->
|
||
<TransferResultCard
|
||
v-else-if="(mode === 'run' || mode === 'result') && (runNo || run?.run_no)"
|
||
:run-no="runNo || String(run?.run_no ?? '')"
|
||
:initial-run="run"
|
||
@download-receipt="onDownloadReceipt"
|
||
@download-erp="onDownloadErp"
|
||
@download-exceptions="onDownloadExceptions"
|
||
@retry="onOrderRetry"
|
||
@closed="onOrderClosed"
|
||
/>
|
||
<TransferBacklogSummaryCard
|
||
v-else-if="mode === 'backlog'"
|
||
:items="transfer.backlog.value"
|
||
:busy="busy"
|
||
:initial-filter="backlogInitialFilter"
|
||
@retry="onBacklogRetry"
|
||
@requery="onBacklogRequery"
|
||
@resume="onBacklogResume"
|
||
@close="onBacklogClose"
|
||
@batch-close="onBacklogBatchClose"
|
||
@refresh="() => transfer.loadBacklog()"
|
||
/>
|
||
<TransferManualCloseDialog
|
||
v-if="closeTarget || batchCloseIds.length"
|
||
:open="Boolean(closeTarget || batchCloseIds.length)"
|
||
:invoice-no="closeTarget?.invoice_no ?? ''"
|
||
:count="batchCloseIds.length"
|
||
@confirm="onCloseConfirm"
|
||
@cancel="onCancelClose"
|
||
/>
|
||
</div>
|
||
</template>
|