Merge pull request 'fix: 修复流水取数漏传 cloudDb 导致流水列静默为空(#43 追随修复)' (#44) from codex/daily-inventory-complete-data-0927 into main

This commit is contained in:
youruo 2026-09-27 10:04:05 +08:00
commit 68d1fcec00
3 changed files with 11 additions and 1 deletions

View File

@ -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();
});

View File

@ -93,6 +93,9 @@ const AVAILABLE_FLOW_FIELDS = FLOW_QUERIES.map((q) => q.field);
* @returns {Promise<Map<string, Object>>} 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) {

View File

@ -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'),
/第一个参数必须是数据库实例/
);
});