feat: 补全多云资产与账单同步
- 接入 AWS、华为云和 Azure 资产及账单 API - 按原始币种隔离统计并修正账号服务器数 - 修复侧栏菜单展开后的滚动行为
This commit is contained in:
1 parent
65e2f09b97
commit
132fe9ba97
25 files changed
+1094
-141
No files matched your search
@@ -95,8 +95,15 @@ func syncAccount(db *gorm.DB, account model.CloudAccount, billingDate string) (c
|
||||
|
||||
accountID := account.ID
|
||||
accountName := account.Name
|
||||
billingCurrency := records[0].Currency
|
||||
if billingCurrency == "" {
|
||||
billingCurrency = "CNY"
|
||||
}
|
||||
|
||||
for _, rec := range records {
|
||||
if rec.Currency == "" {
|
||||
rec.Currency = billingCurrency
|
||||
}
|
||||
var existing model.CloudBilling
|
||||
findErr := db.Where(
|
||||
"cloud_account_id = ? AND billing_date = ? AND provider = ? AND service = ? AND region = ?",
|
||||
@@ -145,9 +152,12 @@ func syncAccount(db *gorm.DB, account model.CloudAccount, billingDate string) (c
|
||||
monthStart := billingDate[:7] + "-01"
|
||||
var monthCost float64
|
||||
db.Model(&model.CloudBilling{}).
|
||||
Where("cloud_account_id = ? AND billing_date >= ?", accountID, monthStart).
|
||||
Where("cloud_account_id = ? AND billing_date >= ? AND currency = ?", accountID, monthStart, billingCurrency).
|
||||
Select("COALESCE(SUM(cost), 0)").Scan(&monthCost)
|
||||
db.Model(&account).Update("monthly_cost", monthCost)
|
||||
db.Model(&account).Updates(map[string]interface{}{
|
||||
"monthly_cost": monthCost,
|
||||
"billing_currency": billingCurrency,
|
||||
})
|
||||
|
||||
return created, updated, skipped, nil
|
||||
}
|
||||
Reference in new issue
Block a user