diff --git a/backend/app/http/super/v1/dto/super.go b/backend/app/http/super/v1/dto/super.go index 0eeb025..555af0f 100644 --- a/backend/app/http/super/v1/dto/super.go +++ b/backend/app/http/super/v1/dto/super.go @@ -231,6 +231,8 @@ type AdminContentItem struct { Price *v1_dto.ContentPrice `json:"price"` StatusDescription string `json:"status_description"` VisibilityDescription string `json:"visibility_description"` + // Tenant 内容所属租户信息,用于超管列表展示与跳转。 + Tenant *SuperContentTenantLite `json:"tenant"` } type AdminContentOwnerLite struct { diff --git a/backend/app/services/super.go b/backend/app/services/super.go index 99bb2e2..c8f5442 100644 --- a/backend/app/services/super.go +++ b/backend/app/services/super.go @@ -294,9 +294,14 @@ func (s *super) ListContents(ctx context.Context, filter *super_dto.SuperContent return nil, err } + tenantMap, err := s.contentTenantMap(ctx, list) + if err != nil { + return nil, err + } + data := make([]super_dto.AdminContentItem, 0, len(list)) for _, c := range list { - data = append(data, s.toSuperContentItem(c, priceMap[c.ID])) + data = append(data, s.toSuperContentItem(c, priceMap[c.ID], tenantMap[c.TenantID])) } return &requests.Pager{ Pagination: filter.Pagination, @@ -635,13 +640,42 @@ func (s *super) contentPriceMap(ctx context.Context, list []*models.Content) (ma return priceMap, nil } -func (s *super) toSuperContentItem(item *models.Content, price *models.ContentPrice) super_dto.AdminContentItem { +func (s *super) contentTenantMap(ctx context.Context, list []*models.Content) (map[int64]*models.Tenant, error) { + if len(list) == 0 { + return map[int64]*models.Tenant{}, nil + } + + ids := make([]int64, 0, len(list)) + seen := make(map[int64]struct{}, len(list)) + for _, item := range list { + if _, ok := seen[item.TenantID]; ok { + continue + } + seen[item.TenantID] = struct{}{} + ids = append(ids, item.TenantID) + } + + tbl, q := models.TenantQuery.QueryContext(ctx) + tenants, err := q.Where(tbl.ID.In(ids...)).Find() + if err != nil { + return nil, errorx.ErrDatabaseError.WithCause(err) + } + + tenantMap := make(map[int64]*models.Tenant, len(tenants)) + for _, tenant := range tenants { + tenantMap[tenant.ID] = tenant + } + return tenantMap, nil +} + +func (s *super) toSuperContentItem(item *models.Content, price *models.ContentPrice, tenant *models.Tenant) super_dto.AdminContentItem { return super_dto.AdminContentItem{ Content: s.toSuperContentDTO(item, price), Owner: s.toSuperContentOwner(item.Author), Price: s.toSuperContentPrice(price), StatusDescription: item.Status.Description(), VisibilityDescription: item.Visibility.Description(), + Tenant: s.toSuperContentTenant(tenant), } } @@ -657,6 +691,17 @@ func (s *super) toSuperContentOwner(author *models.User) *super_dto.AdminContent } } +func (s *super) toSuperContentTenant(tenant *models.Tenant) *super_dto.SuperContentTenantLite { + if tenant == nil { + return nil + } + return &super_dto.SuperContentTenantLite{ + ID: tenant.ID, + Code: tenant.Code, + Name: tenant.Name, + } +} + func (s *super) toSuperContentDTO(item *models.Content, price *models.ContentPrice) *v1_dto.ContentItem { dto := &v1_dto.ContentItem{ ID: item.ID,