ming #1

Merged
liufumingren merged 558 commits from ming into main 2026-11-18 16:13:25 +08:00
Showing only changes of commit f6ee444d36 - Show all commits

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,
};