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,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;
|
||||
}
|
||||
Reference in new issue
Block a user