|
@@ -3,14 +3,14 @@ package util
|
|
|
import (
|
|
|
MC "app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
- "fmt"
|
|
|
IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
// 标讯搜索:全文搜索和附件搜索限制
|
|
|
func IsSearchLimit(searchItems []string) bool {
|
|
|
for _, searchItem := range searchItems {
|
|
|
- if searchItem == "detail" || searchItem == "filetext" {
|
|
|
+ if LimitItemsMap[searchItem] {
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
@@ -23,6 +23,12 @@ func LimitSearchInit() {
|
|
|
for i := 0; i < IC.C.LimitSearchText.Count; i++ {
|
|
|
redis.RPUSH("other", IC.SearchLimitKey, 1)
|
|
|
}
|
|
|
+ if limitItems := IC.C.LimitSearchText.LimitItems; len(limitItems) > 0 {
|
|
|
+ LimitItemsMap = map[string]bool{}
|
|
|
+ for _, v := range IC.C.LimitSearchText.LimitItems {
|
|
|
+ LimitItemsMap[v] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -92,3 +98,89 @@ func IsCanLogin(userId string) bool {
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+var (
|
|
|
+ UserIdentMap = map[string]int{
|
|
|
+ "payer": 1,
|
|
|
+ "free": 2,
|
|
|
+ "noLogin": 3,
|
|
|
+ }
|
|
|
+ LimitItemsMap = map[string]bool{
|
|
|
+ "detail": true,
|
|
|
+ "filetext": true,
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+/*
|
|
|
+限制正文、附件查询
|
|
|
+return 1 正常
|
|
|
+return -1 抱歉!由于系统繁忙暂时无法进行搜索,请1分钟后再试!
|
|
|
+return -2 抱歉!由于系统繁忙暂时无法进行搜索,请稍后再试!
|
|
|
+userIdent 未登录用户是;cookie 中存的标识;登录用户是UserId
|
|
|
+*/
|
|
|
+func CheckLimit(userType int, userIdent string, isNew bool) (state int64) {
|
|
|
+ if !IC.C.LimitSearchText.Flag {
|
|
|
+ state = 1
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var limitCount = int(redis.LLEN("other", IC.SearchLimitKey))
|
|
|
+ switch IC.C.LimitSearchText.Count {
|
|
|
+ case -2: //不限制
|
|
|
+ state = 1
|
|
|
+ return
|
|
|
+ case -1:
|
|
|
+ state = -2
|
|
|
+ return
|
|
|
+ default:
|
|
|
+ if limitCount <= 0 {
|
|
|
+ state = -1
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //同一用户 -- 请求频次 在IC.C.LimitSearchText.TimeOut内 不允许多次请求
|
|
|
+ if IC.C.LimitSearchText.TimeOut > 0 {
|
|
|
+ if isNew {
|
|
|
+ if limitCount <= IC.C.LimitSearchText.Count/2 {
|
|
|
+ timeLimit, _ := redis.Exists("other", fmt.Sprintf(IC.C.LimitSearchText.LimitKey, userIdent))
|
|
|
+ if timeLimit {
|
|
|
+ state = -1
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redis.Put("other", fmt.Sprintf(IC.C.LimitSearchText.LimitKey, userIdent), 1, IC.C.LimitSearchText.TimeOut)
|
|
|
+ }
|
|
|
+ //userType 用户标识:1:付费用户;2:免费用户;3:未登录用户;
|
|
|
+ switch userType {
|
|
|
+ case 1:
|
|
|
+ if limitCount > 0 {
|
|
|
+ state = 1
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ state = -2
|
|
|
+ if limitCount > IC.C.LimitSearchText.ForPayer {
|
|
|
+ switch userType {
|
|
|
+ case 2:
|
|
|
+ quota := limitCount * IC.C.LimitSearchText.Percentage / 100
|
|
|
+ if quota > 0 {
|
|
|
+ state = 1
|
|
|
+ } else {
|
|
|
+ state = -1
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ quota := limitCount * IC.C.LimitSearchText.NoLogin / 100
|
|
|
+ if quota > 0 {
|
|
|
+ state = 1
|
|
|
+ } else {
|
|
|
+ state = -1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //两套负载 同一套并发池
|
|
|
+ pollLimit := redis.LPOP("other", IC.SearchLimitKey)
|
|
|
+ if MC.IntAll(pollLimit) <= 0 {
|
|
|
+ state = -2
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|