feat(shipping-notice): 新增发货批次和任务管理功能,支持批次创建与任务处理
This commit is contained in:
1 parent
457f0f4e5e
commit
634dee4b81
81 files changed
+9088
-3625
No files matched your search
@@ -1,13 +1,17 @@
|
||||
/**
|
||||
/**
|
||||
* features/chat/api/shipping.api.ts
|
||||
* 货代发货 HTTP API:任务列表、上传库存、映射、决策、Excel 生成等。
|
||||
* 后端路由前缀为 /api/workspace/shipping-tasks,由 chat 域 Agent 流程与工作台页面共用。
|
||||
* 用途:封装发货通知相关 HTTP API,包括任务/批次查询、库存上传、映射确认、人工决策与 Excel 导出。
|
||||
* 依赖:浏览器 fetch、getAuthHeaders、shipping.api.types 类型定义。
|
||||
* 逻辑:上游由 useChatShipping 与 shipping/* handler 调用本文件;本文件统一请求工作台后端 `/api/workspace/*` 路由并抛出标准错误。
|
||||
*/
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
ShippingBatchSummary,
|
||||
ShippingChatActionsResponse,
|
||||
ShippingDecisionResponse,
|
||||
ShippingInventoryUploadResponse,
|
||||
ShippingNoticeHeader,
|
||||
ShippingNoticeLine,
|
||||
ShippingNoticeUploadResponse,
|
||||
ShippingTaskCreateResponse,
|
||||
ShippingTaskDetail,
|
||||
@@ -24,6 +28,7 @@ async function getJson<T>(url: string): Promise<T> {
|
||||
}
|
||||
|
||||
export const listWorkspaceShippingTasks = (params?: { process_status?: string; limit?: number }) => {
|
||||
/** 拉取当前用户可见的发货任务列表。 */
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.process_status) sp.set('process_status', params.process_status);
|
||||
if (params?.limit) sp.set('limit', String(params.limit));
|
||||
@@ -31,17 +36,46 @@ export const listWorkspaceShippingTasks = (params?: { process_status?: string; l
|
||||
return getJson<ShippingTaskSummary[]>(`/api/workspace/shipping-tasks${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
|
||||
export const listWorkspaceShippingBatches = (params?: { limit?: number }) => {
|
||||
/** 拉取当前用户的发货批次摘要列表。 */
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.limit) sp.set('limit', String(params.limit));
|
||||
const qs = sp.toString();
|
||||
return getJson<ShippingBatchSummary[]>(`/api/workspace/shipping-batches${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
|
||||
/** 获取批次详情、批次任务列表与当前焦点任务。 */
|
||||
export const getWorkspaceShippingBatch = (batchNo: string) =>
|
||||
getJson<ShippingBatchSummary & { tasks?: ShippingTaskSummary[]; focus_task?: ShippingTaskSummary | null }>(
|
||||
`/api/workspace/shipping-batches/${encodeURIComponent(batchNo)}`,
|
||||
);
|
||||
|
||||
/** 获取指定批次当前焦点任务。 */
|
||||
export const getWorkspaceShippingBatchFocusTask = (batchNo: string) =>
|
||||
getJson<ShippingTaskSummary>(
|
||||
`/api/workspace/shipping-batches/${encodeURIComponent(batchNo)}/focus-task`,
|
||||
);
|
||||
|
||||
/** 获取单个发货任务详情。 */
|
||||
export const getWorkspaceShippingTask = (taskNo: string) =>
|
||||
getJson<ShippingTaskDetail>(`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}`);
|
||||
|
||||
/** 生成任务导出文件的前端下载 URL。 */
|
||||
export const workspaceShippingExportUrl = (taskNo: string) =>
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/export`;
|
||||
|
||||
/** 获取聊天气泡动作按钮、检查点和 human options。 */
|
||||
export const getShippingChatActions = (taskNo: string) =>
|
||||
getJson<ShippingChatActionsResponse>(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/chat-actions`,
|
||||
);
|
||||
|
||||
/**
|
||||
* 上传库存 Excel,并由后端完成解析与 schema preview 生成。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param file - 用户选择的库存文件
|
||||
* @returns 库存上传与解析结果
|
||||
*/
|
||||
export async function uploadWorkspaceShippingInventory(taskNo: string, file: File) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
@@ -58,6 +92,12 @@ export async function uploadWorkspaceShippingInventory(taskNo: string, file: Fil
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交库存字段映射。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param columnMappingJson - 前端表单确认后的 map_json
|
||||
* @returns 映射应用与库存解析结果
|
||||
*/
|
||||
export async function applyWorkspaceShippingInventoryMapping(taskNo: string, columnMappingJson: Record<string, unknown>) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/apply-inventory-mapping`,
|
||||
@@ -74,6 +114,11 @@ export async function applyWorkspaceShippingInventoryMapping(taskNo: string, col
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单个发货任务。
|
||||
* @param params - 建单参数,可包含 source_type、conversation_id、raw_content
|
||||
* @returns 建单结果
|
||||
*/
|
||||
export async function createWorkspaceShippingTask(params?: {
|
||||
source_type?: string;
|
||||
conversation_id?: string;
|
||||
@@ -91,6 +136,12 @@ export async function createWorkspaceShippingTask(params?: {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传单个发货通知附件并立即建单解析。
|
||||
* @param file - 发货通知文件
|
||||
* @param conversationId - 可选会话 ID,用于把任务绑定到聊天会话
|
||||
* @returns 建单与解析结果
|
||||
*/
|
||||
export async function createWorkspaceShippingTaskFromNotice(file: File, conversationId?: string) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
@@ -109,6 +160,67 @@ export async function createWorkspaceShippingTaskFromNotice(file: File, conversa
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传多份发货通知并创建批次。
|
||||
* @param files - 发货通知附件列表
|
||||
* @param conversationId - 可选会话 ID
|
||||
* @returns 批次与任务创建结果
|
||||
*/
|
||||
export async function createWorkspaceShippingBatchFromNotices(files: File[], conversationId?: string) {
|
||||
const form = new FormData();
|
||||
files.forEach((file) => form.append('files', file));
|
||||
if (conversationId) form.append('conversation_id', conversationId);
|
||||
const headers = getAuthHeaders();
|
||||
delete (headers as Record<string, string>)['Content-Type'];
|
||||
const res = await fetch('/api/workspace/shipping-batches/create-from-notices', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: form,
|
||||
});
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingNoticeUploadResponse & {
|
||||
error?: string;
|
||||
batch_no?: string;
|
||||
data?: unknown;
|
||||
};
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换批次当前焦点任务。
|
||||
* @param batchNo - 批次编号
|
||||
* @param taskNo - 目标任务编号
|
||||
* @returns 更新后的批次摘要与焦点任务
|
||||
*/
|
||||
export async function switchWorkspaceShippingBatchFocusTask(batchNo: string, taskNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-batches/${encodeURIComponent(batchNo)}/focus-task`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ task_no: taskNo }),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as {
|
||||
error?: string;
|
||||
batch?: ShippingBatchSummary;
|
||||
focus_task?: ShippingTaskSummary;
|
||||
};
|
||||
if (!res.ok) {
|
||||
throw new Error(body.error || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交人工决策。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param decision - 决策 ID,如 confirm、reject、reparse
|
||||
* @param comment - 可选备注
|
||||
* @returns 决策执行结果
|
||||
*/
|
||||
export async function submitWorkspaceShippingDecision(taskNo: string, decision: string, comment?: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/submit-decision`,
|
||||
@@ -125,6 +237,121 @@ export async function submitWorkspaceShippingDecision(taskNo: string, decision:
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新发货通知单头字段。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param fields - 需要更新的单头字段
|
||||
* @param comment - 可选操作备注
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function updateWorkspaceShippingNoticeFields(
|
||||
taskNo: string,
|
||||
fields: Partial<ShippingNoticeHeader>,
|
||||
comment?: string,
|
||||
) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/update-notice-fields`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ fields, ...(comment ? { comment } : {}) }),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定订单行。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param lineIndex - 订单行下标
|
||||
* @param patch - 行字段补丁
|
||||
* @param comment - 可选操作备注
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function updateWorkspaceShippingNoticeLine(
|
||||
taskNo: string,
|
||||
lineIndex: number,
|
||||
patch: Partial<ShippingNoticeLine> & { quantity?: number },
|
||||
comment?: string,
|
||||
) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/update-notice-line`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ line_index: lineIndex, patch, ...(comment ? { comment } : {}) }),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为发货通知新增订单行。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param line - 新增的订单行内容
|
||||
* @param comment - 可选操作备注
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function addWorkspaceShippingNoticeLine(
|
||||
taskNo: string,
|
||||
line: Partial<ShippingNoticeLine> & { quantity?: number },
|
||||
comment?: string,
|
||||
) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/add-notice-line`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ line, ...(comment ? { comment } : {}) }),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定订单行。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param lineIndex - 待删除的订单行下标
|
||||
* @param comment - 可选操作备注
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function removeWorkspaceShippingNoticeLine(
|
||||
taskNo: string,
|
||||
lineIndex: number,
|
||||
comment?: string,
|
||||
) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/remove-notice-line`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ line_index: lineIndex, ...(comment ? { comment } : {}) }),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行库存匹配。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @returns 匹配结果与后续动作提示
|
||||
*/
|
||||
export async function matchWorkspaceShippingInventory(taskNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/match-inventory`,
|
||||
@@ -141,7 +368,12 @@ export async function matchWorkspaceShippingInventory(taskNo: string) {
|
||||
return body;
|
||||
}
|
||||
|
||||
/** Hxops 聊天兜底:等同 Dify auto_progress Tool */
|
||||
/**
|
||||
* 以用户态触发自动推进,作为聊天前端兜底入口。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param lang - 可选语言代码
|
||||
* @returns 自动推进结果
|
||||
*/
|
||||
export async function autoProgressWorkspaceShippingTask(taskNo: string, lang?: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/auto-progress`,
|
||||
@@ -158,6 +390,11 @@ export async function autoProgressWorkspaceShippingTask(taskNo: string, lang?: s
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记货代系统已人工上传完成。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @returns 上传确认结果
|
||||
*/
|
||||
export async function markWorkspaceShippingManualUploaded(taskNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/mark-manual-uploaded`,
|
||||
@@ -174,6 +411,11 @@ export async function markWorkspaceShippingManualUploaded(taskNo: string) {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成发货 Excel。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @returns 生成结果,成功时通常会包含下载链接
|
||||
*/
|
||||
export async function generateWorkspaceShippingExcel(taskNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/generate-excel`,
|
||||
@@ -190,13 +432,18 @@ export async function generateWorkspaceShippingExcel(taskNo: string) {
|
||||
return body;
|
||||
}
|
||||
|
||||
/** 货代发货 Agent 显示名称,用于路由与 Agent 匹配 */
|
||||
/** 货代发货 Agent 显示名称,用于聊天路由与 Agent 匹配。 */
|
||||
export const SHIPPING_NOTICE_AGENT_NAME = '货代发货通知 Agent';
|
||||
|
||||
export type {
|
||||
ShippingBatchSummary,
|
||||
ShippingChatAction,
|
||||
ShippingChatActionsResponse,
|
||||
ShippingDecisionResponse,
|
||||
ShippingInventoryUploadResponse,
|
||||
ShippingMatchLineResult,
|
||||
ShippingNoticeHeader,
|
||||
ShippingNoticeLine,
|
||||
ShippingNoticeUploadResponse,
|
||||
ShippingTaskCreateResponse,
|
||||
ShippingTaskDetail,
|
||||
|
||||
Reference in new issue
Block a user