feat(storage): 入库单列表行级新增 total_quantity/received_quantity 数量汇总

- storage.entry.list/listStore 按当前页入库单批量聚合 wms_entry_items(SUM(count)/SUM(received_quantity))注入每行
- 无明细行补 0,不影响筛选/分页/排序逻辑
This commit is contained in:
liufumingren 2026-08-21 23:34:06 +08:00
parent 4b4b645257
commit f6ee444d36

View File

@ -490,12 +490,37 @@ class EntryService extends Service {
}
}
// 为每行附加收货单绑定信息
// 批量聚合当前页入库单的商品总数量(计划数)与已入库数量
/** @type {Map<number, {total_quantity: number, received_quantity: number}>} */
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,
};