免入库(主系统骑手上门取货): - 50 展示「待取货」、副文案「待主系统骑手上门取货」、不建我方配送任务(守卫与开关解耦) - 我方 50 即回写备货完成;两开关(SKIP_INBOUND_AWAIT_PICKUP / FULFILLMENT_EVENTS)改默认开 核货事实镜像(「核货完毕」标记): - 按主系统 lookup 的 actual_qty 落台账,新增 GET/POST /orders/:orderCode/main-system-prep-facts[/refresh] - 详情行内显示「核货完毕」(含核货量),分配对账兜底刷新 实收数量/单位口径变更(对方先改 + 我方事后同步): - 台账加 applied_at;inbound 与 picking_check 同为事实登记(驳回不回滚) - 同意才落我方值:免入库改装车核货量、送仓改验收实收(已入库走既有库存调整)、已结算/已结案只留痕 - 计划量与金额一起改,并同步结算投影(syncStatementsForOrderSafe) - 审核页语义改「主系统实际值(已生效)/ 是否同步」+ 已处理历史(双方时间与落值结论) 台账对照与回写修复: - 行级对照改整单一次性(同名商品不再重复认领)+ 存量纠正 healOrderPrepMapping - 堵住客户绑定回填旁路(免入库单不再被派我方骑手) - 回写触发函数改对象参数(修 branch/order 传反导致的静默不回写) 文档:设计文档 4 篇 +《给主系统 AI 的对接改造清单》§2.9(第六批契约) 回归:服务端全量与 HEAD 基线一致(24 个失败文件同集合);前端 140 文件 / 699 测试全绿;tsc 双端干净
73 lines
3.8 KiB
TypeScript
73 lines
3.8 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/**
|
|
* 客户口径(开发者 2026-10-11 定稿):**主系统的分公司名字就是客户名字**。
|
|
* · 一个主系统下单分公司 = 我方一个客户;客户编码 `MAIN_<分公司编码>`;客户名 = 分公司名;
|
|
* · 分公司名在主系统为空 ⇒ 「主系统分公司 <编码>」兜底(开发者批准);
|
|
* · 名字**没被占用就不加编号**(占用才 `-2`/`-3`);
|
|
* · 拿不到分公司编码(webhook 剥字段)⇒ 退回原占位客户,行为与本改动前一致;
|
|
* · 存量订单按台账/主系统单号里的 `_BRxxx_` 段改挂(开发者决策 ③「需要」)。
|
|
*/
|
|
const importSrc = readFileSync(
|
|
new URL('../src/services/mainSystemOrderImport.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const ledgerSrc = readFileSync(new URL('../src/services/mainSystemPrepLedger.ts', import.meta.url), 'utf8');
|
|
const script = readFileSync(
|
|
new URL('../scripts/reattribute-main-system-branch-customers.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
|
|
describe('客户 = 主系统分公司,客户名 = 分公司名', () => {
|
|
it('客户编码用 MAIN_<分公司编码>,名字用分公司名,空名走兜底', () => {
|
|
expect(importSrc).toContain('`${IMPORT_CUSTOMER_PREFIX}${mainBranchCode}`');
|
|
expect(importSrc).toContain('function fallbackBranchName(mainBranchCode: string)');
|
|
expect(importSrc).toContain('主系统分公司 ${mainBranchCode}');
|
|
expect(importSrc).toMatch(/mainBranchName \|\| fallbackBranchName\(mainBranchCode\)/);
|
|
});
|
|
|
|
it('名字只在被别的客户占用时才加编号', () => {
|
|
const start = importSrc.indexOf('async function dedupeCustomerName');
|
|
const fn = importSrc.slice(start, start + 1200);
|
|
expect(fn).toContain('WHERE company_name = $1 AND customer_code <> $2');
|
|
expect(fn).toContain('if (!taken.rowCount) return baseName;');
|
|
expect(fn).toContain('${baseName}-${i}');
|
|
});
|
|
|
|
it('拿不到分公司编码时退回占位客户(webhook 剥字段的历史兼容)', () => {
|
|
expect(importSrc).toContain('fallbackPlaceholderName');
|
|
expect(importSrc).toMatch(/hasMainBranch\s*\?\s*`\$\{IMPORT_CUSTOMER_PREFIX\}\$\{mainBranchCode\}`/);
|
|
});
|
|
|
|
it('归属取当日行里出现最多的分公司(真混合时告警,不静默丢)', () => {
|
|
const start = importSrc.indexOf('function pickDayMainBranch');
|
|
const fn = importSrc.slice(start, start + 1400);
|
|
expect(fn).toContain('counter');
|
|
expect(fn).toContain('多个下单分公司');
|
|
expect(importSrc).toContain('pickDayMainBranch(pending.flatMap((entry) => entry.rows))');
|
|
});
|
|
|
|
it('台账落 main_branch_code / main_branch_name(非空才覆盖)', () => {
|
|
expect(ledgerSrc).toContain('main_branch_code, main_branch_name');
|
|
expect(ledgerSrc).toContain(
|
|
'main_branch_code = COALESCE(EXCLUDED.main_branch_code, public.main_system_order_import_items.main_branch_code)'
|
|
);
|
|
expect(ledgerSrc).toContain('row.branchCode ? String(row.branchCode).trim().toUpperCase() : null');
|
|
});
|
|
});
|
|
|
|
describe('存量归属改挂(决策 ③)', () => {
|
|
it('导出可复用函数 + 一次性脚本,归属依据逐级回退且不瞎猜', () => {
|
|
expect(importSrc).toContain('export async function reattributeMainSystemOrdersToBranchCustomers');
|
|
expect(importSrc).toContain('BR[0-9A-Z]+');
|
|
const start = importSrc.indexOf('export async function reattributeMainSystemOrdersToBranchCustomers');
|
|
const fn = importSrc.slice(start, start + 3800);
|
|
expect(fn).toContain('if (!mainBranchCode) continue;');
|
|
expect(fn).toContain('customer_code IS DISTINCT FROM $2');
|
|
expect(fn).toContain('SET status = 40');
|
|
expect(fn).toContain('SELECT count(*)::text AS count FROM orders WHERE customer_code = $1');
|
|
expect(script).toContain('reattributeMainSystemOrdersToBranchCustomers');
|
|
});
|
|
});
|