Browse Source

fix:修复报告详情权限不匹配问题,以前写死ficc最大权限数量15个,现在是从表中获取

Roc 3 years ago
parent
commit
cc93ac3613
3 changed files with 38 additions and 17 deletions
  1. 5 15
      controllers/report.go
  2. 9 1
      controllers/user.go
  3. 24 1
      models/chart_permission.go

+ 5 - 15
controllers/report.go

@@ -2,7 +2,6 @@ package controllers
 
 import (
 	"encoding/json"
-	"fmt"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
 	"hongze/hongze_api/utils"
@@ -77,20 +76,11 @@ func (this *ReportController) Detail() {
 		productId = 1
 	}
 
-	maxPermissionCountKey := fmt.Sprint(`hongze_api:max_permission_count:product_id:`, productId)
-	maxPermissionCount, err = utils.Rc.RedisInt(maxPermissionCountKey)
-	if err != nil || maxPermissionCount <= 0 {
-		maxPermissionCount, err = models.GetDefaultChartPermissionCount(productId)
-		if err != nil {
-			br.Msg = "获取报告详情失败"
-			br.ErrMsg = "获取产品默认最大权限数量失败,Err:" + err.Error()
-			return
-		}
-		utils.Rc.SetNX(maxPermissionCountKey, maxPermissionCount, time.Second*3600)
-	}
-	//ficc需要移除策略的权限
-	if productId == 1 {
-		maxPermissionCount = maxPermissionCount - 1
+	maxPermissionCount, err = models.GetDefaultChartPermissionCountByCache(productId)
+	if err != nil {
+		br.Msg = "获取报告详情失败"
+		br.ErrMsg = "获取产品默认最大权限数量失败,Err:" + err.Error()
+		return
 	}
 
 	utils.FileLog.Info("report.detail %d,%d", user.CompanyId, productId)

+ 9 - 1
controllers/user.go

@@ -605,7 +605,15 @@ func (this *UserController) SmallLimit() {
 		return
 	}
 	resp := new(models.SmallLimitResp)
-	if maxCount >= 15 {
+
+	maxPermissionCount, err := models.GetDefaultChartPermissionCountByCache(1)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取产品默认最大权限数量失败,Err:" + err.Error()
+		return
+	}
+
+	if maxCount >= maxPermissionCount {
 		resp.IsMaxPermission = 1
 	} else {
 		resp.IsMaxPermission = 0

+ 24 - 1
models/chart_permission.go

@@ -1,6 +1,11 @@
 package models
 
-import "github.com/rdlucklib/rdluck_tools/orm"
+import (
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/orm"
+	"hongze/hongze_api/utils"
+	"time"
+)
 
 // GetDefaultChartPermissionCount 获取默认的权限数目
 func GetDefaultChartPermissionCount(productId int) (count int, err error) {
@@ -9,3 +14,21 @@ func GetDefaultChartPermissionCount(productId int) (count int, err error) {
 	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 = utils.Rc.RedisInt(maxPermissionCountKey)
+	if err != nil || maxPermissionCount <= 0 {
+		maxPermissionCount, err = GetDefaultChartPermissionCount(productId)
+		if err != nil {
+			return
+		}
+		utils.Rc.SetNX(maxPermissionCountKey, maxPermissionCount, time.Second*3600)
+	}
+	//ficc需要移除策略的权限
+	if productId == 1 {
+		maxPermissionCount = maxPermissionCount - 1
+	}
+	return
+}