136 lines
5.2 KiB
Go
136 lines
5.2 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// CloudBilling 云账单模型 - 每日成本记录
|
|
type CloudBilling struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"`
|
|
AccountName string `gorm:"size:128" json:"account_name"`
|
|
Provider string `gorm:"size:64;index" json:"provider"` // aliyun, tencent, aws, huawei, azure
|
|
BillingDate string `gorm:"size:10;index;not null" json:"billing_date"` // YYYY-MM-DD
|
|
Cost float64 `gorm:"type:decimal(12,2);default:0" json:"cost"` // 费用(元)
|
|
Currency string `gorm:"size:8;default:CNY" json:"currency"` // CNY, USD
|
|
Service string `gorm:"size:128" json:"service"` // ECS, RDS, OSS, CDN 等
|
|
Region string `gorm:"size:64" json:"region"`
|
|
Tags string `gorm:"type:text" json:"tags"` // JSON
|
|
Description string `gorm:"size:500" json:"description"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (CloudBilling) TableName() string {
|
|
return "asset_cloud_billing_records"
|
|
}
|
|
|
|
// BillingSettings 保存轻量云账单换算设置。 // Logan.Li
|
|
type BillingSettings struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
USDCNYRate float64 `gorm:"type:decimal(12,6);default:7.2" json:"usd_cny_rate"`
|
|
UpdatedBy string `gorm:"size:128" json:"updated_by"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 指定云账单设置表名。 // Logan.Li
|
|
func (BillingSettings) TableName() string { return "asset_cloud_billing_settings" }
|
|
|
|
// BillingAlertRule 账单预警规则
|
|
type BillingAlertRule struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:128;not null" json:"name"`
|
|
Provider string `gorm:"size:64" json:"provider"` // 空=所有云厂商
|
|
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"` // 空=所有账号
|
|
Metric string `gorm:"size:32;default:daily" json:"metric"` // daily, monthly
|
|
Threshold float64 `gorm:"type:decimal(12,2)" json:"threshold"` // 阈值(元)
|
|
Operator string `gorm:"size:8;default:>" json:"operator"` // >, >=, <, <=
|
|
Enabled bool `gorm:"default:true" json:"enabled"`
|
|
LastTriggered *time.Time `json:"last_triggered"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (BillingAlertRule) TableName() string {
|
|
return "asset_cloud_billing_alert_rules"
|
|
}
|
|
|
|
// BillingStats 账单统计
|
|
type BillingStats struct {
|
|
TodayCost float64 `json:"today_cost"`
|
|
MonthCost float64 `json:"month_cost"`
|
|
YearCost float64 `json:"year_cost"`
|
|
YesterdayCost float64 `json:"yesterday_cost"`
|
|
MonthTrend []DailyCost `json:"month_trend"`
|
|
ProviderDist []ProviderCost `json:"provider_dist"`
|
|
ProviderTrend []ProviderDailyCost `json:"provider_trend"`
|
|
TopServices []ServiceCost `json:"top_services"`
|
|
Alerts []BillingAlert `json:"alerts"`
|
|
Currency string `json:"currency"`
|
|
ExchangeRates map[string]float64 `json:"exchange_rates"`
|
|
RateSource string `json:"rate_source"`
|
|
DataThrough string `json:"data_through"`
|
|
}
|
|
|
|
// DailyCost 每日成本
|
|
type DailyCost struct {
|
|
Date string `json:"date"`
|
|
Cost float64 `json:"cost"`
|
|
}
|
|
|
|
// ProviderCost 厂商成本分布
|
|
type ProviderCost struct {
|
|
Provider string `json:"provider"`
|
|
Cost float64 `json:"cost"`
|
|
Percent float64 `json:"percent"`
|
|
}
|
|
|
|
// ProviderDailyCost 表示指定云厂商按报告币种折算后的日费用。 // Logan.Li
|
|
type ProviderDailyCost struct {
|
|
Provider string `json:"provider"`
|
|
Date string `json:"date"`
|
|
Cost float64 `json:"cost"`
|
|
}
|
|
|
|
// ServiceCost 表示本月服务费用排行。 // Logan.Li
|
|
type ServiceCost struct {
|
|
Service string `json:"service"`
|
|
Cost float64 `json:"cost"`
|
|
}
|
|
|
|
// BillingAlert 账单预警
|
|
type BillingAlert struct {
|
|
RuleID uint `json:"rule_id"`
|
|
RuleName string `json:"rule_name"`
|
|
Provider string `json:"provider"`
|
|
Current float64 `json:"current"`
|
|
Threshold float64 `json:"threshold"`
|
|
Metric string `json:"metric"`
|
|
Operator string `json:"operator"`
|
|
}
|
|
|
|
// CreateBillingRequest 创建账单记录请求
|
|
type CreateBillingRequest struct {
|
|
CloudAccountID *uint `json:"cloud_account_id"`
|
|
AccountName string `json:"account_name"`
|
|
Provider string `json:"provider" binding:"required"`
|
|
BillingDate string `json:"billing_date" binding:"required"`
|
|
Cost float64 `json:"cost" binding:"required"`
|
|
Currency string `json:"currency"`
|
|
Service string `json:"service"`
|
|
Region string `json:"region"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
// CreateBillingAlertRequest 创建预警规则请求
|
|
type CreateBillingAlertRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Provider string `json:"provider"`
|
|
CloudAccountID *uint `json:"cloud_account_id"`
|
|
Metric string `json:"metric"`
|
|
Threshold float64 `json:"threshold" binding:"required"`
|
|
Operator string `json:"operator"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|