fix(energy): 氢能站点 fallback 区分「未关联」与「未知 #ID」
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
之前两张 site 表都查不到的账单,UI 一律显示「未知站点」。 其中 137 条 station_id 为 NULL(账单未填站点),3 条 station_id 有值但站点表没收录(站点删除/字典漂移)。账单上的 cost_price 是真实的, 所以会出现「未知站点 25 元/Kg」这种可追溯但难定位的情况。 现在 SQL fallback 改为: - station_id IS NULL → 「未关联站点」 - station_id 不为空但 join 不上 → 「未知站点 #ID」 方便定位具体是哪条字典记录缺失。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -85,7 +85,9 @@ app.get('/hydrogen/overview', async (c) => {
|
||||
// Top5 加氢站(本年)
|
||||
const [top5Rows] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT b.hydrogen_station_id AS id,
|
||||
COALESCE(s.short_name, s.name, os.fixed_station_name, os.station_name, '未知站点') AS name,
|
||||
COALESCE(s.short_name, s.name, os.fixed_station_name, os.station_name,
|
||||
CASE WHEN b.hydrogen_station_id IS NULL THEN '未关联站点'
|
||||
ELSE CONCAT('未知站点 #', b.hydrogen_station_id) END) AS name,
|
||||
SUM(b.hydrogen_quantity) AS kg,
|
||||
SUM(b.cost_expense) AS fee
|
||||
FROM tab_energy_hydrogen_bill b
|
||||
@@ -162,7 +164,9 @@ app.get('/hydrogen/daily', async (c) => {
|
||||
const [stationRows] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT DATE_FORMAT(${HYDROGEN_LOCAL}, '%Y-%m-%d') AS d,
|
||||
b.hydrogen_station_id AS stationId,
|
||||
COALESCE(s.short_name, s.name, os.fixed_station_name, os.station_name, '未知站点') AS stationName,
|
||||
COALESCE(s.short_name, s.name, os.fixed_station_name, os.station_name,
|
||||
CASE WHEN b.hydrogen_station_id IS NULL THEN '未关联站点'
|
||||
ELSE CONCAT('未知站点 #', b.hydrogen_station_id) END) AS stationName,
|
||||
SUM(b.hydrogen_quantity) AS kg,
|
||||
AVG(b.cost_price) AS pricePerKg
|
||||
FROM tab_energy_hydrogen_bill b
|
||||
|
||||
Reference in New Issue
Block a user