package models import ( "fmt" "github.com/beego/beego/v2/client/orm" "hongze/hongze_api/services/go_redis" "time" ) // GetDefaultChartPermissionCount 获取默认的权限数目 func GetDefaultChartPermissionCount(productId int) (count int, err error) { sql := ` select count(1) COUNT from chart_permission where product_id=?` o := orm.NewOrm() err = o.Raw(sql, productId).QueryRow(&count) return } // GetDefaultChartPermissionCountByCache 获取默认的权限数目(从缓存获取) func GetDefaultChartPermissionCountByCache(productId int) (maxPermissionCount int, err error) { maxPermissionCountKey := fmt.Sprint(`hongze_api:max_permission_count:product_id:`, productId) maxPermissionCount, err = go_redis.RedisInt(maxPermissionCountKey) if err != nil || maxPermissionCount <= 0 { maxPermissionCount, err = GetDefaultChartPermissionCount(productId) if err != nil { return } go_redis.SetNX(maxPermissionCountKey, maxPermissionCount, time.Second*3600) } //ficc需要移除策略的权限 if productId == 1 { maxPermissionCount = maxPermissionCount - 1 } return }