Browse Source

fix(internal/service): 修复修改全局限流策略时网关组 ID 为空的问题

- 增加了在创建或修改全局限流策略时获取网关组 ID 的逻辑
- 如果未提供网关组 ID,会根据主机 ID 获取默认的网关组 ID- 更新全局限流策略时,确保网关组 ID 不为空
fusu 3 weeks ago
parent
commit
58e0ae998f
1 changed files with 13 additions and 0 deletions
  1. 13 0
      internal/service/globallimit.go

+ 13 - 0
internal/service/globallimit.go

@@ -395,6 +395,18 @@ func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalL
 	if err != nil {
 		return err
 	}
+
+	if data.GatewayGroupId == 0 {
+		gatewayGroupId, e := s.gateWayGroupRep.GetGatewayGroupWhereHostIdNull(ctx, require)
+		if e != nil {
+			return fmt.Errorf("获取网关组失败: %w", e)
+		}
+		if gatewayGroupId == 0 {
+			return fmt.Errorf("获取网关组失败")
+		}
+		data.GatewayGroupId = gatewayGroupId
+	}
+
 	outputTimeStr, err := s.ConversionTime(ctx, require.ExpiredAt)
 	if err != nil {
 		return err
@@ -418,6 +430,7 @@ func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalL
 	if err := s.globalLimitRepository.UpdateGlobalLimitByHostId(ctx, &model.GlobalLimit{
 		HostId:  req.HostId,
 		Comment: req.Comment,
+		GatewayGroupId: data.GatewayGroupId,
 		ExpiredAt: expiredAt,
 	}); err != nil {
 		return err