feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* features/shipping-notice/api/customer-master.api.ts
|
||||
* 用途:货代客户主数据的管理 API,归属货代发货业务域。
|
||||
* 依赖:requestJson、认证请求头、客户主数据类型。
|
||||
* 逻辑:页面位于货代发货工作台,但所有写操作仍调用管理员受保护的后端契约。
|
||||
*/
|
||||
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { BusinessError, requestJson, resolveLocalizedErrorMessage } from '@/shared/api/client';
|
||||
import type {
|
||||
ShippingCustomerIdentifier,
|
||||
ShippingCustomerImportBatch,
|
||||
ShippingCustomerLifecycleImpact,
|
||||
ShippingCustomerLifecycleTimeline,
|
||||
DeleteShippingCustomerRequest,
|
||||
DeleteShippingCustomerResult,
|
||||
MergeShippingCustomerRequest,
|
||||
MergeShippingCustomerResult,
|
||||
ShippingCustomerMergeImpact,
|
||||
ShippingCustomerPage,
|
||||
ShippingCustomerRow,
|
||||
ShippingCustomerShadowItem,
|
||||
ShippingCustomerShadowReport,
|
||||
ShippingIdentifierFormState,
|
||||
} from '../types/customer-master.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
|
||||
export interface ListShippingCustomersParams {
|
||||
q?: string;
|
||||
status?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
/** 分页查询货代标准客户。 */
|
||||
export const listShippingCustomers = (params: ListShippingCustomersParams = {}) => {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.q?.trim()) qs.set('q', params.q.trim());
|
||||
if (params.status) qs.set('status', params.status);
|
||||
qs.set('page', String(params.page || 1));
|
||||
qs.set('page_size', String(params.pageSize || 20));
|
||||
return requestJson<ShippingCustomerPage>(`/api/admin/shipping-customers?${qs.toString()}`, auth());
|
||||
};
|
||||
|
||||
export const getShippingCustomer = (id: number) =>
|
||||
requestJson<ShippingCustomerRow>(`/api/admin/shipping-customers/${id}`, auth());
|
||||
|
||||
/** 查询客户永久删除前的完整引用影响;前端不得以业务单数自行推断。 */
|
||||
export const getShippingCustomerLifecycleImpact = (id: number) =>
|
||||
requestJson<ShippingCustomerLifecycleImpact>(`/api/admin/shipping-customers/${id}/lifecycle-impact`, auth());
|
||||
|
||||
/** 查询客户创建、变更、证据及归并的不可变治理时间线。 */
|
||||
export const getShippingCustomerLifecycleTimeline = (id: number) =>
|
||||
requestJson<ShippingCustomerLifecycleTimeline>(`/api/admin/shipping-customers/${id}/lifecycle-timeline`, auth());
|
||||
|
||||
/** 受控删除误建客户;服务端在提交时重新检查全部生命周期阻断引用。 */
|
||||
export const deleteShippingCustomer = (id: number, payload: DeleteShippingCustomerRequest) =>
|
||||
requestJson<DeleteShippingCustomerResult>(`/api/admin/shipping-customers/${id}`, {
|
||||
method: 'DELETE', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
/** 预览客户归并时保留的历史引用和可迁移的未来识别配置。 */
|
||||
export const getShippingCustomerMergeImpact = (sourceId: number, targetId: number) =>
|
||||
requestJson<ShippingCustomerMergeImpact>(
|
||||
`/api/admin/shipping-customers/${sourceId}/merge-impact?target_customer_id=${targetId}`,
|
||||
auth(),
|
||||
);
|
||||
|
||||
/** 归并重复客户;后端锁定双方并保留历史业务与业务号快照。 */
|
||||
export const mergeShippingCustomer = (sourceId: number, payload: MergeShippingCustomerRequest) =>
|
||||
requestJson<MergeShippingCustomerResult>(`/api/admin/shipping-customers/${sourceId}/merge`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const createShippingCustomer = (payload: Record<string, unknown>) =>
|
||||
requestJson<ShippingCustomerRow>('/api/admin/shipping-customers', {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateShippingCustomer = (id: number, payload: Record<string, unknown>) =>
|
||||
requestJson<ShippingCustomerRow>(`/api/admin/shipping-customers/${id}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const deactivateShippingCustomer = (id: number, reason: string) =>
|
||||
requestJson<ShippingCustomerRow>(`/api/admin/shipping-customers/${id}/deactivate`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify({ reason }),
|
||||
});
|
||||
|
||||
export const createShippingCustomerIdentifier = (customerId: number, payload: ShippingIdentifierFormState) =>
|
||||
requestJson<ShippingCustomerIdentifier>(`/api/admin/shipping-customers/${customerId}/identifiers`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateShippingCustomerIdentifier = (identifierId: number, payload: Record<string, unknown>) =>
|
||||
requestJson<ShippingCustomerIdentifier>(`/api/admin/shipping-customer-identifiers/${identifierId}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const createShippingCustomerExternalRef = (
|
||||
customerId: number,
|
||||
payload: { source_system: string; customer_code: string },
|
||||
) => requestJson(`/api/admin/shipping-customers/${customerId}/external-refs`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const createShippingCustomerSite = (
|
||||
customerId: number,
|
||||
payload: { site_name: string; site_code: string; address?: string; city?: string; country?: string; remark?: string },
|
||||
) => requestJson(`/api/admin/shipping-customers/${customerId}/sites`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const uploadShippingCustomerImport = (file: File, sourceSystem: string) => {
|
||||
const body = new FormData();
|
||||
body.append('file', file);
|
||||
body.append('source_system', sourceSystem);
|
||||
return requestJson<ShippingCustomerImportBatch>('/api/admin/shipping-customer-imports', {
|
||||
method: 'POST', headers: getAuthHeaders(), body,
|
||||
});
|
||||
};
|
||||
|
||||
export const decideShippingCustomerImportRow = (
|
||||
rowId: number,
|
||||
payload: { action: string; target_customer_id?: number; note?: string },
|
||||
) => requestJson(`/api/admin/shipping-customer-import-rows/${rowId}/decision`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const publishShippingCustomerImport = (batchId: number) =>
|
||||
requestJson<ShippingCustomerImportBatch>(`/api/admin/shipping-customer-imports/${batchId}/publish`, {
|
||||
method: 'POST', ...auth(),
|
||||
});
|
||||
|
||||
/** 下载需要管理员权限的二进制文件,并保持统一 BusinessError 契约。 */
|
||||
const downloadCustomerMasterFile = async (url: string, fallbackName: string): Promise<void> => {
|
||||
const response = await fetch(url, { headers: getAuthHeaders() });
|
||||
if (!response.ok) {
|
||||
const payload = await response.json().catch(() => null);
|
||||
const code = payload?.error?.code || 'SYSTEM.HTTP_ERROR';
|
||||
throw new BusinessError({
|
||||
message: resolveLocalizedErrorMessage(code, payload?.error?.message || `HTTP ${response.status}`),
|
||||
code,
|
||||
details: payload?.error?.details || {},
|
||||
requestId: payload?.request_id,
|
||||
status: response.status,
|
||||
});
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const disposition = response.headers.get('Content-Disposition') || '';
|
||||
const encodedName = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
|
||||
const plainName = disposition.match(/filename="?([^";]+)"?/i)?.[1];
|
||||
const filename = encodedName ? decodeURIComponent(encodedName) : plainName || fallbackName;
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = objectUrl;
|
||||
anchor.download = filename;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
};
|
||||
|
||||
export const downloadShippingCustomerImportTemplate = () =>
|
||||
downloadCustomerMasterFile('/api/admin/shipping-customers/import-template', 'shipping_customer_import_template.xlsx');
|
||||
|
||||
export const downloadShippingCustomerReconciliation = (batchId: number, batchNo: string) =>
|
||||
downloadCustomerMasterFile(
|
||||
`/api/admin/shipping-customer-imports/${batchId}/reconciliation`,
|
||||
`${batchNo}_reconciliation.csv`,
|
||||
);
|
||||
|
||||
export const getShippingCustomerShadowReport = (limit = 100) =>
|
||||
requestJson<ShippingCustomerShadowReport>(`/api/admin/shipping-customer-shadow-report?limit=${limit}`, auth());
|
||||
|
||||
export const labelShippingCustomerShadowResolution = (resolutionId: number, customerId: number) =>
|
||||
requestJson<ShippingCustomerShadowItem>(
|
||||
`/api/admin/shipping-customer-shadow-resolutions/${resolutionId}/label`,
|
||||
{ method: 'PUT', ...jsonAuth(), body: JSON.stringify({ customer_id: customerId }) },
|
||||
);
|
||||
Reference in new issue
Block a user