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

+27 -22
View File
@@ -227,10 +227,12 @@ func (h *CloudSyncHandler) ImportInstances(c *gin.Context) {
ip = inst.InstanceID
}
// 检查是否已存在(按 IP 或 hostname)
var count int64
h.db.Model(&model.Server{}).Where("ip = ? OR hostname = ?", ip, inst.Hostname).Count(&count)
if count > 0 {
// 重复资产补齐来源账号关联,保证服务器数统计准确。 // Logan.Li
var existing model.Server
if err := h.db.Where("ip = ? OR hostname = ?", ip, inst.Hostname).Take(&existing).Error; err == nil {
if existing.CloudAccountID == nil {
h.db.Model(&existing).Update("cloud_account_id", account.ID)
}
skipped++
continue
}
@@ -275,22 +277,23 @@ func (h *CloudSyncHandler) ImportInstances(c *gin.Context) {
// 注意:servers 表的 cloud_id 外键引用的是 clouds 表(非 cloud_accounts),
// region_id 外键引用 regions 表。未找到关联时设为 NULL 避免外键约束失败。
server := model.Server{
Hostname: hostname,
IP: ipAddr,
PublicIP: inst.PublicIP,
Port: defaultPort,
Username: username,
AuthType: "password",
OSType: osType,
Protocol: protocol,
RDPPort: 3389,
OS: osName,
CPU: inst.CPU,
Memory: int64(inst.Memory),
Status: status,
RegionID: regionID, // nil = NULL
Description: "从 " + account.Provider + " 导入 (" + inst.InstanceID + ")",
AgentStatus: "offline",
Hostname: hostname,
IP: ipAddr,
PublicIP: inst.PublicIP,
Port: defaultPort,
Username: username,
AuthType: "password",
OSType: osType,
Protocol: protocol,
RDPPort: 3389,
OS: osName,
CPU: inst.CPU,
Memory: int64(inst.Memory),
Status: status,
RegionID: regionID, // nil = NULL
CloudAccountID: &account.ID,
Description: "从 " + account.Provider + " 导入 (" + inst.InstanceID + ")",
AgentStatus: "offline",
}
if protocol == "rdp" && hasRDPCred {
applyCredential(rdpCred, rdpPlain, &server)
@@ -305,8 +308,10 @@ func (h *CloudSyncHandler) ImportInstances(c *gin.Context) {
}
}
// 更新账号的 server_count
h.db.Model(&account).UpdateColumn("server_count", imported)
// 保存该账号当前已关联的资产总数,而不是本次新增数。 // Logan.Li
var serverCount int64
h.db.Model(&model.Server{}).Where("cloud_account_id = ?", account.ID).Count(&serverCount)
h.db.Model(&account).UpdateColumn("server_count", serverCount)
c.JSON(http.StatusOK, model.Response{
Code: 200,