chore: 统一本地服务器与远程仓库源码

- 合并 main 与 master 历史并以服务器结构为基线
- 保留迁移、数据保留、AWS 账单与部署安全能力
- 建立 SDD 规格和 CI 验证闭环
This commit is contained in:
Logan.Li committed 2026-08-05 20:03:25 +08:00
commit fd60361d93
460 files changed
+37492 -23871

No files matched your search

+11 -24
View File
@@ -3,6 +3,7 @@ package billingsync
import (
"fmt"
"strings"
"time"
"ezops/cloud"
@@ -23,16 +24,7 @@ type Result struct {
// Yesterday 昨日日期 YYYY-MM-DD
func Yesterday() string {
return billingYesterdayAt(time.Now())
}
// billingYesterdayAt 按平台业务时区计算昨日,避免服务器 UTC 时区造成日期偏差。 // Logan.Li
func billingYesterdayAt(now time.Time) string {
location, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
location = time.FixedZone("CST", 8*60*60)
}
return now.In(location).AddDate(0, 0, -1).Format("2006-01-02")
return time.Now().AddDate(0, 0, -1).Format("2006-01-02")
}
// SyncDate 同步指定日期账单(全部或单个活跃云账号)
@@ -47,7 +39,7 @@ func SyncDate(db *gorm.DB, billingDate string, accountID *uint) Result {
if accountID != nil {
q = q.Where("id = ?", *accountID)
} else {
// 批量同步只选择已接入账单 API 的厂商,避免无效失败。 // Logan.Li
// 批量同步仅处理已接入账单 API 的厂商,避免不支持厂商造成无效失败。 // Logan.Li
q = q.Where("provider IN ?", cloud.SupportedBillingProviders)
}
q.Find(&accounts)
@@ -95,15 +87,8 @@ 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 = ?",
@@ -125,6 +110,7 @@ func syncAccount(db *gorm.DB, account model.CloudAccount, billingDate string) (c
if row.Currency == "" {
row.Currency = "CNY"
}
row.Currency = strings.ToUpper(row.Currency)
if db.Create(&row).Error == nil {
created++
} else {
@@ -137,9 +123,13 @@ func syncAccount(db *gorm.DB, account model.CloudAccount, billingDate string) (c
continue
}
currency := strings.ToUpper(rec.Currency)
if currency == "" {
currency = "CNY"
}
if db.Model(&existing).Updates(map[string]interface{}{
"cost": rec.Cost,
"currency": rec.Currency,
"currency": currency,
"description": rec.Description,
"account_name": accountName,
}).Error == nil {
@@ -152,12 +142,9 @@ 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 >= ? AND currency = ?", accountID, monthStart, billingCurrency).
Where("cloud_account_id = ? AND billing_date >= ?", accountID, monthStart).
Select("COALESCE(SUM(cost), 0)").Scan(&monthCost)
db.Model(&account).Updates(map[string]interface{}{
"monthly_cost": monthCost,
"billing_currency": billingCurrency,
})
db.Model(&account).Update("monthly_cost", monthCost)
return created, updated, skipped, nil
}