From f6ee444d36cbae5a5477ea1ed943f397f8a0ceec Mon Sep 17 00:00:00 2001 From: liufumingren Date: Fri, 21 Aug 2026 23:34:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(storage):=20=E5=85=A5=E5=BA=93=E5=8D=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=A1=8C=E7=BA=A7=E6=96=B0=E5=A2=9E=20total?= =?UTF-8?q?=5Fquantity/received=5Fquantity=20=E6=95=B0=E9=87=8F=E6=B1=87?= =?UTF-8?q?=E6=80=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - storage.entry.list/listStore 按当前页入库单批量聚合 wms_entry_items(SUM(count)/SUM(received_quantity))注入每行 - 无明细行补 0,不影响筛选/分页/排序逻辑 --- app/service/systems/storage/entry.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/service/systems/storage/entry.js b/app/service/systems/storage/entry.js index 260a70a..26b619d 100644 --- a/app/service/systems/storage/entry.js +++ b/app/service/systems/storage/entry.js @@ -490,12 +490,37 @@ class EntryService extends Service { } } - // 为每行附加收货单绑定信息 + // 批量聚合当前页入库单的商品总数量(计划数)与已入库数量 + /** @type {Map} */ + const quantityMap = new Map(); + if (entryOrderIds.length > 0) { + const quantityRows = await ctx.model.EntryItems.findAll({ + attributes: [ + 'order_id', + [ Sequelize.fn('SUM', Sequelize.col('count')), 'total_quantity' ], + [ Sequelize.fn('SUM', Sequelize.col('received_quantity')), 'received_quantity' ], + ], + where: { order_id: { [Op.in]: entryOrderIds } }, + group: [ 'order_id' ], + raw: true, + }); + for (const item of quantityRows) { + quantityMap.set(Number(item.order_id), { + total_quantity: Number(item.total_quantity) || 0, + received_quantity: Number(item.received_quantity) || 0, + }); + } + } + + // 为每行附加收货单绑定信息与数量汇总 const enrichedRows = rows.map(row => { const rowJSON = row.toJSON ? row.toJSON() : row; const bindings = receivingBindingsMap.get(row.id) || []; + const quantity = quantityMap.get(row.id) || { total_quantity: 0, received_quantity: 0 }; return { ...rowJSON, + total_quantity: quantity.total_quantity, + received_quantity: quantity.received_quantity, receivingBindings: bindings, hasReceiving: bindings.length > 0, };