refactor(energy): 氢能总览参照 BI 重构 + 月度趋势 + 高密度 KPI
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
参考 https://bi.lnh2e.com/lingniu/decision/link/0iqP 重新设计: - 4 张高密度 KPI 卡:累计加氢量 / 累计加氢费 / 本月加氢 / 本日加氢 每张含主指标 + 2 行明细(我司/客户、加氢费/占比) - 新增年内月度加氢量柱图(缺失月份补 0) - 数字格式化:万元/亿元/T 单位自动切换,tabular-nums 对齐 - 后端 /hydrogen/overview 增加 monthly 字段 - 骨架屏同步更新 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -165,7 +165,33 @@ app.get('/hydrogen/overview', async (c) => {
|
||||
...(restKg > 0 ? [{ region: '其他', kg: restKg, share: restKg / totalKg }] : []),
|
||||
];
|
||||
|
||||
return { kpi, top5, regions };
|
||||
// 月度趋势(本年内 12 个月,缺失月补 0)
|
||||
const [monthRows] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT DATE_FORMAT(hydrogen_time, '%Y-%m') AS m,
|
||||
ROUND(SUM(hydrogen_quantity), 2) AS kg,
|
||||
ROUND(SUM(cost_expense), 2) AS fee
|
||||
FROM tab_energy_hydrogen_bill
|
||||
WHERE is_deleted = 0
|
||||
AND hydrogen_time >= ?
|
||||
AND YEAR(hydrogen_time) = YEAR(CURDATE())
|
||||
GROUP BY m
|
||||
ORDER BY m`,
|
||||
[HYDROGEN_MIN_DATE],
|
||||
);
|
||||
const monthMap = new Map<string, { kg: number; fee: number }>();
|
||||
for (const r of monthRows) {
|
||||
monthMap.set(r.m as string, { kg: Number(r.kg) || 0, fee: Number(r.fee) || 0 });
|
||||
}
|
||||
const year = new Date().getFullYear();
|
||||
const currentMonth = new Date().getMonth() + 1;
|
||||
const monthly: { month: string; kg: number; fee: number }[] = [];
|
||||
for (let mi = 1; mi <= currentMonth; mi++) {
|
||||
const key = `${year}-${String(mi).padStart(2, '0')}`;
|
||||
const v = monthMap.get(key) || { kg: 0, fee: 0 };
|
||||
monthly.push({ month: key, kg: v.kg, fee: v.fee });
|
||||
}
|
||||
|
||||
return { kpi, top5, regions, monthly };
|
||||
});
|
||||
return c.json(data);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user