From 57207debfbfde9f5543cdfc91dbe6c7d9058401c Mon Sep 17 00:00:00 2001 From: kkfluous Date: Wed, 29 Apr 2026 20:54:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(energy):=20hydrogen=5Ftime=20=E5=B7=B2?= =?UTF-8?q?=E6=98=AF=20CST=20=E5=AD=97=E9=9D=A2=E5=80=BC=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=A4=9A=E4=BD=99=E7=9A=84=20+8=20HOUR=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前认为 hydrogen_time / charging_start_time 字段存的是 UTC, 所有氢能查询都加了 DATE_ADD(..., INTERVAL 8 HOUR) 转 CST。 但实际上字段存的是 CST 字面值,转换反而把日期边界提前了 8 小时, 导致诸如「04-28 嘉兴嘉燃经开站」的统计少算了部分晚间订单。 实测: - 之前:04-28 嘉燃经开 = 144.36 Kg(CST 转换错位) - 现在:04-28 嘉燃经开 = 153.81 Kg(与业务方直接 DATE(hydrogen_time) 口径一致) 电能 charging_start_time 同样去掉转换。 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/server/routes/energy/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/server/routes/energy/index.ts b/src/server/routes/energy/index.ts index 75c7a67..6fa4987 100644 --- a/src/server/routes/energy/index.ts +++ b/src/server/routes/energy/index.ts @@ -7,9 +7,9 @@ const app = new Hono(); const HYDROGEN_MIN_DATE = '2024-01-01'; -// 把 DATETIME (UTC 字面值) 转换为 CST 用户日期 -const HYDROGEN_LOCAL = `DATE_ADD(hydrogen_time, INTERVAL 8 HOUR)`; -const ELECTRIC_LOCAL = `DATE_ADD(charging_start_time, INTERVAL 8 HOUR)`; +// hydrogen_time 已是 CST 字面值,直接使用即可(不再 +8 小时) +const HYDROGEN_LOCAL = `hydrogen_time`; +const ELECTRIC_LOCAL = `charging_start_time`; type CustomerKind = 'external' | 'lingniu' | 'all'; @@ -98,7 +98,7 @@ app.get('/hydrogen/overview', async (c) => { LEFT JOIN tab_import_hydrogen_order i ON i.bill_code = b.bill_code WHERE b.is_deleted = 0 AND b.hydrogen_time >= ? - AND YEAR(DATE_ADD(b.hydrogen_time, INTERVAL 8 HOUR)) = YEAR(CURDATE()) + AND YEAR(b.hydrogen_time) = YEAR(CURDATE()) GROUP BY b.hydrogen_station_id ORDER BY kg DESC LIMIT 5`, @@ -123,7 +123,7 @@ app.get('/hydrogen/overview', async (c) => { LEFT JOIN tab_outside_hydrogen_site os ON os.inner_site_id = b.hydrogen_station_id WHERE b.is_deleted = 0 AND b.hydrogen_time >= ? - AND YEAR(DATE_ADD(b.hydrogen_time, INTERVAL 8 HOUR)) = YEAR(CURDATE()) + AND YEAR(b.hydrogen_time) = YEAR(CURDATE()) ) r GROUP BY region ORDER BY kg DESC`, @@ -159,7 +159,7 @@ app.get('/hydrogen/daily', async (c) => { const where = [ 'b.is_deleted = 0', `b.hydrogen_time >= '${HYDROGEN_MIN_DATE}'`, - rangeClause(`b.hydrogen_time + INTERVAL 8 HOUR`, range), + rangeClause(`b.hydrogen_time`, range), customerClause('b.truck_id', customer), ].join(' AND '); @@ -167,7 +167,7 @@ app.get('/hydrogen/daily', async (c) => { // 站点名 fallback:内部站表 → 外部站表 → 导入订单表(tab_import_hydrogen_order,按 bill_code 关联) // 单价不重算:同价组显示原价,混合价组返回 NULL,前端显示「—」 const [stationRows] = await pool.query( - `SELECT DATE_FORMAT(DATE_ADD(b.hydrogen_time, INTERVAL 8 HOUR), '%Y-%m-%d') AS d, + `SELECT DATE_FORMAT(b.hydrogen_time, '%Y-%m-%d') AS d, b.hydrogen_station_id AS stationId, COALESCE(MAX(s.short_name), MAX(s.name), MAX(os.fixed_station_name), MAX(os.station_name),