|
@@ -2,6 +2,7 @@ package chart
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"hongze/hongze_yb/controller/response"
|
|
|
"hongze/hongze_yb/global"
|
|
@@ -358,16 +359,20 @@ func RefreshChartInfo(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 刷新频率限制
|
|
|
- //userInfo := user.GetInfoByClaims(c)
|
|
|
- //cacheKey := utils.HZ_CHART_LIB_DETAIL + "YB_REFRESH_LIMIT_" + reqChartInfoId + "_" + strconv.Itoa(int(userInfo.UserID))
|
|
|
- //countUserRefresh, _ := global.Redis.Get(context.TODO(), cacheKey).Int()
|
|
|
- //if countUserRefresh > 2 {
|
|
|
- // response.Ok("刷新成功", c)
|
|
|
- // return
|
|
|
- //}
|
|
|
- //countUserRefresh += 1
|
|
|
- //_ = global.Redis.SetEX(context.TODO(), cacheKey, 1, 1 * time.Hour)
|
|
|
+ // 刷新频率限制-每个用户/图/天/2次
|
|
|
+ userInfo := user.GetInfoByClaims(c)
|
|
|
+ cacheKey := utils.HZ_CHART_LIB_DETAIL + "YB_REFRESH_LIMIT_" + strconv.Itoa(chartInfoId) + "_" + strconv.Itoa(int(userInfo.UserID))
|
|
|
+ fmt.Println("refreshCacheKey:", cacheKey)
|
|
|
+ countUserRefresh, _ := global.Redis.Get(context.TODO(), cacheKey).Int()
|
|
|
+ if countUserRefresh >= 2 {
|
|
|
+ response.Ok("目前已是最新数据", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ countUserRefresh += 1
|
|
|
+ now := time.Now()
|
|
|
+ today := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
|
|
|
+ sub := today.Sub(now)
|
|
|
+ _ = global.Redis.SetEX(context.TODO(), cacheKey, countUserRefresh, sub)
|
|
|
|
|
|
// 图表信息校验
|
|
|
chartInfo, err := chartInfoModel.GetChartInfoById(chartInfoId)
|