- 行不迁移:匹配记录降级为评估留痕(scope/counts/hash 留痕不拦执行), 匹配/重查原地刷新行并续行级新鲜度(updated_at) - 执行改按行:POST /items/execute 三层门禁(行级新鲜度 TTL/文件版本对账/写前复查), Run 留痕不绑匹配记录;消失行 blocked_file_removed fail-closed 入异常池 - 恢复处理收敛为行级重查(batch-resume 删除);待处理池补齐匹配窗口字段, 排序改业务稳定键(收料日期→Invoice→created_at,操作不再引起跳位) - 首页待办看板四队列:可调拨明细/待恢复异常/已人工关闭/结果未知;「最近预检」移除; 收料日期默认 T-1 并加输入期限制;「重新查询 ERP」更名「重查」 - 术语重构 precheck→match:表 transfer_matchings、列 matching_id/matching_no/matching_hash、 API /matchings、单号前缀 MTG、状态值 prechecking→matching(迁移 rn1a2b3c4d5e6,模块未上线无兼容层) - 修复 integration_connector mapping 扇出嵌套丢行缺陷;对账结论:0 vs 30/40/36 系收料仓库映射曾指向错误账套 TGHX(已改 TGHX1),探针留档 backend/tmp - 测试:后端 in_transit_transfer+api+connector 393 passed;前端 chat 713 passed;build ✓
390 lines
14 KiB
Vue
390 lines
14 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;
|
||
恢复处理 = 按明细 id 重查库存(batch-requery 唯一后端),完成后刷新待处理池并
|
||
统计提示,不再跳转匹配卡;执行后切换为结果卡;下载走 requestBlob;
|
||
不展示执行审计入口(决策 19)。
|
||
-->
|
||
<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, requeryTransferMatchingItems } from '../../api/transfer.api';
|
||
import { triggerBlobDownload } from '@/shared/utils/download';
|
||
import { useMessage } from '@/shared/composables/useMessage';
|
||
import type {
|
||
TransferBacklogItem,
|
||
TransferMatchingItem,
|
||
TransferMatchingSummary,
|
||
TransferRunResult,
|
||
TransferSourceProgress,
|
||
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());
|
||
|
||
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);
|
||
|
||
/** 打包下载选中来源的最新归档收料文件 */
|
||
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;
|
||
}
|
||
}
|
||
|
||
/** 按勾选明细行直接生成调拨单(item-centric:门禁在后端,失败经 reportError 展示) */
|
||
async function onExecute(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
transfer.selected.value = new Set(itemIds);
|
||
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;
|
||
}
|
||
}
|
||
|
||
/** 批量重查(待处理池多选):逐行隔离,完成后刷新列表并弹汇总。 */
|
||
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" />
|
||
<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"
|
||
: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>
|