feat(shipping-notice): 完成货代发货通知全流程开发与代码重构
- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑 - 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示 - 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败 - 新增路径工具类统一管理相对路径,优化配置文件处理逻辑 - 归档旧文档,将部署、Dify配置合并到`shipping_notice.md` - 新增完整单元测试与集成测试覆盖核心流程 - 更新前端国际化与会话管理逻辑,优化界面交互
This commit is contained in:
1 parent
b62082758b
commit
8deae3146b
65 files changed
+6477
-1937
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
|
||||
export interface ShippingCaseSummary {
|
||||
export interface ShippingTaskSummary {
|
||||
id: number;
|
||||
case_no: string;
|
||||
task_no: string;
|
||||
source_type: string;
|
||||
customer_name?: string | null;
|
||||
process_status: string;
|
||||
@@ -16,22 +16,23 @@ export interface ShippingCaseSummary {
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingCaseEvent {
|
||||
export interface ShippingTaskEvent {
|
||||
event_type: string;
|
||||
detail_json?: Record<string, unknown> | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingCaseDetail extends ShippingCaseSummary {
|
||||
export interface ShippingTaskDetail extends ShippingTaskSummary {
|
||||
customer_code?: string | null;
|
||||
ship_to?: string | null;
|
||||
po_number?: string | null;
|
||||
required_date?: string | null;
|
||||
lines: Array<Record<string, unknown>>;
|
||||
shortage?: Record<string, unknown> | null;
|
||||
line_results?: Array<Record<string, unknown>>;
|
||||
parse_confidence?: number | null;
|
||||
error_message?: string | null;
|
||||
events: ShippingCaseEvent[];
|
||||
events: ShippingTaskEvent[];
|
||||
}
|
||||
|
||||
async function getJson<T>(url: string): Promise<T> {
|
||||
@@ -43,19 +44,19 @@ async function getJson<T>(url: string): Promise<T> {
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export const listWorkspaceShippingCases = (params?: { process_status?: string; limit?: number }) => {
|
||||
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));
|
||||
const qs = sp.toString();
|
||||
return getJson<ShippingCaseSummary[]>(`/api/workspace/shipping-cases${qs ? '?' + qs : ''}`);
|
||||
return getJson<ShippingTaskSummary[]>(`/api/workspace/shipping-tasks${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
|
||||
export const getWorkspaceShippingCase = (caseNo: string) =>
|
||||
getJson<ShippingCaseDetail>(`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}`);
|
||||
export const getWorkspaceShippingTask = (taskNo: string) =>
|
||||
getJson<ShippingTaskDetail>(`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}`);
|
||||
|
||||
export const workspaceShippingExportUrl = (caseNo: string) =>
|
||||
`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}/export`;
|
||||
export const workspaceShippingExportUrl = (taskNo: string) =>
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/export`;
|
||||
|
||||
export interface ShippingChatAction {
|
||||
id: string;
|
||||
@@ -65,7 +66,7 @@ export interface ShippingChatAction {
|
||||
}
|
||||
|
||||
export interface ShippingChatActionsResponse {
|
||||
case_no: string;
|
||||
task_no: string;
|
||||
checkpoint?: string | null;
|
||||
process_status: string;
|
||||
review_status?: string | null;
|
||||
@@ -73,18 +74,18 @@ export interface ShippingChatActionsResponse {
|
||||
action_buttons: ShippingChatAction[];
|
||||
}
|
||||
|
||||
export const getShippingChatActions = (caseNo: string) =>
|
||||
export const getShippingChatActions = (taskNo: string) =>
|
||||
getJson<ShippingChatActionsResponse>(
|
||||
`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}/chat-actions`,
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/chat-actions`,
|
||||
);
|
||||
|
||||
export async function uploadWorkspaceShippingInventory(caseNo: string, file: File) {
|
||||
export async function uploadWorkspaceShippingInventory(taskNo: string, file: File) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const headers = getAuthHeaders();
|
||||
delete (headers as Record<string, string>)['Content-Type'];
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}/upload-inventory`,
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/upload-inventory`,
|
||||
{ method: 'POST', headers, body: form },
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingInventoryUploadResponse & { error?: string };
|
||||
@@ -94,25 +95,92 @@ export async function uploadWorkspaceShippingInventory(caseNo: string, file: Fil
|
||||
return body;
|
||||
}
|
||||
|
||||
export async function applyWorkspaceShippingInventoryMapping(taskNo: string, columnMappingJson: Record<string, unknown>) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/apply-inventory-mapping`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ column_mapping_json: columnMappingJson }),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingInventoryUploadResponse & { error?: string };
|
||||
if (!res.ok) {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export interface ShippingInventoryUploadResponse {
|
||||
status: string;
|
||||
message?: string;
|
||||
case_id?: string;
|
||||
task_id?: string;
|
||||
checkpoint?: string;
|
||||
data?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ShippingTaskCreateResponse {
|
||||
status: string;
|
||||
message?: string;
|
||||
task_id?: string;
|
||||
checkpoint?: string;
|
||||
data?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export async function createWorkspaceShippingTask(params?: {
|
||||
source_type?: string;
|
||||
conversation_id?: string;
|
||||
raw_content?: string;
|
||||
}) {
|
||||
const res = await fetch('/api/workspace/shipping-tasks', {
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(params || {}),
|
||||
});
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingTaskCreateResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export interface ShippingNoticeUploadResponse {
|
||||
status: string;
|
||||
message?: string;
|
||||
task_id?: string;
|
||||
checkpoint?: string;
|
||||
data?: Record<string, unknown>;
|
||||
human_options?: string[];
|
||||
}
|
||||
|
||||
export async function createWorkspaceShippingTaskFromNotice(file: File) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const headers = getAuthHeaders();
|
||||
delete (headers as Record<string, string>)['Content-Type'];
|
||||
const res = await fetch('/api/workspace/shipping-tasks/create-from-notice', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: form,
|
||||
});
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingNoticeUploadResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export interface ShippingDecisionResponse {
|
||||
status: string;
|
||||
message?: string;
|
||||
case_id?: string;
|
||||
task_id?: string;
|
||||
checkpoint?: string;
|
||||
data?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export async function submitWorkspaceShippingDecision(caseNo: string, decision: string, comment?: string) {
|
||||
export async function submitWorkspaceShippingDecision(taskNo: string, decision: string, comment?: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}/submit-decision`,
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/submit-decision`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
@@ -126,4 +194,36 @@ export async function submitWorkspaceShippingDecision(caseNo: string, decision:
|
||||
return body;
|
||||
}
|
||||
|
||||
export async function matchWorkspaceShippingInventory(taskNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/match-inventory`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
},
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
export async function generateWorkspaceShippingExcel(taskNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/generate-excel`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
},
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
export const SHIPPING_NOTICE_AGENT_NAME = '货代发货通知 Agent';
|
||||
Reference in new issue
Block a user