- 异动解析跳过无异动日期的在途/执行中行,兼容 datetime 日期单元格 - ERP 网关故障降级为逐票阻断并带原因,不再炸整来源 - 预检明细唯一约束升粒度:(预检,来源,单号,料号,收料日期) - Invoice 恢复单号锚定并移至料号前;批号 lot_no 全链贯通, 拨出/拨入批号按 WTP→HOW 转换展示;新增收料日期列 - 预检表格筛选/全选;单行与批量重查 ERP 库存 - 收料日期范围作为预检查询范围,截止卡控不超出 D+1 规则 - 来源多选打包下载收料文件;调拨消息与子流程容器放宽宽度 - 预检恢复明细补齐收料日期与批号字段(修复卡片三列空值)
130 lines
5.2 KiB
TypeScript
130 lines
5.2 KiB
TypeScript
/**
|
||
* features/chat/api/transfer.api.ts
|
||
* 用途:在途仓自动调拨 API 客户端(统一 requestJson / requestBlob,不重复造客户端)。
|
||
* 依赖:@/shared/api/client(requestJson / requestBlob / BusinessError)、getAuthHeaders。
|
||
* 逻辑:薄封装后端 /api/in-transit-transfer 全部端点;二进制下载走 requestBlob。
|
||
*/
|
||
import { requestBlob, requestJson } from '@/shared/api/client';
|
||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||
import type {
|
||
TransferActionResult,
|
||
TransferBacklogItem,
|
||
TransferBacklogSummary,
|
||
TransferExecuteResponse,
|
||
TransferPrecheckDetail,
|
||
TransferPrecheckSummary,
|
||
TransferRunResult,
|
||
TransferSourceFileStatus,
|
||
TransferSourceOption,
|
||
} from '../types/transfer.types';
|
||
|
||
const BASE = '/api/in-transit-transfer';
|
||
|
||
/** JSON 请求头:除鉴权外必须带 Content-Type: application/json,否则 Flask request.get_json 解析不到 body。 */
|
||
const jsonHeaders = () => ({ 'Content-Type': 'application/json', ...getAuthHeaders() });
|
||
|
||
export interface CreatePrecheckPayload {
|
||
source_codes: string[];
|
||
business_date?: string;
|
||
receipt_date_from?: string;
|
||
receipt_date_to?: string;
|
||
}
|
||
|
||
/** 创建预检(只读) */
|
||
export const createTransferPrecheck = (payload: CreatePrecheckPayload) =>
|
||
requestJson<TransferPrecheckSummary>(BASE + '/prechecks', {
|
||
method: 'POST',
|
||
headers: jsonHeaders(),
|
||
body: JSON.stringify(payload),
|
||
});
|
||
|
||
/** 恢复预检进度与明细 */
|
||
export const getTransferPrecheck = (precheckId: string) =>
|
||
requestJson<TransferPrecheckDetail>(`${BASE}/prechecks/${precheckId}`, {
|
||
headers: getAuthHeaders(),
|
||
});
|
||
|
||
/** 确认选择范围并直接生成执行 Run */
|
||
export const executeTransferPrecheck = (precheckId: string, invoiceNos: string[]) =>
|
||
requestJson<TransferExecuteResponse>(`${BASE}/prechecks/${precheckId}/execute`, {
|
||
method: 'POST',
|
||
headers: jsonHeaders(),
|
||
body: JSON.stringify({ invoice_nos: invoiceNos }),
|
||
});
|
||
|
||
/** 恢复 Run 最终结果 */
|
||
export const getTransferRun = (runNo: string) =>
|
||
requestJson<TransferRunResult>(`${BASE}/runs/${runNo}`, {
|
||
headers: getAuthHeaders(),
|
||
});
|
||
|
||
/** 请求停止剩余任务 */
|
||
export const cancelTransferRun = (runNo: string, reason: string) =>
|
||
requestJson<TransferActionResult>(`${BASE}/runs/${runNo}/cancel`, {
|
||
method: 'POST',
|
||
headers: jsonHeaders(),
|
||
body: JSON.stringify({ reason }),
|
||
});
|
||
|
||
/** 人工重试异常项(仅重新查询 ERP,新 Attempt) */
|
||
export const retryTransferItem = (itemId: number) =>
|
||
requestJson<TransferActionResult>(`${BASE}/items/${itemId}/retry`, {
|
||
method: 'POST',
|
||
headers: jsonHeaders(),
|
||
body: JSON.stringify({ kind: 'erp_recheck' }),
|
||
});
|
||
|
||
/** 人工关闭异常项 */
|
||
export const manualCloseTransferItem = (itemId: number, reason: string) =>
|
||
requestJson<TransferActionResult>(`${BASE}/items/${itemId}/manual-close`, {
|
||
method: 'POST',
|
||
headers: jsonHeaders(),
|
||
body: JSON.stringify({ reason }),
|
||
});
|
||
|
||
/** 下载收料来源文件(zip) */
|
||
export const downloadTransferReceiptFiles = (runNo: string) =>
|
||
requestBlob(`${BASE}/runs/${runNo}/receipt-files`, { headers: getAuthHeaders() });
|
||
|
||
/** 下载预检冻结的 ERP 库存表(csv) */
|
||
export const downloadTransferErpInventory = (runNo: string) =>
|
||
requestBlob(`${BASE}/runs/${runNo}/erp-inventory`, { headers: getAuthHeaders() });
|
||
|
||
/** 下载七 Sheet 异常 Excel */
|
||
export const downloadTransferExceptions = (runNo: string) =>
|
||
requestBlob(`${BASE}/runs/${runNo}/exceptions.xlsx`, { headers: getAuthHeaders() });
|
||
|
||
/** 批量重查 ERP 库存(可恢复阻断行;invoice_nos 缺省 = 全部阻断行) */
|
||
export const requeryTransferItems = (precheckNo: string, invoiceNos?: string[]) =>
|
||
requestJson<{ precheck_no: string; total: number; results: Array<Record<string, unknown>> }>(
|
||
`${BASE}/prechecks/${precheckNo}/items/requery`,
|
||
{ method: 'POST', body: JSON.stringify(invoiceNos ? { invoice_nos: invoiceNos } : {}), headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' } },
|
||
);
|
||
|
||
/** 按选中来源打包下载各自最新归档收料文件(zip) */
|
||
export const downloadTransferSourceFiles = (sourceCodes: string[]) =>
|
||
requestBlob(`${BASE}/sources/receipt-files`, {
|
||
method: 'POST',
|
||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ source_codes: sourceCodes }),
|
||
});
|
||
|
||
/** 待处理异常列表(可恢复/已关闭/结果未知 + 老化等级) */
|
||
export const listTransferBacklog = () =>
|
||
requestJson<TransferBacklogItem[]>(`${BASE}/backlog`, { headers: getAuthHeaders() });
|
||
|
||
/** 待处理异常汇总(含 3/5/7 天老化分级) */
|
||
export const getTransferBacklogSummary = () =>
|
||
requestJson<TransferBacklogSummary>(`${BASE}/backlog/summary`, { headers: getAuthHeaders() });
|
||
|
||
/** 来源实例列表(平台 DBS/Crane 仅分组,每来源附收料文件状态) */
|
||
export const listTransferSources = () =>
|
||
requestJson<TransferSourceOption[]>(`${BASE}/sources`, { headers: getAuthHeaders() });
|
||
|
||
/** 对指定来源重新触发一次收料 RPA 抓取 */
|
||
export const retryTransferSourceRpa = (sourceCode: string) =>
|
||
requestJson<TransferSourceFileStatus>(`${BASE}/sources/${encodeURIComponent(sourceCode)}/retry-rpa`, {
|
||
method: 'POST',
|
||
headers: jsonHeaders(),
|
||
});
|