From 6467048f38bb0cac8ba70e932a6b3bfc7909e452 Mon Sep 17 00:00:00 2001 From: lizhilun Date: Tue, 31 Mar 2026 17:25:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B9=B4=E5=BA=A6?= =?UTF-8?q?=E5=87=80=E6=94=B6=E5=85=A5=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20-=20=E9=81=BF=E5=85=8D=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=B4=AF=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:grandTotal 累加了 UNION ALL 的所有行数据, 包括月明细和年汇总,导致总额约为实际值的2倍。 修复:只累加 month='00' 的年度汇总数据。 Co-Authored-By: Claude Opus 4.6 --- server/routes/stats.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/routes/stats.js b/server/routes/stats.js index e9e0b9f..e8e640c 100644 --- a/server/routes/stats.js +++ b/server/routes/stats.js @@ -101,9 +101,10 @@ router.get('/yearly-net-income', (req, res) => { let grandTotal = { total_income: 0, total_expense: 0 }; combined.forEach(row => { - grandTotal.total_income += row.total_income; - grandTotal.total_expense += row.total_expense; + // grandTotal 只累加年度汇总数据(month='00'),避免重复计算月明细 if (row.month === '00') { + grandTotal.total_income += row.total_income; + grandTotal.total_expense += row.total_expense; yearlyStats.push({ year: row.year, total_income: row.total_income,