chart_permission.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_api/services/go_redis"
  6. "time"
  7. )
  8. // GetDefaultChartPermissionCount 获取默认的权限数目
  9. func GetDefaultChartPermissionCount(productId int) (count int, err error) {
  10. sql := ` select count(1) COUNT from chart_permission where product_id=?`
  11. o := orm.NewOrm()
  12. err = o.Raw(sql, productId).QueryRow(&count)
  13. return
  14. }
  15. // GetDefaultChartPermissionCountByCache 获取默认的权限数目(从缓存获取)
  16. func GetDefaultChartPermissionCountByCache(productId int) (maxPermissionCount int, err error) {
  17. maxPermissionCountKey := fmt.Sprint(`hongze_api:max_permission_count:product_id:`, productId)
  18. maxPermissionCount, err = go_redis.RedisInt(maxPermissionCountKey)
  19. if err != nil || maxPermissionCount <= 0 {
  20. maxPermissionCount, err = GetDefaultChartPermissionCount(productId)
  21. if err != nil {
  22. return
  23. }
  24. go_redis.SetNX(maxPermissionCountKey, maxPermissionCount, time.Second*3600)
  25. }
  26. //ficc需要移除策略的权限
  27. if productId == 1 {
  28. maxPermissionCount = maxPermissionCount - 1
  29. }
  30. return
  31. }