fix(主系统计划): 用主系统供应商编码换 token
之前把本地 branch_code 当 supplier_code,换 token 403;改为从导入台账 main_supplier_code 取值。
This commit is contained in:
@@ -25,13 +25,14 @@ export type MainSystemPlanChangePayload = {
|
||||
};
|
||||
|
||||
export async function submitMainSystemPlanChange(input: {
|
||||
branchCode: string;
|
||||
/** 主系统供应商编码(不是供应商本地 branch_code;二者常不相等) */
|
||||
supplierCode: 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);
|
||||
const tokenResult = await getMainSystemToken(input.supplierCode);
|
||||
if (tokenResult.kind === 'not_configured') {
|
||||
return { kind: 'not_configured', status: 0, reason: tokenResult.reason, payload: null };
|
||||
}
|
||||
|
||||
@@ -135,6 +135,35 @@ export async function dispatchMainSystemPlanChange(changeId: string): Promise<Pl
|
||||
};
|
||||
}
|
||||
|
||||
const supplierRow = await pool.query(
|
||||
`SELECT main_supplier_code
|
||||
FROM public.main_system_order_import_items
|
||||
WHERE prep_id = $1::uuid
|
||||
LIMIT 1`,
|
||||
[row.prep_id]
|
||||
);
|
||||
const mainSupplierCode = String(supplierRow.rows[0]?.main_supplier_code || '').trim();
|
||||
if (!mainSupplierCode) {
|
||||
await pool.query(
|
||||
`UPDATE public.main_system_plan_changes
|
||||
SET status = 'failed', last_error = $2, updated_at = NOW()
|
||||
WHERE id = $1::uuid`,
|
||||
[changeId, '缺少主系统供应商编码(main_supplier_code),请重新拉取备货行']
|
||||
);
|
||||
return {
|
||||
change_id: String(row.id),
|
||||
request_id: String(row.request_id),
|
||||
status: 'failed',
|
||||
before_qty: Number(row.before_qty) || 0,
|
||||
before_unit: String(row.before_unit || ''),
|
||||
after_qty: Number(row.after_qty) || 0,
|
||||
after_unit: String(row.after_unit || ''),
|
||||
actual_received_qty: Number(row.actual_received_qty) || 0,
|
||||
sync_enabled: true,
|
||||
message: '缺少主系统供应商编码,待重新拉取后同步',
|
||||
};
|
||||
}
|
||||
|
||||
await pool.query(
|
||||
`UPDATE public.main_system_plan_changes
|
||||
SET status = 'syncing', attempts = attempts + 1, updated_at = NOW()
|
||||
@@ -144,7 +173,7 @@ export async function dispatchMainSystemPlanChange(changeId: string): Promise<Pl
|
||||
let result;
|
||||
try {
|
||||
result = await submitMainSystemPlanChange({
|
||||
branchCode: String(row.branch_code),
|
||||
supplierCode: mainSupplierCode,
|
||||
payload: payloadOf(row),
|
||||
});
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -40,6 +40,7 @@ describe('主系统备货计划变更(供应商侧)', () => {
|
||||
expect(svc).toContain('mainOrderItemId');
|
||||
expect(svc).toContain('main_order_item_id');
|
||||
expect(svc).toContain("payload->>'mainOrderItemId'");
|
||||
expect(svc).toContain('main_supplier_code');
|
||||
});
|
||||
|
||||
it('库存出库和分拣称重按 SKU 库存单位判断', () => {
|
||||
|
||||
Reference in New Issue
Block a user