feat: 精确耗电计算(接入充值记录接口)
- 新增 queryISIMSRoomBuyRecord 充值记录获取 + 10分钟缓存 - 日耗电 = 剩余变化 + 当天充值电量(电价0.535元/度) - 月度汇总增加充值次数/电量/金额 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
32
go/main.go
32
go/main.go
@@ -100,21 +100,35 @@ func apiHistory(w http.ResponseWriter, r *http.Request) {
|
||||
month := q.Get("month") // YYYY-MM,空=全部
|
||||
|
||||
records := getRecords()
|
||||
allDaily := buildDailyStats(records, "") // 全量(用于可用月份列表)
|
||||
monthDaily := buildDailyStats(records, month)
|
||||
|
||||
// 获取充值记录(用于精确耗电计算)
|
||||
rechargeMap := map[string]float64{}
|
||||
var buyRecords []buyRecord
|
||||
if c, err := loadCache(); err == nil {
|
||||
if recs, err := getBuyRecordsCached(c.AppShiro, &c.Room); err == nil {
|
||||
rechargeMap = rechargeKwhByDate(recs)
|
||||
buyRecords = recs
|
||||
} else {
|
||||
fmt.Println("[充值] 获取充值记录失败:", err)
|
||||
}
|
||||
}
|
||||
|
||||
allDaily := buildDailyStats(records, "", rechargeMap) // 全量(用于可用月份列表)
|
||||
monthDaily := buildDailyStats(records, month, rechargeMap)
|
||||
|
||||
// 可用月份列表(降序)
|
||||
months := availableMonths(records)
|
||||
|
||||
summary := buildMonthSummary(monthDaily, month)
|
||||
writeJSON(w, map[string]any{
|
||||
"ok": true,
|
||||
"month": month,
|
||||
"months": months,
|
||||
"records": monthDaily, // 升序每日统计(含 usage)
|
||||
"daily": monthDaily,
|
||||
"summary": summary,
|
||||
"all_count": len(allDaily),
|
||||
"ok": true,
|
||||
"month": month,
|
||||
"months": months,
|
||||
"records": monthDaily, // 升序每日统计(含 usage)
|
||||
"daily": monthDaily,
|
||||
"summary": summary,
|
||||
"recharges": buyRecords, // 充值记录明细
|
||||
"all_count": len(allDaily),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user