58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
import { MAIN_SYSTEM_FETCH_TIMEOUT_MS, MAIN_SYSTEM_DEFAULT_PATHS } from '../config';
|
|
import { getMainSystemToken } from '../token';
|
|
import { requestMainSystem, type MainSystemResult } from '../http';
|
|
import { mainSystemPlanChangePath } from '../endpoints';
|
|
|
|
/**
|
|
* 供应商分拣后修改主系统备货计划(数量/单位)。
|
|
*
|
|
* 契约见 handoff/20261102-主系统备货计划变更-提示词与实施计划.md。
|
|
* 主系统必须只改供应商备货计划,不改客户订单金额/成交价;备注与通知由主系统负责。
|
|
*/
|
|
export type MainSystemPlanChangePayload = {
|
|
prep_id: string;
|
|
order_item_id?: string | null;
|
|
before_qty: number;
|
|
before_unit: string;
|
|
after_qty: number;
|
|
after_unit: string;
|
|
actual_received_qty: number;
|
|
original_customer_qty?: number | null;
|
|
original_customer_unit?: string | null;
|
|
reason?: string | null;
|
|
source?: string;
|
|
client_request_id: string;
|
|
};
|
|
|
|
export async function submitMainSystemPlanChange(input: {
|
|
branchCode: string;
|
|
payload: MainSystemPlanChangePayload;
|
|
fetchImpl?: typeof fetch;
|
|
}): Promise<MainSystemResult<any>> {
|
|
const prepId = String(input.payload?.prep_id || '').trim();
|
|
if (!prepId) return { kind: 'rejected', status: 0, reason: '缺少主系统备货行 id', payload: null };
|
|
const tokenResult = await getMainSystemToken(input.branchCode);
|
|
if (tokenResult.kind === 'not_configured') {
|
|
return { kind: 'not_configured', status: 0, reason: tokenResult.reason, payload: null };
|
|
}
|
|
if (tokenResult.kind !== 'ok') {
|
|
return { kind: 'unavailable', status: 0, reason: tokenResult.reason, payload: null };
|
|
}
|
|
return requestMainSystem<any>({
|
|
endpoint: 'supplierPlanChange',
|
|
method: 'POST',
|
|
token: tokenResult.token,
|
|
path: mainSystemPlanChangePath(prepId),
|
|
body: input.payload,
|
|
timeoutMs: MAIN_SYSTEM_FETCH_TIMEOUT_MS,
|
|
timeoutReason: '修改主系统备货计划超时',
|
|
networkReasonPrefix: '修改主系统备货计划失败:',
|
|
fetchImpl: input.fetchImpl,
|
|
});
|
|
}
|
|
|
|
/** 仅用于检查端点表不会静默丢失(主系统未交付时也允许读到默认路径)。 */
|
|
export function defaultPlanChangeBasePath(): string {
|
|
return MAIN_SYSTEM_DEFAULT_PATHS.supplierPlanChange;
|
|
}
|