|
@@ -9,6 +9,7 @@ import (
|
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/repository"
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
|
"github.com/spf13/viper"
|
|
|
+ "go.uber.org/zap"
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
"gorm.io/gorm"
|
|
|
"strconv"
|
|
@@ -261,21 +262,32 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
|
}
|
|
|
|
|
|
// 获取套餐ID
|
|
|
- maxProtection := strings.Split(require.ConfigMaxProtection, "G")
|
|
|
- maxProtectionInt, err := strconv.Atoi(maxProtection[0])
|
|
|
+ maxProtection := strings.TrimSuffix(require.ConfigMaxProtection, "G")
|
|
|
+ if maxProtection == "" {
|
|
|
+ return fmt.Errorf("无效的配置 ConfigMaxProtection: '%s',数字部分为空", require.ConfigMaxProtection)
|
|
|
+ }
|
|
|
+ maxProtectionInt, err := strconv.Atoi(maxProtection)
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ return fmt.Errorf("无效的配置 ConfigMaxProtection: '%s',无法转换为数字", require.ConfigMaxProtection)
|
|
|
}
|
|
|
var planId int64
|
|
|
- if maxProtectionInt < 1000 {
|
|
|
- NodeAreaName := fmt.Sprintf("%s-%dT",require.NodeArea, 1)
|
|
|
- planId, err = s.globalLimitRepository.GetNodeArea(ctx, NodeAreaName)
|
|
|
- if err != nil {
|
|
|
+ maxProtectionNum := 1
|
|
|
+ if maxProtectionInt >= 2000 {
|
|
|
+ maxProtectionNum = maxProtectionInt / 1000
|
|
|
+ }
|
|
|
+ NodeAreaName := fmt.Sprintf("%s-%dT",require.NodeArea, maxProtectionNum)
|
|
|
+ planId, err = s.globalLimitRepository.GetNodeArea(ctx, NodeAreaName)
|
|
|
+ if err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ planId = 0
|
|
|
+ }else {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
if planId == 0 {
|
|
|
+ // 安全冗余套餐
|
|
|
planId = 6
|
|
|
+ s.logger.Warn("获取套餐Id失败", zap.String("节点区域", NodeAreaName), zap.String("防御阈值", require.ConfigMaxProtection),zap.Int64("套餐Id", int64(req.Uid)),zap.Int64("魔方套餐Id", int64(req.HostId)))
|
|
|
}
|
|
|
|
|
|
|