refactor(in-transit-transfer): 行归属解耦、按行执行三层门禁并重构术语为匹配

- 行不迁移:匹配记录降级为评估留痕(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 ✓
This commit is contained in:
hugo committed 2026-09-24 00:24:03 +08:00
1 parent f9f5053f0b
commit 0cf3c24119
108 files changed
+3660 -2356

No files matched your search

@@ -1,30 +1,33 @@
<!--
features/chat/components/messages/TransferMessageView.vue
用途:在途调拨消息卡片的自驱动挂载视图——按 payload 形态渲染卡片,并把卡片按钮
(生成调拨单 / 下载 / 重查 / 恢复 / 关闭)经 useChatTransfer 真实调用 API。
(生成调拨单 / 下载 / 重查 / 恢复处理 / 关闭)经 useChatTransfer 真实调用 API。
依赖:Transfer*Card、useChatTransfer、i18n chat.transfer.*。
逻辑:payload 作为初始状态(ChatLog 回放);仅携带 precheck_id 时按 ID 恢复预检卡
(最近预检入口);执行后切换为结果卡;下载走 requestBlob;
逻辑: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 TransferPrecheckCard from './TransferPrecheckCard.vue';
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, getTransferPrecheck, requeryTransferItems } from '../../api/transfer.api';
import { downloadTransferSourceFiles, getTransferMatching, requeryTransferMatchingItems } from '../../api/transfer.api';
import { triggerBlobDownload } from '@/shared/utils/download';
import { useMessage } from '@/shared/composables/useMessage';
import type {
TransferBacklogItem,
TransferPrecheckItem,
TransferPrecheckSummary,
TransferMatchingItem,
TransferMatchingSummary,
TransferRunResult,
TransferSourceProgress,
TransferType,
@@ -35,14 +38,14 @@ const props = defineProps<{
}>();
const { t } = useI18n();
const { error: notifyError, success: notifySuccess, warning: notifyWarning } = useMessage();
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 ?? 'precheck'));
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'>(() => {
@@ -50,8 +53,8 @@ const backlogInitialFilter = computed<'all' | 'recoverable' | 'closed' | 'unknow
const allowed = ['all', 'recoverable', 'closed', 'unknown'] as const;
return (allowed as readonly string[]).includes(value) ? (value as (typeof allowed)[number]) : 'all';
});
const summaryRef = ref<TransferPrecheckSummary | null>((props.payload?.summary as TransferPrecheckSummary) ?? null);
const items = ref<TransferPrecheckItem[]>((props.payload?.items as TransferPrecheckItem[]) ?? []);
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);
@@ -72,43 +75,28 @@ onMounted(() => {
if (kind.value === 'source-select') {
void transfer.loadSources();
}
// 最近预检入口:仅携带 precheck_id 无 summary,按 ID 恢复预检进度与明细。
if (kind.value === 'precheck' && !summaryRef.value && props.payload?.precheck_id) {
void restoreById(String(props.payload.precheck_id));
if (kind.value === 'executable') {
void transfer.loadExecutableItems();
}
});
/** 按预检号恢复预检卡(GET /prechecks/{id},页面刷新/最近预检入口共用)。 */
async function restoreById(precheckId: string) {
busy.value = true;
try {
const detail = await transfer.restorePrecheckById(precheckId);
mode.value = 'precheck';
summaryRef.value = detail.summary;
items.value = detail.items;
} catch (e) {
reportError(e);
} finally {
busy.value = false;
}
}
/** 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[]) ?? [];
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 TransferPrecheckSummary) ?? null;
const summaryValue = (payload.summary as TransferMatchingSummary) ?? null;
if (summaryValue) {
transfer.precheckId.value = summaryValue.precheck_id;
transfer.matchingId.value = summaryValue.matching_id;
// 默认勾选可执行明细行(按 item_id);历史回放行无 item_id 不参与勾选
transfer.selected.value = new Set(
(payload.items as TransferPrecheckItem[] ?? [])
.filter((item) => item.result === 'executable')
.map((item) => item.invoice_no),
((payload.items as TransferMatchingItem[]) ?? [])
.filter((item) => item.result === 'executable' && item.item_id != null)
.map((item) => item.item_id as number),
);
}
if (runNo.value) {
@@ -135,17 +123,21 @@ async function onDownloadSources(sourceCodes: string[]) {
/** 重新获取 ERP 库存:批量重查后用服务端明细原位刷新(保留勾选中仍阻断的行) */
async function onRequery(invoiceNos: string[]) {
if (!invoiceNos.length || !transfer.precheckId.value) return;
if (!invoiceNos.length || !transfer.matchingId.value) return;
busy.value = true;
try {
await requeryTransferItems(transfer.precheckId.value, invoiceNos);
const detail = await getTransferPrecheck(transfer.precheckId.value);
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 stillBlocked = new Set(
items.value.filter((item) => String(item.result).startsWith('blocked_')).map((item) => item.invoice_no),
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)),
);
transfer.selected.value = new Set([...transfer.selected.value].filter((no) => stillBlocked.has(no)));
} catch (e) {
reportError(e);
} finally {
@@ -153,11 +145,26 @@ async function onRequery(invoiceNos: string[]) {
}
}
/** 直接生成调拨单(决策 4/5:无独立确认页) */
async function onExecute(invoiceNos: string[]) {
/** 可调拨明细行重查:逐行核对最新库存后刷新队列(行级 retry 不依赖匹配) */
async function onExecutableRequery(itemIds: number[]) {
busy.value = true;
try {
transfer.selected.value = new Set(invoiceNos);
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';
@@ -223,39 +230,17 @@ async function onBacklogRequery(itemIds: number[]) {
}
}
/** 恢复处理(行级/多选):按(来源, 收料日期)分组重建预检。仅当重建预检
* 含可执行行才切换预检卡(其余份数引导到「最近预检」);全部仍阻断(ERP
* 未修正)不跳转,留在待处理池并明确提示;文件不可用的来源已触发重抓。 */
/** 恢复处理(行级/多选):恢复语义 = 按明细 id 重查库存(batch-requery 唯一后端);
* 完成后刷新待处理池,并按结果统计提示(ready_to_execute 计为已可执行,其余仍阻断);
* 不再跳转匹配卡(行式执行重构后恢复与匹配卡解耦)。 */
async function onBacklogResume(itemIds: number[]) {
busy.value = true;
try {
const result = await transfer.batchResume(itemIds);
const result = await transfer.resume(itemIds);
await transfer.loadBacklog();
const actionable = result.prechecks.filter((entry) => entry.executable_count > 0);
const firstActionable = actionable[0];
if (firstActionable) {
const detail = await transfer.restorePrecheckById(firstActionable.precheck_no);
mode.value = 'precheck';
summaryRef.value = detail.summary;
items.value = detail.items;
if (actionable.length > 1) {
notifySuccess(t('chat.transfer.toastResumeOpened', { count: actionable.length }));
}
}
const stillBlockedCount = result.prechecks
.filter((entry) => entry.executable_count === 0)
.reduce((sum, entry) => sum + entry.selected_item_count, 0);
if (stillBlockedCount) {
notifyWarning(t('chat.transfer.toastResumeStillBlocked', { count: stillBlockedCount }));
}
const refetching = result.file_fetching.filter((entry) => entry.ok).map((entry) => entry.source_code);
if (refetching.length) {
notifyWarning(t('chat.transfer.toastResumeRefetching', { sources: refetching.join('、') }));
}
const failedCount = result.file_fetching.filter((entry) => !entry.ok).length + result.skipped.length;
if (failedCount) {
notifyWarning(t('chat.transfer.toastResumeSkipped', { count: failedCount }));
}
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 {
@@ -297,7 +282,7 @@ async function onCloseConfirm(reason: string) {
}
}
/** 来源实例选择确认 → 创建预检并切换预检卡(决策 4:两步第一步;收料日期范围为查询范围;调拨类型决定数据范围) */
/** 来源实例选择确认 → 创建匹配并切换匹配卡(决策 4:两步第一步;收料日期范围为查询范围;调拨类型决定数据范围) */
async function onSourceConfirm(
sourceCodes: string[],
dateRange?: { from?: string; to?: string },
@@ -305,9 +290,9 @@ async function onSourceConfirm(
) {
busy.value = true;
try {
await transfer.createPrecheck(sourceCodes, undefined, dateRange, transferType);
mode.value = 'precheck';
summaryRef.value = transfer.precheck.value;
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) {
@@ -351,19 +336,27 @@ async function onSourceRetry(sourceCodes: string[]) {
@download="onDownloadSources"
@retry="onSourceRetry"
/>
<TransferPrecheckCard
v-else-if="mode === 'precheck' && summaryRef"
<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="(invoiceNo, checked) => transfer.toggleSelect(invoiceNo, checked)"
@toggle-all="(invoiceNos, checked) => invoiceNos.forEach((no) => transfer.toggleSelect(no, checked))"
@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"