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

+42 -42
View File
@@ -2,24 +2,23 @@ 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"`
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 {
@@ -28,17 +27,17 @@ func (CloudBilling) TableName() string {
// 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"`
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 {
@@ -47,19 +46,20 @@ func (BillingAlertRule) TableName() string {
// 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"`
Alerts []BillingAlert `json:"alerts"`
Currency string `json:"currency"`
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"`
Alerts []BillingAlert `json:"alerts"`
}
// DailyCost 每日成本
type DailyCost struct {
Date string `json:"date"`
Cost float64 `json:"cost"`
Date string `json:"date"`
Cost float64 `json:"cost"`
}
// ProviderCost 厂商成本分布
@@ -82,15 +82,15 @@ type BillingAlert struct {
// 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"`
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"`
Currency string `json:"currency"`
Service string `json:"service"`
Region string `json:"region"`
Description string `json:"description"`
}
// CreateBillingAlertRequest 创建预警规则请求
+48 -46
View File
@@ -6,40 +6,41 @@ import (
// Server 服务器模型
type Server struct {
ID uint `gorm:"primarykey" json:"id"`
Hostname string `gorm:"size:128;not null" json:"hostname"`
IP string `gorm:"size:64;not null" json:"ip"`
PublicIP string `gorm:"size:64" json:"public_ip"`
Port int `gorm:"default:22" json:"port"`
Username string `gorm:"size:64;default:root" json:"username"`
Password string `gorm:"size:255" json:"-"`
SSHKey string `gorm:"type:text" json:"-"`
AuthType string `gorm:"size:32;default:password" json:"auth_type"` // password, key
OSType string `gorm:"size:32;default:linux" json:"os_type"` // 操作系统类型:linux/windows // Logan.Li
Protocol string `gorm:"size:32;default:ssh" json:"protocol"` // 远程协议:ssh/rdp // Logan.Li
RDPPort int `gorm:"default:3389" json:"rdp_port"` // Windows RDP 端口 // Logan.Li
OS string `gorm:"size:64" json:"os"`
Kernel string `gorm:"size:64" json:"kernel"`
OSVersion string `gorm:"size:64" json:"os_version"`
Arch string `gorm:"size:32" json:"arch"`
CPU int `json:"cpu"`
Memory int64 `json:"memory"` // MB
Disk int64 `json:"disk"` // GB
Status string `gorm:"size:32;default:stopped" json:"status"` // running, stopped, maintenance, error
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
DiskUsage float64 `json:"disk_usage"`
Uptime int64 `json:"uptime"` // seconds
AgentVersion string `gorm:"size:32" json:"agent_version"`
AgentStatus string `gorm:"size:32;default:offline" json:"agent_status"` // online, offline
HasAuth bool `gorm:"-" json:"has_auth"` // 是否有认证凭据(密码或SSH密钥) — 不存DB,handler 计算后返回 // Logan.Li
RegionID *uint `json:"region_id"`
CloudID *uint `json:"cloud_id"`
Tags string `gorm:"type:text" json:"tags"` // JSON
Description string `gorm:"size:500" json:"description"`
LastCheckAt *time.Time `json:"last_check_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID uint `gorm:"primarykey" json:"id"`
Hostname string `gorm:"size:128;not null" json:"hostname"`
IP string `gorm:"size:64;not null" json:"ip"`
PublicIP string `gorm:"size:64" json:"public_ip"`
Port int `gorm:"default:22" json:"port"`
Username string `gorm:"size:64;default:root" json:"username"`
Password string `gorm:"size:255" json:"-"`
SSHKey string `gorm:"type:text" json:"-"`
AuthType string `gorm:"size:32;default:password" json:"auth_type"` // password, key
OSType string `gorm:"size:32;default:linux" json:"os_type"` // 操作系统类型:linux/windows // Logan.Li
Protocol string `gorm:"size:32;default:ssh" json:"protocol"` // 远程协议:ssh/rdp // Logan.Li
RDPPort int `gorm:"default:3389" json:"rdp_port"` // Windows RDP 端口 // Logan.Li
OS string `gorm:"size:64" json:"os"`
Kernel string `gorm:"size:64" json:"kernel"`
OSVersion string `gorm:"size:64" json:"os_version"`
Arch string `gorm:"size:32" json:"arch"`
CPU int `json:"cpu"`
Memory int64 `json:"memory"` // MB
Disk int64 `json:"disk"` // GB
Status string `gorm:"size:32;default:stopped" json:"status"` // running, stopped, maintenance, error
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
DiskUsage float64 `json:"disk_usage"`
Uptime int64 `json:"uptime"` // seconds
AgentVersion string `gorm:"size:32" json:"agent_version"`
AgentStatus string `gorm:"size:32;default:offline" json:"agent_status"` // online, offline
HasAuth bool `gorm:"-" json:"has_auth"` // 是否有认证凭据(密码或SSH密钥) — 不存DB,handler 计算后返回 // Logan.Li
RegionID *uint `json:"region_id"`
CloudID *uint `json:"cloud_id"`
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"` // 关联导入来源云账号,用于准确统计。 // Logan.Li
Tags string `gorm:"type:text" json:"tags"` // JSON
Description string `gorm:"size:500" json:"description"`
LastCheckAt *time.Time `json:"last_check_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联
Region *Region `json:"region,omitempty"`
@@ -71,18 +72,19 @@ func (Cloud) TableName() string {
// CloudAccount 云账号模型
type CloudAccount struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Provider string `gorm:"size:64;not null" json:"provider"` // aws, aliyun, tencent, huawei, azure
AccessKey string `gorm:"size:255;not null" json:"-"`
SecretKey string `gorm:"size:255;not null" json:"-"`
Status string `gorm:"size:32;default:active" json:"status"` // active, inactive, error
RegionCount int `gorm:"default:0" json:"region_count"`
ServerCount int `gorm:"default:0" json:"server_count"`
MonthlyCost float64 `gorm:"default:0" json:"monthly_cost"` // 月费用(元),驱动仪表盘成本统计
LastSyncAt *time.Time `json:"last_sync_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Provider string `gorm:"size:64;not null" json:"provider"` // aws, aliyun, tencent, huawei, azure
AccessKey string `gorm:"size:255;not null" json:"-"`
SecretKey string `gorm:"size:255;not null" json:"-"`
Status string `gorm:"size:32;default:active" json:"status"` // active, inactive, error
RegionCount int `gorm:"default:0" json:"region_count"`
ServerCount int `gorm:"default:0" json:"server_count"`
MonthlyCost float64 `gorm:"default:0" json:"monthly_cost"` // 月费用(元),驱动仪表盘成本统计
BillingCurrency string `gorm:"size:8;default:CNY" json:"billing_currency"` // 账单原始币种。 // Logan.Li
LastSyncAt *time.Time `json:"last_sync_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 表名