charging-cabinet/tasks/007-energy-management.md
2026-07-02 05:38:01 +08:00

82 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 任务007能耗管理
## 目标
实现电表数据统计,柜子/项目维度的能耗分析,趋势图表。
## 后端API
```
GET /api/energy-stats/summary # 总览(今日/本月总能耗、电费估算)
GET /api/energy-stats/cabinets # 柜子能耗排行
GET /api/energy-stats/projects # 项目能耗统计
GET /api/energy-stats/trend # 趋势数据(日/周/月)
GET /api/energy-stats/export # 导出能耗报表(异步)
```
### 响应示例
**总览:**
```json
{
"today_energy": 3750.50,
"month_energy": 85200.00,
"estimated_cost": 68160.00,
"cabinet_count": 128,
"online_count": 125
}
```
**柜子排行:**
```json
[
{"cabinet_id": 1, "abstract_id": "10-00000001", "today_energy": 320.5},
{"cabinet_id": 2, "abstract_id": "10-00000002", "today_energy": 285.0}
]
```
**趋势(日):**
```json
[
{"date": "2026-07-01", "energy": 3750.50, "charge_count": 423},
{"date": "2026-06-30", "energy": 3680.20, "charge_count": 415}
]
```
## 前端页面
### 能耗管理页
**顶部数据卡片:**
```
┌─────────┐ ┌───────── ┌─────────┐ ┌─────────
│今日能耗 │ │本月能耗 │ │电费估算 │ │在线柜子 │
│3,750 kWh│ │85,200 kWh│ │¥68,160 │ │ 125 │
└───────── └─────────┘ └───────── └─────────┘
```
**柜子能耗排行:**
- 表格显示柜子ID、今日能耗、本月能耗
- 支持排序
**项目能耗统计:**
- 表格显示项目名、柜子数、今日能耗、本月能耗
**趋势图:**
- 日/周/月切换
- 折线图显示能耗趋势
- 柱状图显示充电次数
**导出按钮:**
- 异步导出Excel
- 文件名:`能耗统计_2026年7月.xlsx`
## 质量约束
1. 完成代码后执行 `cargo check` + `tsc --noEmit`,零报错零警告
2. 分层拆分单函数≤80行命名语义化完整注释
3. 所有外部IO/网络请求异常捕获禁止裸panic
4. 分支逻辑全覆盖,不遗漏兜底分支
5. 常量抽离不使用废弃API
6. Rust内存安全React函数组件+Hooks