Files
SupplierSystem/server/src/services/mainSystem/api/planChanges.ts
T
Ubuntu b18e0c3f0a
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(主系统计划): 分拣实重扣库与备货计划同步
供应商侧:按 SKU 库存单位称重出库;订单单位不一致时分拣后更新本地计划/实收并写 outbox,主系统接口开关默认关可重试。
2026-11-02 17:43:40 +08:00

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;
}