From e764ae996ea656102f0f92709c18c4483cee1912 Mon Sep 17 00:00:00 2001 From: wangxiaogang Date: Thu, 4 Jun 2026 20:41:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E8=AE=A1=E6=A6=82=E8=A7=88?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=A1=A5=E5=85=85=20expenseCount/incomeCount?= =?UTF-8?q?/dailyIncome=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端 stats/overview 接口返回字段与前端 Overview 类型不一致 - 前端页面使用了 expenseCount、incomeCount、dailyIncome 但后端未返回 - 导致统计页收入标签切换时日均和笔数显示为 0 - 补充 SQL 聚合查询,返回完整字段 --- server/src/routes/stats.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/src/routes/stats.ts b/server/src/routes/stats.ts index 3258151..30edc60 100644 --- a/server/src/routes/stats.ts +++ b/server/src/routes/stats.ts @@ -72,16 +72,27 @@ router.get('/overview', async (req: AuthRequest, res: Response) => { `SELECT COALESCE(SUM(CASE WHEN t.type = 'expense' THEN t.amount ELSE 0 END), 0) as expense, COALESCE(SUM(CASE WHEN t.type = 'income' THEN t.amount ELSE 0 END), 0) as income, - COUNT(*) as count + COUNT(*) as count, + SUM(CASE WHEN t.type = 'expense' THEN 1 ELSE 0 END) as expenseCount, + SUM(CASE WHEN t.type = 'income' THEN 1 ELSE 0 END) as incomeCount FROM transactions t ${result.where}`, [...result.params, startDate, endDate] ) const row = (rows as any[])[0] const daily = elapsedDays > 0 ? Math.round(row.expense / elapsedDays) : 0 + const dailyIncome = elapsedDays > 0 ? Math.round(row.income / elapsedDays) : 0 res.json({ code: 0, - data: { expense: row.expense, income: row.income, count: row.count, daily } + data: { + expense: row.expense, + income: row.income, + count: row.count, + daily, + dailyIncome, + expenseCount: row.expenseCount, + incomeCount: row.incomeCount + } }) } catch (err) { console.error('[Stats] overview error:', err)