Files
aiops/backend/controller/billing_sync.go
T
LoganandClaude 76ec9387f0 feat(rdp): 新增 RDP 远程桌面/SMB/账单同步能力 + 清理编译产物
主要变更:
- RDP 远程桌面:新增 backend/pkg/rdp(RDP 引擎 + credssp/display/rle/trace)、
  backend/controller/rdp*(连接/凭证/文件/会话/实时)、frontend RDP 组件与 API
- Windows SMB 文件传输:backend/pkg/winsmb
- 云账单同步:backend/pkg/billingsync + billing_sync/aliyun_billing,前端账单详情
- Agent CLI Kubernetes 工具:kubernetes_action/get、pod_execute/logs
- 服务器导入助手:server_import_helpers、ImportCredentialSettings
- 国际化与组件重构(cloud/deploy/monitor/server/system 等多模块)
- 清理编译产物二进制:移除 backend/server、backend/agent/bin/aiops-agent-*
- .gitignore:新增 backend/agent/ 与 .cache/(避免 334MB go-build 缓存误入库)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-04 01:50:36 +08:00

85 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package controller
import (
"fmt"
"net/http"
"strconv"
"ezops/model"
"ezops/pkg/billingsync"
"github.com/gin-gonic/gin"
)
// syncBillingRequest 同步账单请求(可选指定账号) // Logan.Li
type syncBillingRequest struct {
AccountID *uint `json:"account_id"`
Date string `json:"date"` // YYYY-MM-DD,默认昨日
}
// SyncYesterdayBillings 从云账号 AK 同步指定日期(默认昨日)账单 // Logan.Li
// POST /cloud-billings/sync
func (h *BillingHandler) SyncYesterdayBillings(c *gin.Context) {
var req syncBillingRequest
_ = c.ShouldBindJSON(&req)
billingDate := req.Date
if billingDate == "" {
billingDate = billingsync.Yesterday()
}
if len(billingDate) != 10 {
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "date 格式应为 YYYY-MM-DD"})
return
}
result := billingsync.SyncDate(h.db, billingDate, req.AccountID)
if result.Accounts == 0 {
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "没有可同步的活跃云账号,请先在云账号管理中添加 AK"})
return
}
msg := fmt.Sprintf("同步完成:新增 %d 条,更新 %d 条", result.Created, result.Updated)
if len(result.Errors) > 0 {
msg += fmt.Sprintf(",%d 个账号失败", len(result.Errors))
}
c.JSON(http.StatusOK, model.Response{
Code: 200,
Message: msg,
Data: result,
})
}
// SyncAccountBilling 同步单个云账号账单
// POST /cloud-accounts/:id/sync-billing
func (h *BillingHandler) SyncAccountBilling(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
if id <= 0 {
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "无效账号 ID"})
return
}
var req struct {
Date string `json:"date"`
}
_ = c.ShouldBindJSON(&req)
billingDate := req.Date
if billingDate == "" {
billingDate = billingsync.Yesterday()
}
uid := uint(id)
result := billingsync.SyncDate(h.db, billingDate, &uid)
if result.Accounts == 0 {
c.JSON(http.StatusNotFound, model.Response{Code: 404, Message: "云账号不存在或未激活"})
return
}
msg := fmt.Sprintf("同步完成:新增 %d 条,更新 %d 条", result.Created, result.Updated)
if len(result.Errors) > 0 {
msg = "同步失败: " + result.Errors[0]
}
c.JSON(http.StatusOK, model.Response{Code: 200, Message: msg, Data: result})
}