From 952c57a84adf68e04c9c8c1f815a05149cd46229 Mon Sep 17 00:00:00 2001 From: youruo <15018737611@163.com> Date: Sun, 27 Sep 2026 10:03:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E5=8F=96=E6=95=B0=E6=BC=8F=E4=BC=A0=20cloudDb=20=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=B5=81=E6=B0=B4=E5=88=97=E9=9D=99=E9=BB=98=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 路由调用 fetchFlows(wmsCoIds, from) 少了第一个参数 cloudDb, 导致形参错位(cloudDb=数组、wmsCoIds=日期、fromText=undefined), 函数静默返回空 Map 且无任何报错。补传参数,并为 fetchFlows 增加 防呆校验:首参非数据库实例时立即抛 TypeError。补 1 项回归测试。 --- backend/src/api/dailyInventory.js | 2 +- backend/src/services/dailyInventoryFlows.js | 3 +++ backend/test/dailyInventoryFlows.test.js | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/api/dailyInventory.js b/backend/src/api/dailyInventory.js index 45a3dc1..aec520f 100644 --- a/backend/src/api/dailyInventory.js +++ b/backend/src/api/dailyInventory.js @@ -283,7 +283,7 @@ router.get('/', async (req, res) => { // 流水列:自期初时刻(最新业务日 01:00)以来的单据合计(带符号,流出为负) let flowMap = new Map(); if (openingDate) { - flowMap = await fetchFlows(wmsCoIds, `${latestBizDate} 01:00:00`).catch((e) => { + flowMap = await fetchFlows(cloudDb, wmsCoIds, `${latestBizDate} 01:00:00`).catch((e) => { console.error('[daily-inventory] 流水取数失败:', e.message); return new Map(); }); diff --git a/backend/src/services/dailyInventoryFlows.js b/backend/src/services/dailyInventoryFlows.js index 41014aa..0c612d3 100644 --- a/backend/src/services/dailyInventoryFlows.js +++ b/backend/src/services/dailyInventoryFlows.js @@ -93,6 +93,9 @@ const AVAILABLE_FLOW_FIELDS = FLOW_QUERIES.map((q) => q.field); * @returns {Promise>} key = wmsCoId 字符串,value = { purchaseIn, purchaseReturn, salesOut, salesReturn }(带符号,无记录的字段不出现) */ async function fetchFlows(cloudDb, wmsCoIds, fromText) { + if (!cloudDb || typeof cloudDb.query !== 'function') { + throw new TypeError('fetchFlows 第一个参数必须是数据库实例(防呆:调用漏传 cloudDb 时立即报错而非静默返回空)'); + } const map = new Map(); if (!wmsCoIds.length || !fromText) return map; for (const q of FLOW_QUERIES) { diff --git a/backend/test/dailyInventoryFlows.test.js b/backend/test/dailyInventoryFlows.test.js index d58efed..23e1d66 100644 --- a/backend/test/dailyInventoryFlows.test.js +++ b/backend/test/dailyInventoryFlows.test.js @@ -105,3 +105,10 @@ test('deriveAndStoreOpeningSnapshot:监控表命中走精确值,未命中用 // 带回基线仓库名,保证后续按 wmsCoId 读取正确 assert.equal(byWh.get(102).warehouse, '仓B主仓'); }); + +test('fetchFlows 缺少数据库实例参数时立即抛错(防静默空结果)', async () => { + await assert.rejects( + () => fetchFlows([101, 102], '2026-09-26 01:00:00'), + /第一个参数必须是数据库实例/ + ); +}); -- 2.47.2