feat(shipping_notice): 新增货代订单全流程业务模块及配套基建
本次提交新增货代订单处理全流程的完整业务能力、数据库迁移与测试用例: 1. 统一追加式审计事件体系,支持全链路不可篡改的业务追溯 2. 货代任务撤销、版本替代管控逻辑,规范已上传订单的合规版本更替 3. 订单抽取路由审计、模板自动冻结资格、路由计数等核心业务基建 4. EML订单补充表解析契约与合并逻辑,完善订单补全能力 5. Chatflow只读能力令牌校验机制,保障工具调用安全 6. 人工复核证据校验服务,规范人工审核的证据留存 所有变更均配套完整的单元测试与迁移契约测试,支持受控回退
This commit is contained in:
1 parent
90f77634d6
commit
1f3ecb87b7
128 files changed
+3635
-2074
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
updateWorkspaceShippingNoticeLine,
|
||||
type ShippingNoticeHeader,
|
||||
type ShippingNoticeLine,
|
||||
type ShippingReviewEvidence,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { getShippingParseReviewPayload } from './shippingParseReview';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
@@ -34,6 +35,7 @@ export interface ShippingParseReviewContext {
|
||||
* @returns 复核卡片同步与编辑处理函数集合
|
||||
*/
|
||||
export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContext) {
|
||||
const manualEvidence = (reason: string): ShippingReviewEvidence => ({ evidence_type: 'manual_input', reason });
|
||||
/**
|
||||
* 读取任务当前 order_data_version,供改单乐观锁使用。
|
||||
* @param taskId - 任务编号
|
||||
@@ -75,8 +77,10 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
const taskId = String(payload.taskId || '').trim().toUpperCase();
|
||||
try {
|
||||
const expectedOrderDataVersion = await resolveOrderDataVersion(taskId);
|
||||
if (expectedOrderDataVersion == null) throw new Error('订单版本不可用,请刷新后重试');
|
||||
await updateWorkspaceShippingNoticeFields(taskId, fields, '聊天区订单表修订', {
|
||||
expectedOrderDataVersion,
|
||||
evidence: manualEvidence('聊天区人工复核'), reason: '聊天区人工复核',
|
||||
idempotencyKey: `parse-review-header-${taskId}-${expectedOrderDataVersion ?? 'na'}-${Date.now()}`,
|
||||
});
|
||||
await syncShippingParseReviewCard(taskId);
|
||||
@@ -102,8 +106,10 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
const taskId = String(payload.taskId || '').trim().toUpperCase();
|
||||
try {
|
||||
const expectedOrderDataVersion = await resolveOrderDataVersion(taskId);
|
||||
if (expectedOrderDataVersion == null) throw new Error('订单版本不可用,请刷新后重试');
|
||||
await updateWorkspaceShippingNoticeLine(taskId, lineIndex, patch, '聊天区订单表修订', {
|
||||
expectedOrderDataVersion,
|
||||
evidence: manualEvidence('聊天区人工复核'), reason: '聊天区人工复核',
|
||||
idempotencyKey: `parse-review-line-${taskId}-${lineIndex}-${expectedOrderDataVersion ?? 'na'}`,
|
||||
});
|
||||
await syncShippingParseReviewCard(taskId);
|
||||
@@ -127,7 +133,11 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
payload.saving = true;
|
||||
const taskId = String(payload.taskId || '').trim().toUpperCase();
|
||||
try {
|
||||
await addWorkspaceShippingNoticeLine(taskId, line, '聊天区订单表新增行');
|
||||
const expectedOrderDataVersion = await resolveOrderDataVersion(taskId);
|
||||
if (expectedOrderDataVersion == null) throw new Error('订单版本不可用,请刷新后重试');
|
||||
await addWorkspaceShippingNoticeLine(taskId, line, '聊天区订单表新增行', {
|
||||
expectedOrderDataVersion, evidence: manualEvidence('聊天区人工新增行'), reason: '聊天区人工新增行',
|
||||
});
|
||||
await syncShippingParseReviewCard(taskId);
|
||||
await ctx.refreshShippingActions();
|
||||
return true;
|
||||
@@ -149,7 +159,11 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
payload.saving = true;
|
||||
const taskId = String(payload.taskId || '').trim().toUpperCase();
|
||||
try {
|
||||
await removeWorkspaceShippingNoticeLine(taskId, lineIndex, '聊天区订单表删除行');
|
||||
const expectedOrderDataVersion = await resolveOrderDataVersion(taskId);
|
||||
if (expectedOrderDataVersion == null) throw new Error('订单版本不可用,请刷新后重试');
|
||||
await removeWorkspaceShippingNoticeLine(taskId, lineIndex, '聊天区订单表删除行', {
|
||||
expectedOrderDataVersion, evidence: manualEvidence('聊天区人工删除行'), reason: '聊天区人工删除行',
|
||||
});
|
||||
await syncShippingParseReviewCard(taskId);
|
||||
await ctx.refreshShippingActions();
|
||||
return true;
|
||||
|
||||
@@ -39,7 +39,7 @@ const createContext = (
|
||||
getActiveShippingTaskId: () => '',
|
||||
lastAssistantMessageContent: () => '',
|
||||
lastAssistantShippingActions: () => [],
|
||||
sendMessage: vi.fn(async () => ({ accepted: true, completed: true })),
|
||||
sendMessage: vi.fn(async () => true),
|
||||
buildFileSpecsForSend: vi.fn(async () => []),
|
||||
loadHistory: vi.fn(async () => undefined),
|
||||
sendShippingMenuMessage: vi.fn(async () => undefined),
|
||||
@@ -51,7 +51,8 @@ const createContext = (
|
||||
handleShippingAutoUploadFile: vi.fn(async () => undefined),
|
||||
handleShippingAutoUploadNoticeBatch: vi.fn(async () => undefined),
|
||||
isShippingNoticeBatchSubmitting: () => isShippingNoticeBatchSubmitting(),
|
||||
startOrderExtractionRun: vi.fn(async () => true),
|
||||
markOrderExtractionStarted: vi.fn(),
|
||||
rollbackOrderExtractionStarted: vi.fn(),
|
||||
syncShippingConversationWorkspace: vi.fn(async () => true),
|
||||
refreshShippingActions: vi.fn(async () => undefined),
|
||||
shippingSuggestedPrompt: computed(() => ''),
|
||||
@@ -81,41 +82,8 @@ describe('useChatShippingSendHandler', () => {
|
||||
expect(ctx.msg.info).toHaveBeenCalledWith('chat.shippingNoticeBatchSubmitting');
|
||||
});
|
||||
|
||||
it('keeps a spreadsheet pending until the user explicitly declares it as inventory', async () => {
|
||||
const attachment = {
|
||||
id: 'spreadsheet', kind: 'local' as const,
|
||||
file: new File(['sheet'], 'unknown.xlsx', { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }),
|
||||
type: 'document' as const, uploadStatus: 'waiting' as const, uploadProgress: 0,
|
||||
};
|
||||
const ctx = createContext({ attachments: ref([attachment]) });
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.handleShippingAutoUploadFile).not.toHaveBeenCalled();
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
expect(ctx.msg.info).toHaveBeenCalledWith('chat.shippingNoticeSpreadsheetIntentRequired');
|
||||
expect(ctx.attachments.value).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('routes a declared xls spreadsheet to the isolated temporary inventory path', async () => {
|
||||
const attachment = {
|
||||
id: 'legacy-spreadsheet', kind: 'local' as const,
|
||||
file: new File(['sheet'], 'inventory.xls', { type: 'application/vnd.ms-excel' }),
|
||||
type: 'document' as const, uploadStatus: 'waiting' as const, uploadProgress: 0,
|
||||
};
|
||||
const ctx = createContext({ attachments: ref([attachment]), shippingAutoFlowRequested: ref(false) });
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow('这是库存文件,请分析', '这是库存文件,请分析', '这是库存文件,请分析');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.handleShippingAutoUploadFile).toHaveBeenCalledWith(attachment.file);
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates a background Run for parsed intakes without calling the Chatflow', async () => {
|
||||
it('sends parsed intakes to the existing Chatflow without requiring upload-time candidates', async () => {
|
||||
const completionOrder: string[] = [];
|
||||
const attachment = {
|
||||
id: 'notice-1',
|
||||
kind: 'shipping_notice' as const,
|
||||
@@ -132,6 +100,11 @@ describe('useChatShippingSendHandler', () => {
|
||||
hasCandidateReviewIssues: () => true,
|
||||
hasSelectedNoticeCandidates: () => true,
|
||||
getParsedIntakeNos: () => ['SNI-1'],
|
||||
applyShippingBatchSnapshot: vi.fn(() => { completionOrder.push('snapshot'); return true; }),
|
||||
refreshNoticeIntakeStatuses: vi.fn(async () => { completionOrder.push('intakes'); }),
|
||||
syncShippingConversationWorkspace: vi.fn(async () => { completionOrder.push('workspace'); return true; }),
|
||||
clearConsumedNoticeAttachments: vi.fn(() => { completionOrder.push('clear'); }),
|
||||
refreshShippingActions: vi.fn(async () => { completionOrder.push('actions'); }),
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
@@ -139,20 +112,34 @@ describe('useChatShippingSendHandler', () => {
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
expect(ctx.startOrderExtractionRun).toHaveBeenCalledWith(
|
||||
expect(ctx.sendMessage).toHaveBeenCalledWith(
|
||||
'chat.shippingOrderExtractionDefaultPrompt',
|
||||
['SNI-1'],
|
||||
[{
|
||||
id: 'notice-1',
|
||||
1,
|
||||
'',
|
||||
[],
|
||||
{
|
||||
shipping_intake_nos: ['SNI-1'],
|
||||
display_query: 'chat.shippingOrderExtractionDefaultPrompt',
|
||||
},
|
||||
expect.objectContaining({
|
||||
userAttachments: [{
|
||||
name: 'orders.eml',
|
||||
size: 100,
|
||||
extension: 'eml',
|
||||
type: 'document',
|
||||
source: 'shipping_notice',
|
||||
}],
|
||||
}],
|
||||
onAssistantMessageFinished: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expect(ctx.sendMessage).not.toHaveBeenCalled();
|
||||
expect(ctx.attachments.value).toEqual([]);
|
||||
expect(ctx.markOrderExtractionStarted).toHaveBeenCalledWith(['SNI-1']);
|
||||
|
||||
const hooks = vi.mocked(ctx.sendMessage).mock.calls[0]?.[5];
|
||||
const assistantMessage = { role: 'assistant', content: '已打开已有任务' } as const;
|
||||
await hooks?.onAssistantMessageFinished?.(assistantMessage, []);
|
||||
expect(ctx.applyShippingBatchSnapshot).toHaveBeenCalledWith(assistantMessage);
|
||||
expect(completionOrder).toEqual(['snapshot', 'intakes', 'workspace', 'clear', 'actions']);
|
||||
expect(ctx.syncShippingConversationWorkspace).toHaveBeenCalledWith({ preferLatest: true });
|
||||
});
|
||||
|
||||
it('uses the user query for full extraction even when no candidate exists before send', async () => {
|
||||
@@ -179,21 +166,32 @@ describe('useChatShippingSendHandler', () => {
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
expect(ctx.startOrderExtractionRun).toHaveBeenCalledWith(
|
||||
expect(ctx.sendMessage).toHaveBeenCalledWith(
|
||||
'请解析这些附件',
|
||||
['SNI-1'],
|
||||
[{
|
||||
id: 'notice-1',
|
||||
1,
|
||||
'',
|
||||
[],
|
||||
{
|
||||
shipping_intake_nos: ['SNI-1'],
|
||||
display_query: '请解析这些附件',
|
||||
},
|
||||
expect.objectContaining({
|
||||
userAttachments: [{
|
||||
name: 'orders.eml',
|
||||
size: 100,
|
||||
extension: 'eml',
|
||||
type: 'document',
|
||||
source: 'shipping_notice',
|
||||
}],
|
||||
}],
|
||||
onAssistantMessageFinished: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps attachments when Run creation reports not started', async () => {
|
||||
it('retries the conversation workspace once when the first refresh fails', async () => {
|
||||
const syncWorkspace = vi.fn()
|
||||
.mockResolvedValueOnce(false)
|
||||
.mockResolvedValueOnce(true);
|
||||
const ctx = createContext({
|
||||
attachments: ref([{
|
||||
id: 'notice-retry',
|
||||
@@ -207,15 +205,22 @@ describe('useChatShippingSendHandler', () => {
|
||||
intakeNo: 'SNI-RETRY',
|
||||
}]),
|
||||
getParsedIntakeNos: () => ['SNI-RETRY'],
|
||||
startOrderExtractionRun: vi.fn(async () => false),
|
||||
syncShippingConversationWorkspace: syncWorkspace,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
expect(ctx.attachments.value).toHaveLength(1);
|
||||
const hooks = vi.mocked(ctx.sendMessage).mock.calls[0]?.[5];
|
||||
await hooks?.onAssistantMessageFinished?.({} as never, []);
|
||||
|
||||
expect(syncWorkspace).toHaveBeenCalledTimes(2);
|
||||
expect(syncWorkspace).toHaveBeenNthCalledWith(1, { preferLatest: true });
|
||||
expect(syncWorkspace).toHaveBeenNthCalledWith(2, { preferLatest: true });
|
||||
expect(ctx.refreshShippingActions).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('keeps attachments and reports the error when Run creation fails', async () => {
|
||||
it('rolls back the local extracting state when the chat request fails', async () => {
|
||||
const rollback = vi.fn();
|
||||
const ctx = createContext({
|
||||
attachments: ref([{
|
||||
id: 'notice-failed-send',
|
||||
@@ -229,18 +234,20 @@ describe('useChatShippingSendHandler', () => {
|
||||
intakeNo: 'SNI-FAILED-SEND',
|
||||
}]),
|
||||
getParsedIntakeNos: () => ['SNI-FAILED-SEND'],
|
||||
startOrderExtractionRun: vi.fn(async () => { throw new Error('network failed'); }),
|
||||
sendMessage: vi.fn(async () => { throw new Error('network failed'); }),
|
||||
rollbackOrderExtractionStarted: rollback,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(rollback).toHaveBeenCalledWith(['SNI-FAILED-SEND']);
|
||||
expect(ctx.msg.warning).toHaveBeenCalledWith('network failed');
|
||||
expect(ctx.attachments.value).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('does not call the Chatflow when Run creation is handled as unavailable', async () => {
|
||||
it('rolls back extraction state when sendMessage reports a handled stream failure', async () => {
|
||||
const rollback = vi.fn();
|
||||
const ctx = createContext({
|
||||
attachments: ref([{
|
||||
id: 'notice-handled-failure',
|
||||
@@ -254,46 +261,15 @@ describe('useChatShippingSendHandler', () => {
|
||||
intakeNo: 'SNI-HANDLED-FAILURE',
|
||||
}]),
|
||||
getParsedIntakeNos: () => ['SNI-HANDLED-FAILURE'],
|
||||
startOrderExtractionRun: vi.fn(async () => false),
|
||||
sendMessage: vi.fn(async () => false),
|
||||
rollbackOrderExtractionStarted: rollback,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.sendMessage).not.toHaveBeenCalled();
|
||||
expect(ctx.attachments.value).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('removes only the Intake set accepted by the background Run', async () => {
|
||||
const submitted = {
|
||||
id: 'notice-accepted-error',
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: 'orders.eml',
|
||||
fileSize: 100,
|
||||
intakeNo: 'SNI-ACCEPTED-ERROR',
|
||||
};
|
||||
const retained = {
|
||||
...submitted,
|
||||
id: 'notice-retained',
|
||||
originalFilename: 'other.eml',
|
||||
intakeNo: 'SNI-RETAINED',
|
||||
};
|
||||
const ctx = createContext({
|
||||
attachments: ref([submitted, retained]),
|
||||
getParsedIntakeNos: () => ['SNI-ACCEPTED-ERROR'],
|
||||
startOrderExtractionRun: vi.fn(async () => true),
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.attachments.value).toEqual([retained]);
|
||||
expect(ctx.sendMessage).not.toHaveBeenCalled();
|
||||
expect(rollback).toHaveBeenCalledWith(['SNI-HANDLED-FAILURE']);
|
||||
expect(ctx.loadHistory).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,8 @@ describe('shipping notice order extraction state', () => {
|
||||
expect(isOrderExtractionEligibleIntake({ ...base, orderExtractionStatus: 'partially_completed' })).toBe(false);
|
||||
expect(isOrderExtractionEligibleIntake({ ...base, orderExtractionStatus: 'completed' })).toBe(false);
|
||||
expect(isOrderExtractionEligibleIntake({ ...base, orderExtractionStatus: 'failed' })).toBe(true);
|
||||
expect(isOrderExtractionEligibleIntake({ ...base, layoutStatus: 'processing' })).toBe(false);
|
||||
expect(isOrderExtractionEligibleIntake({ ...base, layoutStatus: 'completed' })).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps polling after preprocessing is parsed while order extraction is active', () => {
|
||||
@@ -46,6 +48,11 @@ describe('shipping notice order extraction state', () => {
|
||||
parseStatus: 'parsed',
|
||||
orderExtractionStatus: 'failed',
|
||||
})).toBe(false);
|
||||
expect(shouldPollShippingNoticeIntake({
|
||||
parseStatus: 'parsed',
|
||||
orderExtractionStatus: 'not_started',
|
||||
layoutStatus: 'processing',
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it('preserves the immediate extracting state until the backend leaves not_started', () => {
|
||||
@@ -61,6 +68,7 @@ describe('shipping notice order extraction state', () => {
|
||||
expect(shouldRestoreShippingNoticeIntake('parse_failed')).toBe(true);
|
||||
expect(shouldRestoreShippingNoticeIntake('parsed', 'failed', 0)).toBe(true);
|
||||
expect(shouldRestoreShippingNoticeIntake('parsed', 'partially_completed', 2)).toBe(true);
|
||||
expect(shouldRestoreShippingNoticeIntake('parsed', 'not_started', 0, 'processing')).toBe(true);
|
||||
|
||||
// 已完成且没有待审核 Candidate 的文件仅保留在用户消息气泡中。
|
||||
expect(shouldRestoreShippingNoticeIntake('parsed')).toBe(false);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* features/chat/shipping/useShippingNoticeIntakes.ts
|
||||
* 用途:发货通知选择即上传、创建 intake 与批量状态轮询编排。
|
||||
* 依赖:file-assets.api、shipping.api、shipping.types、shippingNoticeAttachmentIntegrity。
|
||||
* 依赖:file-assets.api、shipping.api、shipping.types、shippingNoticeAttachmentIntegrity、后端布局状态汇总。
|
||||
* 逻辑:useChatShipping / useChatAttachments 在货代 Agent 下委托本 composable 管理预解析附件;
|
||||
* 完整性判定委托 shippingNoticeAttachmentIntegrity(与后端契约对齐);会话刷新仅恢复未提交的处理中或解析失败附件。
|
||||
*/
|
||||
@@ -51,34 +51,55 @@ export function shouldRestoreShippingNoticeIntake(
|
||||
parseStatus: string | null | undefined,
|
||||
orderExtractionStatus?: string | null,
|
||||
candidateCount = 0,
|
||||
layoutStatus?: ShippingNoticePendingAttachment['layoutStatus'],
|
||||
): boolean {
|
||||
const status = String(parseStatus || '').trim().toLowerCase();
|
||||
const extractionStatus = String(orderExtractionStatus || '').trim().toLowerCase();
|
||||
return ACTIVE_PARSE.has(status)
|
||||
|| status === 'parse_failed'
|
||||
|| layoutStatus === 'processing'
|
||||
|| extractionStatus === 'failed'
|
||||
|| (extractionStatus === 'partially_completed' && candidateCount > 0);
|
||||
}
|
||||
|
||||
/** 判断 Intake 是否仍需轮询上传预处理或订单抽取状态。 */
|
||||
export function shouldPollShippingNoticeIntake(
|
||||
item: Pick<ShippingNoticePendingAttachment, 'parseStatus' | 'orderExtractionStatus'>,
|
||||
item: Pick<ShippingNoticePendingAttachment, 'parseStatus' | 'orderExtractionStatus' | 'layoutStatus'>,
|
||||
): boolean {
|
||||
return !TERMINAL_PARSE.has(item.parseStatus)
|
||||
|| ACTIVE_ORDER_EXTRACTION.has(String(item.orderExtractionStatus || '').trim().toLowerCase());
|
||||
|| ACTIVE_ORDER_EXTRACTION.has(String(item.orderExtractionStatus || '').trim().toLowerCase())
|
||||
|| item.layoutStatus === 'processing';
|
||||
}
|
||||
|
||||
/** 判断附件是否仍可作为新一轮完整订单抽取的输入。 */
|
||||
export function isOrderExtractionEligibleIntake(
|
||||
item: Pick<ShippingNoticePendingAttachment, 'intakeNo' | 'parseStatus' | 'parseSummary' | 'orderExtractionStatus'>,
|
||||
item: Pick<ShippingNoticePendingAttachment, 'intakeNo' | 'parseStatus' | 'parseSummary' | 'orderExtractionStatus' | 'layoutStatus'>,
|
||||
): boolean {
|
||||
const extractionStatus = String(item.orderExtractionStatus || 'not_started').trim().toLowerCase();
|
||||
return item.parseStatus === 'parsed'
|
||||
&& Boolean(item.intakeNo)
|
||||
&& (extractionStatus === 'not_started' || extractionStatus === 'failed')
|
||||
&& item.layoutStatus !== 'processing'
|
||||
&& !isShippingNoticeAttachmentParseIncomplete(item.parseSummary);
|
||||
}
|
||||
|
||||
/** 把后端布局汇总投影为附件卡片使用的最小状态,旧响应缺字段时保持兼容。 */
|
||||
function mapServerLayout(remote: ShippingNoticeIntakeResponse): Pick<ShippingNoticePendingAttachment, 'layoutStatus' | 'layoutSummary'> {
|
||||
const summary = remote.layout_summary;
|
||||
return {
|
||||
layoutStatus: remote.layout_status || summary?.status,
|
||||
layoutSummary: summary ? {
|
||||
total: Number(summary.total || 0),
|
||||
queued: Number(summary.queued || 0),
|
||||
running: Number(summary.running || 0),
|
||||
ready: Number(summary.ready || 0),
|
||||
needs_review: Number(summary.needs_review || 0),
|
||||
failed: Number(summary.failed || 0),
|
||||
unsupported: Number(summary.unsupported || 0),
|
||||
} : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/** 保留刚点击发送的本地 extracting,直到服务端进入真实抽取状态或返回终态。 */
|
||||
export function resolveShippingOrderExtractionStatus(localStatus?: string, remoteStatus?: string | null): string | undefined {
|
||||
const local = String(localStatus || '').trim().toLowerCase();
|
||||
@@ -239,6 +260,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
|| ACTIVE_PARSE.has(item.parseStatus)
|
||||
|| item.parseStatus === 'queued'
|
||||
|| item.parseStatus === 'parsing'
|
||||
|| item.layoutStatus === 'processing'
|
||||
|| ACTIVE_ORDER_EXTRACTION.has(String(item.orderExtractionStatus || '').trim().toLowerCase()),
|
||||
),
|
||||
);
|
||||
@@ -339,6 +361,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
remote.order_extraction_status,
|
||||
),
|
||||
parseSummary: (remote.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
...mapServerLayout(remote),
|
||||
errorCode: remote.order_extraction_error_code || remote.error_code || undefined,
|
||||
errorMessage: remote.order_extraction_error_message || remote.error_message || undefined,
|
||||
expiresAt: remote.expires_at || undefined,
|
||||
@@ -369,6 +392,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
parseStatus: mapServerParseStatus(intake.parse_status),
|
||||
orderExtractionStatus: intake.order_extraction_status || undefined,
|
||||
parseSummary: (intake.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
...mapServerLayout(intake),
|
||||
errorCode: intake.order_extraction_error_code || intake.error_code || undefined,
|
||||
errorMessage: intake.order_extraction_error_message || intake.error_message || undefined,
|
||||
expiresAt: intake.expires_at || undefined,
|
||||
@@ -421,6 +445,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
patchAttachment(id, {
|
||||
parseStatus: mapServerParseStatus(intake.parse_status),
|
||||
parseSummary: (intake.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
...mapServerLayout(intake),
|
||||
errorCode: intake.error_code || undefined,
|
||||
errorMessage: intake.error_message || undefined,
|
||||
});
|
||||
@@ -472,6 +497,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
item.parse_status,
|
||||
item.order_extraction_status,
|
||||
item.candidates?.length || 0,
|
||||
item.layout_status,
|
||||
))
|
||||
.map((item) => ({
|
||||
id: `restored_${item.intake_no}`,
|
||||
@@ -486,6 +512,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
originalFilename: item.original_filename || item.intake_no,
|
||||
fileSize: Number(item.file_size || 0),
|
||||
parseSummary: (item.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
...mapServerLayout(item),
|
||||
errorCode: item.order_extraction_error_code || item.error_code || undefined,
|
||||
errorMessage: item.order_extraction_error_message || item.error_message || undefined,
|
||||
expiresAt: item.expires_at || undefined,
|
||||
@@ -515,6 +542,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
);
|
||||
patchAttachment(target.id, {
|
||||
parseStatus: mapServerParseStatus(intake.parse_status),
|
||||
...mapServerLayout(intake),
|
||||
...mapServerDuplicate(intake),
|
||||
});
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user