feat(tenant): 按租户隔离支付退款与商户配置
This commit is contained in:
@@ -5,19 +5,21 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
)
|
||||
|
||||
const dashboardCacheTTL = 5 * time.Minute
|
||||
|
||||
func (r *Repository) dashboardCacheKey(query DashboardQuery) string {
|
||||
return fmt.Sprintf("admin-finance:dashboard:v2:%d:%d", query.StartDate.Unix(), query.EndDate.Unix())
|
||||
func (r *Repository) dashboardCacheKey(ctx context.Context, query DashboardQuery) string {
|
||||
return fmt.Sprintf("admin-finance:dashboard:v3:%d:%d:%d", tenancy.IDFromContext(ctx), query.StartDate.Unix(), query.EndDate.Unix())
|
||||
}
|
||||
|
||||
func (r *Repository) loadDashboardCache(ctx context.Context, query DashboardQuery) *DashboardDTO {
|
||||
if r.redis == nil {
|
||||
return nil
|
||||
}
|
||||
raw, err := r.redis.Get(ctx, r.dashboardCacheKey(query)).Bytes()
|
||||
raw, err := r.redis.Get(ctx, r.dashboardCacheKey(ctx, query)).Bytes()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -37,5 +39,5 @@ func (r *Repository) storeDashboardCache(ctx context.Context, query DashboardQue
|
||||
return
|
||||
}
|
||||
// 缓存不可用时静默降级到实时统计,不能影响财务页面可用性。
|
||||
_ = r.redis.Set(ctx, r.dashboardCacheKey(query), raw, dashboardCacheTTL).Err()
|
||||
_ = r.redis.Set(ctx, r.dashboardCacheKey(ctx, query), raw, dashboardCacheTTL).Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user