feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估
- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。 - 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。 - 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。 - 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。 - 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
1 parent
cef3d5b26a
commit
3a9fbac2fc
226 files changed
+25010
-2098
No files matched your search
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* features/chat/shipping/conversationProcessingProjection.spec.ts
|
||||
* 用途:验收「本次处理中」对象投影——Run/Candidate/Task/Gate 聚合与聚焦。
|
||||
* 依赖:Vitest、conversationProcessingProjection。
|
||||
* 逻辑:构造 WorkflowItem;断言去重、聚焦标记与 Gate 行。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
mapLifecycleToNodeStatus,
|
||||
projectConversationProcessingObjects,
|
||||
} from './conversationProcessingProjection';
|
||||
import type { ShippingWorkflowItem } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
function item(partial: Partial<ShippingWorkflowItem>): ShippingWorkflowItem {
|
||||
return {
|
||||
item_no: 'WI-1',
|
||||
workflow_no: 'WF-1',
|
||||
conversation_id: 'conv-1',
|
||||
root_document_id: 1,
|
||||
current_document_id: 1,
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'pending_review',
|
||||
current_stage: 'pending_review',
|
||||
lock_version: 1,
|
||||
...partial,
|
||||
};
|
||||
}
|
||||
|
||||
describe('conversationProcessingProjection', () => {
|
||||
it('maps lifecycle to node status without inventing percentages', () => {
|
||||
expect(mapLifecycleToNodeStatus('inventory_matching')).toBe('running');
|
||||
expect(mapLifecycleToNodeStatus('failed')).toBe('failed');
|
||||
expect(mapLifecycleToNodeStatus('closed')).toBe('succeeded');
|
||||
});
|
||||
|
||||
it('projects run / candidate / task / process_gate rows and focus', () => {
|
||||
const rows = projectConversationProcessingObjects([
|
||||
item({
|
||||
item_no: 'WI-1',
|
||||
current_run_no: 'RUN-1',
|
||||
current_case_no: 'CASE-1',
|
||||
current_task_no: 'SN-1',
|
||||
lifecycle_status: 'pending_review',
|
||||
process_gate: {
|
||||
execution_no: 'EX-1',
|
||||
status: 'blocked',
|
||||
current_blocking_gate: {
|
||||
gate_code: 'inventory_matching',
|
||||
sequence_no: 1,
|
||||
status: 'blocked_manual',
|
||||
evaluation_version: 1,
|
||||
},
|
||||
task_no: 'SN-1',
|
||||
},
|
||||
}),
|
||||
item({
|
||||
item_no: 'WI-2',
|
||||
current_run_no: 'RUN-1',
|
||||
current_task_no: 'SN-1',
|
||||
lifecycle_status: 'inventory_matching',
|
||||
}),
|
||||
], { focusTaskNo: 'SN-1', focusRunNo: 'RUN-1' });
|
||||
|
||||
// 关键断言:同 Run/Task 去重;聚焦 Task;含 Gate。
|
||||
expect(rows.filter((row) => row.kind === 'run')).toHaveLength(1);
|
||||
expect(rows.filter((row) => row.kind === 'task')).toHaveLength(1);
|
||||
expect(rows.find((row) => row.kind === 'task')?.focused).toBe(true);
|
||||
expect(rows.some((row) => row.kind === 'candidate')).toBe(true);
|
||||
expect(rows.some((row) => row.kind === 'process_gate')).toBe(true);
|
||||
});
|
||||
|
||||
it('prefers backend node_status over lifecycle mapping for tasks', () => {
|
||||
const rows = projectConversationProcessingObjects([
|
||||
item({
|
||||
current_run_no: 'RUN-2',
|
||||
current_task_no: 'SN-2',
|
||||
lifecycle_status: 'inventory_matching',
|
||||
node_status: 'manual_takeover',
|
||||
progress_nodes: [
|
||||
{ code: 'freight_upload', label: '货代上传', status: 'manual_takeover' },
|
||||
],
|
||||
}),
|
||||
]);
|
||||
// 关键断言:侧栏 Task 使用后端权威 node_status,不覆盖为 running。
|
||||
expect(rows.find((row) => row.kind === 'task')?.node_status).toBe('manual_takeover');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
* features/chat/shipping/conversationProcessingProjection.ts
|
||||
* 用途:将现有 Workflow Items 投影为对话「本次处理中」统一对象行。
|
||||
* 依赖:shipping.api.types(ConversationProcessingObject / WorkflowNodeStatus)。
|
||||
* 逻辑:Timeline 复用本投影;Task 优先消费后端 node_status / progress_nodes;
|
||||
* 不伪造进度百分比。
|
||||
*/
|
||||
|
||||
import type {
|
||||
ConversationProcessingObject,
|
||||
ShippingWorkflowItem,
|
||||
WorkflowNodeStatus,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
/**
|
||||
* 将生命周期状态映射为 WorkflowNodeStatus(展示用,非进度百分比)。
|
||||
*/
|
||||
export function mapLifecycleToNodeStatus(
|
||||
lifecycle: string | null | undefined,
|
||||
): WorkflowNodeStatus {
|
||||
const status = String(lifecycle || '').trim();
|
||||
if (!status || status === 'queued') return 'pending';
|
||||
if (
|
||||
status === 'layout_parsing'
|
||||
|| status === 'extracting'
|
||||
|| status === 'building_order'
|
||||
|| status === 'inventory_matching'
|
||||
|| status === 'generating_excel'
|
||||
) {
|
||||
return 'running';
|
||||
}
|
||||
if (status === 'failed' || status === 'reparse_failed') return 'failed';
|
||||
if (status === 'upload_rpa_pending' || status === 'upload_rpa_running') {
|
||||
return 'running';
|
||||
}
|
||||
if (status === 'upload_rpa_failed') return 'failed';
|
||||
if (status === 'pending_review' || status === 'manual_upload_pending') {
|
||||
return 'manual_takeover';
|
||||
}
|
||||
if (status === 'closed' || status === 'cancelled') return 'succeeded';
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
/**
|
||||
* 取 Item 用户可见状态:细粒度 display/current_stage 优先。
|
||||
*/
|
||||
export function resolveItemDisplayStatus(item: ShippingWorkflowItem): string {
|
||||
const display = String(item.display_lifecycle_status || '').trim();
|
||||
if (display) return display;
|
||||
const stage = String(item.current_stage || '').trim();
|
||||
if (
|
||||
stage === 'upload_rpa_pending'
|
||||
|| stage === 'upload_rpa_running'
|
||||
|| stage === 'upload_rpa_failed'
|
||||
) {
|
||||
return stage;
|
||||
}
|
||||
return String(item.lifecycle_status || '').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Workflow Items 聚合 Run / Candidate / Task / Process Gate 侧栏行。
|
||||
*
|
||||
* 核心逻辑:同一 run_no / task_no 去重;Gate 取每项首个阻断门禁;
|
||||
* focusTaskNo 命中时标记 focused。
|
||||
*
|
||||
* @param items - 当前会话 Workflow Items
|
||||
* @param options.focusTaskNo - 当前聚焦 Task
|
||||
* @param options.focusRunNo - 当前聚焦 Run
|
||||
*/
|
||||
export function projectConversationProcessingObjects(
|
||||
items: ShippingWorkflowItem[],
|
||||
options?: {
|
||||
focusTaskNo?: string | null;
|
||||
focusRunNo?: string | null;
|
||||
focusCandidateNo?: string | null;
|
||||
},
|
||||
): ConversationProcessingObject[] {
|
||||
const focusTask = String(options?.focusTaskNo || '').trim().toUpperCase();
|
||||
const focusRun = String(options?.focusRunNo || '').trim();
|
||||
const focusCandidate = String(options?.focusCandidateNo || '').trim();
|
||||
const rows: ConversationProcessingObject[] = [];
|
||||
const seenRuns = new Set<string>();
|
||||
const seenTasks = new Set<string>();
|
||||
const seenGates = new Set<string>();
|
||||
|
||||
for (const item of items || []) {
|
||||
const runNo = String(item.current_run_no || '').trim();
|
||||
const taskNo = String(item.current_task_no || '').trim().toUpperCase();
|
||||
const caseNo = String(item.current_case_no || '').trim();
|
||||
const itemNo = String(item.item_no || '').trim();
|
||||
const documentId = Number(item.current_document_id || 0) || null;
|
||||
// 优先消费后端权威 node_status;缺失时才用 lifecycle 本地映射。
|
||||
const displayStatus = resolveItemDisplayStatus(item);
|
||||
const backendNodeStatus = String(item.node_status || '').trim() as WorkflowNodeStatus | '';
|
||||
const nodeStatus = backendNodeStatus || mapLifecycleToNodeStatus(displayStatus);
|
||||
|
||||
if (runNo && !seenRuns.has(runNo)) {
|
||||
seenRuns.add(runNo);
|
||||
rows.push({
|
||||
kind: 'run',
|
||||
object_key: `run:${runNo}`,
|
||||
label: runNo,
|
||||
status_label: displayStatus,
|
||||
node_status: mapLifecycleToNodeStatus(displayStatus),
|
||||
run_no: runNo,
|
||||
case_no: caseNo || null,
|
||||
document_id: documentId,
|
||||
workflow_item_no: itemNo || null,
|
||||
primary_action: caseNo || item.lifecycle_status === 'pending_review'
|
||||
? 'open_review'
|
||||
: 'expand',
|
||||
focused: Boolean(focusRun && focusRun === runNo),
|
||||
});
|
||||
}
|
||||
|
||||
// Candidate:尚无独立列表时,以待复核 Case 作为候选处理对象入口。
|
||||
if (caseNo && (item.lifecycle_status === 'pending_review' || focusCandidate)) {
|
||||
const candidateKey = `candidate:${caseNo}`;
|
||||
if (!rows.some((row) => row.object_key === candidateKey)) {
|
||||
rows.push({
|
||||
kind: 'candidate',
|
||||
object_key: candidateKey,
|
||||
label: caseNo,
|
||||
status_label: 'pending_review',
|
||||
qualification_status: 'review_required',
|
||||
run_no: runNo || null,
|
||||
candidate_no: focusCandidate || null,
|
||||
case_no: caseNo,
|
||||
document_id: documentId,
|
||||
workflow_item_no: itemNo || null,
|
||||
primary_action: 'open_review',
|
||||
focused: Boolean(
|
||||
(focusCandidate && focusCandidate === caseNo)
|
||||
|| (focusCandidate && focusCandidate === String(focusCandidate)),
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (taskNo && !seenTasks.has(taskNo)) {
|
||||
seenTasks.add(taskNo);
|
||||
rows.push({
|
||||
kind: 'task',
|
||||
object_key: `task:${taskNo}`,
|
||||
label: taskNo,
|
||||
status_label: displayStatus,
|
||||
node_status: nodeStatus,
|
||||
run_no: runNo || null,
|
||||
task_no: taskNo,
|
||||
case_no: caseNo || null,
|
||||
document_id: documentId,
|
||||
workflow_item_no: itemNo || null,
|
||||
primary_action: 'focus_task',
|
||||
focused: Boolean(focusTask && focusTask === taskNo),
|
||||
});
|
||||
}
|
||||
|
||||
const gateSummary = item.process_gate;
|
||||
const blockingGate = gateSummary?.current_blocking_gate;
|
||||
const gateCode = String(
|
||||
blockingGate?.gate_code
|
||||
|| gateSummary?.blocking_reason_code
|
||||
|| '',
|
||||
).trim();
|
||||
const gateStatus = String(blockingGate?.status || gateSummary?.status || '').trim();
|
||||
if (gateCode && blockingGate) {
|
||||
const gateKey = `gate:${taskNo || runNo || itemNo}:${gateCode}`;
|
||||
if (!seenGates.has(gateKey)) {
|
||||
seenGates.add(gateKey);
|
||||
rows.push({
|
||||
kind: 'process_gate',
|
||||
object_key: gateKey,
|
||||
label: gateCode,
|
||||
status_label: gateStatus || 'blocked',
|
||||
node_status: 'failed',
|
||||
run_no: runNo || null,
|
||||
task_no: taskNo || gateSummary?.task_no || null,
|
||||
case_no: caseNo || gateSummary?.case_no || null,
|
||||
document_id: documentId,
|
||||
workflow_item_no: itemNo || null,
|
||||
primary_action: 'open_gate',
|
||||
focused: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ describe('orderExtractionHandlingRefs', () => {
|
||||
})).toBe('skip.pdf');
|
||||
|
||||
expect(resolveHandlingAffectedRefTarget({ type: 'task', task_no: 'ST-9' })).toEqual({
|
||||
kind: 'task',
|
||||
kind: 'chat_focus_task',
|
||||
taskNo: 'ST-9',
|
||||
});
|
||||
expect(resolveHandlingAffectedRefTarget({
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
export type ShippingHandlingAffectedRef = Record<string, unknown>;
|
||||
|
||||
export type ShippingHandlingRefTarget =
|
||||
| { kind: 'task'; taskNo: string }
|
||||
/** 对话侧聚焦 Task(主路径);不再默认跳转 Task 工作台。 */
|
||||
| { kind: 'chat_focus_task'; taskNo: string }
|
||||
| { kind: 'review'; documentId?: number; candidateNo?: string }
|
||||
| { kind: 'none' };
|
||||
|
||||
@@ -51,7 +52,7 @@ export function resolveHandlingAffectedRefTarget(ref: ShippingHandlingAffectedRe
|
||||
const candidateNo = String(ref.candidate_no || '').trim();
|
||||
const documentId = Number(ref.document_id || 0);
|
||||
if ((type === 'task' || !type) && taskNo) {
|
||||
return { kind: 'task', taskNo };
|
||||
return { kind: 'chat_focus_task', taskNo };
|
||||
}
|
||||
if (type === 'candidate' || type === 'document' || type === 'attachment' || candidateNo || documentId > 0) {
|
||||
return {
|
||||
|
||||
@@ -172,6 +172,7 @@ export function mapOrderExtractionRunToMessageState(run: ShippingOrderExtraction
|
||||
terminal: !ACTIVE_RUN_STATUSES.has(run.status),
|
||||
refreshFailed: false,
|
||||
errorCode: run.error?.code || null,
|
||||
errorExplainability: run.error?.explainability || null,
|
||||
startedAt: run.started_at || null,
|
||||
finishedAt: run.finished_at || null,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user