feat: add superadmin health center

This commit is contained in:
2026-01-17 09:18:05 +08:00
parent 94a10a3af0
commit 4f2b8ea3ad
14 changed files with 870 additions and 5 deletions

View File

@@ -0,0 +1,75 @@
package dto
// SuperHealthOverviewFilter 超管健康概览查询条件。
type SuperHealthOverviewFilter struct {
// TenantID 租户ID不传代表全平台
TenantID *int64 `query:"tenant_id"`
// StartAt 统计开始时间RFC3339可选默认当前时间往前 7 天)。
StartAt *string `query:"start_at"`
// EndAt 统计结束时间RFC3339可选默认当前时间
EndAt *string `query:"end_at"`
// UploadStuckHours 上传处理超时时长(小时,可选;默认 24 小时)。
UploadStuckHours *int64 `query:"upload_stuck_hours"`
}
// SuperHealthOverviewResponse 超管健康概览响应。
type SuperHealthOverviewResponse struct {
// TenantID 当前统计的租户ID0 代表全平台)。
TenantID int64 `json:"tenant_id"`
// StartAt 统计开始时间RFC3339
StartAt string `json:"start_at"`
// EndAt 统计结束时间RFC3339
EndAt string `json:"end_at"`
// UploadStuckHours 上传处理超时时长(小时)。
UploadStuckHours int64 `json:"upload_stuck_hours"`
// TenantTotal 租户总数。
TenantTotal int64 `json:"tenant_total"`
// TenantWarningCount 健康预警租户数。
TenantWarningCount int64 `json:"tenant_warning_count"`
// TenantRiskCount 健康风险租户数。
TenantRiskCount int64 `json:"tenant_risk_count"`
// OrderTotal 订单总数(统计区间内)。
OrderTotal int64 `json:"order_total"`
// OrderFailed 失败订单数(统计区间内)。
OrderFailed int64 `json:"order_failed"`
// OrderFailedRate 失败率(失败订单数 / 总订单数)。
OrderFailedRate float64 `json:"order_failed_rate"`
// UploadTotal 上传资产总数(统计区间内)。
UploadTotal int64 `json:"upload_total"`
// UploadFailed 上传失败资产数(统计区间内)。
UploadFailed int64 `json:"upload_failed"`
// UploadFailedRate 上传失败率(失败资产数 / 总资产数)。
UploadFailedRate float64 `json:"upload_failed_rate"`
// UploadProcessingStuck 处理超时资产数processing 且超时)。
UploadProcessingStuck int64 `json:"upload_processing_stuck"`
// UploadUploadedStuck 已上传但未进入处理的超时资产数uploaded 且超时)。
UploadUploadedStuck int64 `json:"upload_uploaded_stuck"`
// StorageTotalCount 资产总量(全量)。
StorageTotalCount int64 `json:"storage_total_count"`
// StorageTotalSize 资产总大小(字节,全量)。
StorageTotalSize int64 `json:"storage_total_size"`
// Alerts 健康告警列表。
Alerts []SuperHealthAlertItem `json:"alerts"`
}
// SuperHealthAlertItem 健康告警条目。
type SuperHealthAlertItem struct {
// Level 告警级别warning/risk
Level string `json:"level"`
// Kind 告警类型order_error_rate/upload_error_rate/upload_stuck/tenant_health
Kind string `json:"kind"`
// TenantID 关联租户ID无则为 0
TenantID int64 `json:"tenant_id"`
// TenantCode 关联租户编码。
TenantCode string `json:"tenant_code"`
// TenantName 关联租户名称。
TenantName string `json:"tenant_name"`
// Title 告警标题。
Title string `json:"title"`
// Detail 告警详情说明。
Detail string `json:"detail"`
// Count 关联数量(例如失败数、超时数)。
Count int64 `json:"count"`
// UpdatedAt 告警更新时间RFC3339
UpdatedAt string `json:"updated_at"`
}

View File

@@ -0,0 +1,29 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type healths struct{}
// Health overview
//
// @Router /super/v1/health/overview [get]
// @Summary Health overview
// @Description Platform health overview
// @Tags Health
// @Accept json
// @Produce json
// @Param tenant_id query int false "Tenant ID"
// @Param start_at query string false "Start time"
// @Param end_at query string false "End time"
// @Param upload_stuck_hours query int false "Upload stuck hours"
// @Success 200 {object} dto.SuperHealthOverviewResponse
// @Bind filter query
func (c *healths) Overview(ctx fiber.Ctx, filter *dto.SuperHealthOverviewFilter) (*dto.SuperHealthOverviewResponse, error) {
return services.Super.HealthOverview(ctx, filter)
}

View File

@@ -73,6 +73,13 @@ func Provide(opts ...opt.Option) error {
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*healths, error) {
obj := &healths{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*notifications, error) {
obj := &notifications{}
@@ -111,6 +118,7 @@ func Provide(opts ...opt.Option) error {
creatorApplications *creatorApplications,
creators *creators,
finance *finance,
healths *healths,
middlewares *middlewares.Middlewares,
notifications *notifications,
orders *orders,
@@ -131,6 +139,7 @@ func Provide(opts ...opt.Option) error {
creatorApplications: creatorApplications,
creators: creators,
finance: finance,
healths: healths,
middlewares: middlewares,
notifications: notifications,
orders: orders,

View File

@@ -34,6 +34,7 @@ type Routes struct {
creatorApplications *creatorApplications
creators *creators
finance *finance
healths *healths
notifications *notifications
orders *orders
payoutAccounts *payoutAccounts
@@ -243,6 +244,12 @@ func (r *Routes) Register(router fiber.Router) {
r.finance.ListLedgers,
Query[dto.SuperLedgerListFilter]("filter"),
))
// Register routes for controller: healths
r.log.Debugf("Registering route: Get /super/v1/health/overview -> healths.Overview")
router.Get("/super/v1/health/overview"[len(r.Path()):], DataFunc1(
r.healths.Overview,
Query[dto.SuperHealthOverviewFilter]("filter"),
))
// Register routes for controller: notifications
r.log.Debugf("Registering route: Get /super/v1/notifications -> notifications.List")
router.Get("/super/v1/notifications"[len(r.Path()):], DataFunc1(