fix(energy): hydrogen_time 已是 CST 字面值,去掉多余的 +8 HOUR 转换
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
之前认为 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) <noreply@anthropic.com>
This commit is contained in:
@@ -7,9 +7,9 @@ const app = new Hono();
|
|||||||
|
|
||||||
const HYDROGEN_MIN_DATE = '2024-01-01';
|
const HYDROGEN_MIN_DATE = '2024-01-01';
|
||||||
|
|
||||||
// 把 DATETIME (UTC 字面值) 转换为 CST 用户日期
|
// hydrogen_time 已是 CST 字面值,直接使用即可(不再 +8 小时)
|
||||||
const HYDROGEN_LOCAL = `DATE_ADD(hydrogen_time, INTERVAL 8 HOUR)`;
|
const HYDROGEN_LOCAL = `hydrogen_time`;
|
||||||
const ELECTRIC_LOCAL = `DATE_ADD(charging_start_time, INTERVAL 8 HOUR)`;
|
const ELECTRIC_LOCAL = `charging_start_time`;
|
||||||
|
|
||||||
type CustomerKind = 'external' | 'lingniu' | 'all';
|
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
|
LEFT JOIN tab_import_hydrogen_order i ON i.bill_code = b.bill_code
|
||||||
WHERE b.is_deleted = 0
|
WHERE b.is_deleted = 0
|
||||||
AND b.hydrogen_time >= ?
|
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
|
GROUP BY b.hydrogen_station_id
|
||||||
ORDER BY kg DESC
|
ORDER BY kg DESC
|
||||||
LIMIT 5`,
|
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
|
LEFT JOIN tab_outside_hydrogen_site os ON os.inner_site_id = b.hydrogen_station_id
|
||||||
WHERE b.is_deleted = 0
|
WHERE b.is_deleted = 0
|
||||||
AND b.hydrogen_time >= ?
|
AND b.hydrogen_time >= ?
|
||||||
AND YEAR(DATE_ADD(b.hydrogen_time, INTERVAL 8 HOUR)) = YEAR(CURDATE())
|
AND YEAR(b.hydrogen_time) = YEAR(CURDATE())
|
||||||
) r
|
) r
|
||||||
GROUP BY region
|
GROUP BY region
|
||||||
ORDER BY kg DESC`,
|
ORDER BY kg DESC`,
|
||||||
@@ -159,7 +159,7 @@ app.get('/hydrogen/daily', async (c) => {
|
|||||||
const where = [
|
const where = [
|
||||||
'b.is_deleted = 0',
|
'b.is_deleted = 0',
|
||||||
`b.hydrogen_time >= '${HYDROGEN_MIN_DATE}'`,
|
`b.hydrogen_time >= '${HYDROGEN_MIN_DATE}'`,
|
||||||
rangeClause(`b.hydrogen_time + INTERVAL 8 HOUR`, range),
|
rangeClause(`b.hydrogen_time`, range),
|
||||||
customerClause('b.truck_id', customer),
|
customerClause('b.truck_id', customer),
|
||||||
].join(' AND ');
|
].join(' AND ');
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ app.get('/hydrogen/daily', async (c) => {
|
|||||||
// 站点名 fallback:内部站表 → 外部站表 → 导入订单表(tab_import_hydrogen_order,按 bill_code 关联)
|
// 站点名 fallback:内部站表 → 外部站表 → 导入订单表(tab_import_hydrogen_order,按 bill_code 关联)
|
||||||
// 单价不重算:同价组显示原价,混合价组返回 NULL,前端显示「—」
|
// 单价不重算:同价组显示原价,混合价组返回 NULL,前端显示「—」
|
||||||
const [stationRows] = await pool.query<RowDataPacket[]>(
|
const [stationRows] = await pool.query<RowDataPacket[]>(
|
||||||
`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,
|
b.hydrogen_station_id AS stationId,
|
||||||
COALESCE(MAX(s.short_name), MAX(s.name),
|
COALESCE(MAX(s.short_name), MAX(s.name),
|
||||||
MAX(os.fixed_station_name), MAX(os.station_name),
|
MAX(os.fixed_station_name), MAX(os.station_name),
|
||||||
|
|||||||
Reference in New Issue
Block a user