feat: 补全多云资产与账单同步

- 接入 AWS、华为云和 Azure 资产及账单 API

- 按原始币种隔离统计并修正账号服务器数

- 修复侧栏菜单展开后的滚动行为
This commit is contained in:
Logan.Li committed 2026-07-29 06:15:00 +08:00
1 parent 65e2f09b97
commit 132fe9ba97
25 files changed
+1094 -141

No files matched your search

+13 -8
View File
@@ -37,6 +37,9 @@ func (h *BillingHandler) ListBillings(c *gin.Context) {
if accountID := c.Query("cloud_account_id"); accountID != "" {
query = query.Where("cloud_account_id = ?", accountID)
}
if currency := c.Query("currency"); currency != "" {
query = query.Where("currency = ?", currency)
}
if startDate := c.Query("start_date"); startDate != "" {
query = query.Where("billing_date >= ?", startDate)
}
@@ -167,27 +170,29 @@ func (h *BillingHandler) GetBillingStats(c *gin.Context) {
yesterday := now.AddDate(0, 0, -1).Format("2006-01-02")
monthStart := now.Format("2006-01") + "-01"
yearStart := fmt.Sprintf("%d-01-01", now.Year())
currency := c.DefaultQuery("currency", "CNY")
stats := model.BillingStats{
Currency: currency,
MonthTrend: []model.DailyCost{},
ProviderDist: []model.ProviderCost{},
Alerts: []model.BillingAlert{},
}
// 今日成本
h.db.Model(&model.CloudBilling{}).Where("billing_date = ?", today).
h.db.Model(&model.CloudBilling{}).Where("billing_date = ? AND currency = ?", today, currency).
Select("COALESCE(SUM(cost), 0)").Scan(&stats.TodayCost)
// 昨日成本
h.db.Model(&model.CloudBilling{}).Where("billing_date = ?", yesterday).
h.db.Model(&model.CloudBilling{}).Where("billing_date = ? AND currency = ?", yesterday, currency).
Select("COALESCE(SUM(cost), 0)").Scan(&stats.YesterdayCost)
// 本月成本
h.db.Model(&model.CloudBilling{}).Where("billing_date >= ?", monthStart).
h.db.Model(&model.CloudBilling{}).Where("billing_date >= ? AND currency = ?", monthStart, currency).
Select("COALESCE(SUM(cost), 0)").Scan(&stats.MonthCost)
// 本年成本
h.db.Model(&model.CloudBilling{}).Where("billing_date >= ?", yearStart).
h.db.Model(&model.CloudBilling{}).Where("billing_date >= ? AND currency = ?", yearStart, currency).
Select("COALESCE(SUM(cost), 0)").Scan(&stats.YearCost)
// 近30天趋势
@@ -198,7 +203,7 @@ func (h *BillingHandler) GetBillingStats(c *gin.Context) {
var trends []dayCost
h.db.Model(&model.CloudBilling{}).
Select("billing_date, SUM(cost) as total").
Where("billing_date >= ?", now.AddDate(0, 0, -29).Format("2006-01-02")).
Where("billing_date >= ? AND currency = ?", now.AddDate(0, 0, -29).Format("2006-01-02"), currency).
Group("billing_date").
Order("billing_date ASC").
Scan(&trends)
@@ -215,7 +220,7 @@ func (h *BillingHandler) GetBillingStats(c *gin.Context) {
var provCosts []provCost
h.db.Model(&model.CloudBilling{}).
Select("provider, SUM(cost) as total").
Where("billing_date >= ?", monthStart).
Where("billing_date >= ? AND currency = ?", monthStart, currency).
Group("provider").
Scan(&provCosts)
@@ -258,7 +263,7 @@ func (h *BillingHandler) checkBillingAlerts(stats *model.BillingStats, now time.
if rule.Metric == "daily" {
// 查今日该厂商/账号的成本
q := h.db.Model(&model.CloudBilling{}).Where("billing_date = ?", now.Format("2006-01-02"))
q := h.db.Model(&model.CloudBilling{}).Where("billing_date = ? AND currency = ?", now.Format("2006-01-02"), stats.Currency)
if rule.Provider != "" {
q = q.Where("provider = ?", rule.Provider)
}
@@ -268,7 +273,7 @@ func (h *BillingHandler) checkBillingAlerts(stats *model.BillingStats, now time.
q.Select("COALESCE(SUM(cost), 0)").Scan(&current)
} else {
// monthly - 本月累计
q := h.db.Model(&model.CloudBilling{}).Where("billing_date >= ?", now.Format("2006-01")+"-01")
q := h.db.Model(&model.CloudBilling{}).Where("billing_date >= ? AND currency = ?", now.Format("2006-01")+"-01", stats.Currency)
if rule.Provider != "" {
q = q.Where("provider = ?", rule.Provider)
}