feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议

This commit is contained in:
hugo committed 2026-07-18 11:41:02 +08:00
1 parent 46eb63f5bb
commit e9bdd81f1a
320 files changed
+28361 -10487

No files matched your search

+12 -31
View File
@@ -1,17 +1,17 @@
/**
* features/chat/api/shipping.api.ts
* 用途:封装发货通知相关 HTTP API,包括任务/批次查询、库存上传、映射确认、人工决策与 Excel 导出。
* 用途:封装发货通知相关 HTTP API,包括任务/批次查询、人工决策与 Excel 导出。
* 依赖:统一 requestJson / BusinessError、shipping.api.types 类型定义。
* 逻辑:上游由 useChatShipping 与 shipping/* handler 调用本文件;本文件统一请求工作台后端 `/api/workspace/*` 路由并抛出标准错误。
*/
import { BusinessError, requestJson } from '@/shared/api/client';
import { getAuthHeaders } from '@/shared/utils/auth';
import { reportShippingDebugEvent } from '../shipping/shippingDebugReporter';
import type {
ShippingBatchSummary,
ShippingBatchUiState,
ShippingConversationWorkspace,
ShippingDecisionResponse,
ShippingInventoryUploadResponse,
ShippingNoticeHeader,
ShippingNoticeLine,
ShippingNoticeUploadResponse,
@@ -125,20 +125,16 @@ export const getWorkspaceShippingTaskUiState = (taskNo: string) =>
export const workspaceShippingExportUrl = (taskNo: string) =>
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/export`;
/**
* 上传库存 Excel,并由后端完成解析与 schema preview 生成。
* @param taskNo - 发货任务编号
* @param file - 用户选择的库存文件
* @returns 库存上传与解析结果
*/
export async function uploadWorkspaceShippingInventory(taskNo: string, file: File) {
const form = new FormData();
form.append('file', file);
const body = await requestJson<ShippingInventoryUploadResponse & ShippingApiStatusPayload>(
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/upload-inventory`,
{ method: 'POST', body: form },
);
return assertShippingOk(body);
/** 下载一个批次或显式任务集合的当前 ready 发货 Excel ZIP。 */
export async function downloadWorkspaceShippingExportArchive(payload: { batch_no?: string; task_nos?: string[] }) {
const response = await fetch('/api/workspace/shipping-exports/archive', {
method: 'POST', headers: { 'Content-Type': 'application/json', ...getAuthHeaders() }, body: JSON.stringify(payload),
});
if (!response.ok) throw new Error('Shipping export archive download failed');
const disposition = response.headers.get('Content-Disposition') || '';
const encoded = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
const plain = disposition.match(/filename="?([^";]+)"?/i)?.[1];
return { blob: await response.blob(), filename: encoded ? decodeURIComponent(encoded) : (plain || 'shipping_exports.zip') };
}
/**
@@ -169,20 +165,6 @@ export const confirmWorkspaceShippingCustomer = (taskNo: string, customerId: num
jsonPost({ customer_id: customerId }),
);
/**
* 提交库存字段映射。
* @param taskNo - 发货任务编号
* @param columnMappingJson - 前端表单确认后的 map_json
* @returns 映射应用与库存解析结果
*/
export async function applyWorkspaceShippingInventoryMapping(taskNo: string, columnMappingJson: Record<string, unknown>) {
const body = await requestJson<ShippingInventoryUploadResponse & ShippingApiStatusPayload>(
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/apply-inventory-mapping`,
jsonPost({ map_json: columnMappingJson }),
);
return assertShippingOk(body);
}
/**
* 创建单个发货任务。
* @param params - 建单参数,可包含 source_type、conversation_id、raw_content
@@ -681,7 +663,6 @@ export type {
ShippingConversationWorkspaceSummary,
ShippingCurrentStepProgress,
ShippingDecisionResponse,
ShippingInventoryUploadResponse,
ShippingMatchLineResult,
ShippingNoticeHeader,
ShippingNoticeLine,