开发者要求:「先确保我们这边能够正常使用,然后再考虑主系统那边也能用」。
全仓扫描后确认服务端解析条码**只有三处**,本轮把漏掉的补齐并逐条真库验证:
① 分拣扫码 scanPickingBarcode → 已在本分拣单内反查(上一提交)✅
实测(临时单):用主系统 SKU 扫 ⇒ 命中我方行、picked_qty=1.00/review_status=20
② 发车核货扫码 scanDeliveryLoadingBarcode → **两处**查询都补共享兜底(匹配 + "未找到条码"判定)
实测(临时单):用主系统 SKU 扫 ⇒ 返回 sku_code=SKU88064225461、item_name=土豆、
loaded_qty=6、all_loaded=true(我方配送员扫新标签照旧可用)
③ 秤端「扫码搜索 / 按商品取待办」weighStationService → 匹配 label_barcode
实测(真实单 ORD_API_20261013_BR003_0003):用主系统 SKU 过滤 ⇒ ["土豆/SKU88064225461"]
④ 旧秤端打印通道 printJobService 的标签条码同步对齐(同一条 COALESCE 链),避免两套标签口径不一致
⑤ 老标签(我方码)不受影响:解析先走原路径,未命中才兜底(契约测试钉住顺序)
真实单实测(四行都是导入行):瘦肉⇒SKU78664481821、土豆⇒SKU78661069731、
苹果⇒SKU78666376463、抄手皮⇒SKU78662536922(`barcode` 字段仍是我方码,只改二维码内容)。
顺带:pickingRowCleanupOnReturn 的 SQL 窗口 3000→6000(本次在 SELECT 里加了
label_barcode + 台账 JOIN,谓词被推出原窗口;非功能回归)。
回归:server 套件与基线一致(新增失败仅上述窗口问题,已修);相关 6 文件全绿;tsc 0;门禁 8/1/1。
设计文 §7/§8:我方消费点全量表 + 主系统侧现状与待办(他们扫码零改造;入库扫码入口需他们新增)。
107 lines
5.8 KiB
TypeScript
107 lines
5.8 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
import { describe, expect, it } from 'vitest';
|
||
|
||
/**
|
||
* **分拣标签二维码:两边都能扫**(2026-10-13 方案 A,开发者确认:务必保证我方与主系统都能扫)。
|
||
*
|
||
* 背景:同一件商品在主系统是他们的 SKU(如土豆 `SKU78661069731`),在我方是另一个 SKU
|
||
* (`SKU88064225461`)⇒ 不能为了兼容主系统而让我方配送员扫不了。
|
||
*
|
||
* 方案:
|
||
* ① 打印:有主系统来源的行 ⇒ 印**主系统的 SKU**(他们 `SELECT sku_code FROM skus WHERE barcode=$1 OR sku_code=$1`
|
||
* 零改造就能命中);无来源 ⇒ 回退我方 barcode/SKU(现状);
|
||
* ② 我方扫码:两个入口(分拣扫码 / 发车核货扫码)在未命中我方 `skus` 时,
|
||
* 用共享函数 `resolveOurSkuByMainSystemSku` **在本单/本分拣单内**反查 ⇒ 扫同一个码照旧能用。
|
||
*
|
||
* 真库实测(临时单,跑完即清理):造单用**他们的** SKU `SKU78661069731` ⇒ 台账记 main_sku_code,
|
||
* 我方行 = `SKU88064225461`;标签将印 `SKU78661069731`;用该码走我方分拣扫码 ⇒ 反查命中,
|
||
* 该行 `picked_qty=1.00 / review_status=20`(我方配送员照旧能扫)。
|
||
*/
|
||
const SRC = path.join(__dirname, '../src');
|
||
const read = (rel: string) => readFileSync(path.join(SRC, rel), 'utf8');
|
||
|
||
describe('分拣标签二维码:主系统与我方都能扫', () => {
|
||
const picking = read('services/pickingService.ts');
|
||
const loading = read('services/deliveryLoadingService.ts');
|
||
const mapping = read('services/mainSystemItemSkuMappingService.ts');
|
||
|
||
it('① 标签码取值:主系统 SKU 优先,其次我方条码/SKU 链', () => {
|
||
const idx = picking.indexOf('AS label_barcode');
|
||
expect(idx).toBeGreaterThan(-1);
|
||
const block = picking.slice(idx - 700, idx);
|
||
expect(block).toContain('NULLIF(TRIM(msi.main_sku_code), \'\')');
|
||
expect(block).toContain('NULLIF(TRIM(s.barcode), \'\')');
|
||
// 关联主系统行级台账(按我方明细 id)
|
||
expect(picking).toContain(
|
||
'LEFT JOIN public.main_system_order_import_items msi ON msi.our_order_item_id = pi.order_item_id'
|
||
);
|
||
});
|
||
|
||
it('② 前端/小程序打印优先用 label_barcode,老接口回退 barcode', () => {
|
||
const page = readFileSync(path.join(__dirname, '../../src/pages/picking/PickingManagement.tsx'), 'utf8');
|
||
const hits = page.match(/item\.label_barcode \|\| item\.barcode \|\| item\.sku_code/g) || [];
|
||
expect(hits.length).toBe(2); // 单行打印 + 批量打印
|
||
const mp = readFileSync(
|
||
path.join(__dirname, '../../miniprogram/utils/pickingLabelPrint.js'),
|
||
'utf8'
|
||
);
|
||
expect(mp).toContain('item.label_barcode || item.barcode || item.sku_code');
|
||
});
|
||
|
||
it('③ 我方两个扫码入口都用共享兜底(未命中我方 skus 时才走)', () => {
|
||
expect(mapping).toContain('export async function resolveOurSkuByMainSystemSku(');
|
||
// 分拣扫码:必须在本分拣单内反查
|
||
expect(picking).toContain('resolveOurSkuByMainSystemSku({');
|
||
expect(picking).toContain('pickCode: input.pickCode,');
|
||
// 发车核货扫码:必须在本单内反查
|
||
expect(loading).toContain('resolveOurSkuByMainSystemSku({');
|
||
expect(loading).toContain('orderCode,');
|
||
// 兜底只发生在原解析未命中之后(老标签行为不变)
|
||
const skuMissIdx = picking.indexOf("if (!skuCode) throw new Error(`未找到条码对应商品:${barcode}`)");
|
||
const fallbackIdx = picking.indexOf('resolveOurSkuByMainSystemSku({');
|
||
expect(fallbackIdx).toBeGreaterThan(-1);
|
||
expect(skuMissIdx).toBeGreaterThan(fallbackIdx);
|
||
});
|
||
|
||
it('④ 兜底必须带上下文(不带单号/分拣单号一律不做全局猜测)', () => {
|
||
const idx = mapping.indexOf('export async function resolveOurSkuByMainSystemSku(');
|
||
const body = mapping.slice(idx, idx + 900);
|
||
expect(body).toContain('if (!barcode || (!pickCode && !orderCode)) return null;');
|
||
});
|
||
});
|
||
|
||
/**
|
||
* 我方**全部**条码消费点核查(2026-10-13 开发者要求:先确保我方正常使用)。
|
||
* 全仓扫描结果:服务端解析条码只有三处 ——
|
||
* ① 分拣扫码 scanPickingBarcode(小程序分拣扫码)
|
||
* ② 发车核货扫码 scanDeliveryLoadingBarcode(小程序装车连续扫码;两处查询:匹配 + 报错判定)
|
||
* ③ 秤端搜索 searchPendingWeighStation / filterRowsBySkuThenName(安卓称重终端扫码搜索)
|
||
* 三处都必须在"未命中我方 skus"时认得**主系统 SKU**(标签二维码内容);否则我方扫新标签会失败。
|
||
*/
|
||
describe('我方所有条码消费点都认得主系统 SKU', () => {
|
||
const weigh = read('services/weighStationService.ts');
|
||
const printJob = read('services/printJobService.ts');
|
||
const loading = read('services/deliveryLoadingService.ts');
|
||
|
||
it('⑤ 秤端模糊搜索 + 按商品取待办都匹配 label_barcode(主系统 SKU)', () => {
|
||
expect(weigh).toContain('const label = String(row.label_barcode || \'\').toLowerCase();');
|
||
expect(weigh).toContain('(!!label && label === like)');
|
||
expect(weigh).toContain('const byMainSku = items.filter(');
|
||
expect(weigh).toContain("String(row.label_barcode || '').trim() === sku");
|
||
});
|
||
|
||
it('⑥ 发车核货扫码的"报错判定"那一处也走同一兜底(否则误报未找到条码)', () => {
|
||
const hits = loading.match(/resolveOurSkuByMainSystemSku\(/g) || [];
|
||
expect(hits.length).toBe(2);
|
||
expect(loading).toContain('let knownSku = skuMiss.rows[0]?.sku_code');
|
||
});
|
||
|
||
it('⑦ 旧秤端打印通道(已停用但保留)同步对齐,避免两套标签口径不一致', () => {
|
||
expect(printJob).toContain('NULLIF(TRIM(msi.main_sku_code), \'\')');
|
||
expect(printJob).toContain(
|
||
'LEFT JOIN public.main_system_order_import_items msi ON msi.our_order_item_id = pi.order_item_id'
|
||
);
|
||
});
|
||
});
|