浏览代码

feat(service): 优化 CC 服务并添加新功能

- 修正 CC 服务构造函数,添加 CdnService 参数
- 在 CdnService 接口中添加 DelIpItem 方法
- 在 GlobalLimitRepository 中添加 GetGlobalLimitsByExpirationRange 方法
- 更新相关处理器和服务器构造逻辑
fusu 3 周之前
父节点
当前提交
066eb22390
共有 6 个文件被更改,包括 30 次插入3 次删除
  1. 1 1
      cmd/server/wire/wire_gen.go
  2. 2 0
      go.mod
  3. 2 0
      go.sum
  4. 21 0
      internal/repository/globallimit.go
  5. 2 2
      internal/service/cc.go
  6. 2 0
      internal/service/cdn.go

+ 1 - 1
cmd/server/wire/wire_gen.go

@@ -103,7 +103,7 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*app.App, func(), err
 	gateWayGroupIpHandler := handler.NewGateWayGroupIpHandler(handlerHandler, gateWayGroupIpService)
 	allowAndDenyIpHandler := handler.NewAllowAndDenyIpHandler(handlerHandler, allowAndDenyIpService)
 	ccRepository := repository.NewCcRepository(repositoryRepository)
-	ccService := service.NewCcService(serviceService, ccRepository, webForwardingRepository)
+	ccService := service.NewCcService(serviceService, ccRepository, webForwardingRepository, cdnService)
 	ccHandler := handler.NewCcHandler(handlerHandler, ccService)
 	httpServer := server.NewHTTPServer(logger, viperViper, jwtJWT, syncedEnforcer, limiterLimiter, handlerFunc, userHandler, gameShieldHandler, gameShieldBackendHandler, webForwardingHandler, webLimitHandler, tcpforwardingHandler, udpForWardingHandler, tcpLimitHandler, udpLimitHandler, globalLimitHandler, adminHandler, gatewayGroupHandler, gateWayGroupIpHandler, allowAndDenyIpHandler, ccHandler)
 	appApp := newApp(httpServer)

+ 2 - 0
go.mod

@@ -22,6 +22,7 @@ require (
 	github.com/golang/mock v1.6.0
 	github.com/google/uuid v1.3.1
 	github.com/google/wire v0.5.0
+	github.com/hashicorp/go-multierror v1.0.0
 	github.com/jinzhu/copier v0.4.0
 	github.com/mcuadros/go-defaults v1.2.0
 	github.com/mozillazg/go-pinyin v0.20.0
@@ -82,6 +83,7 @@ require (
 	github.com/golang/snappy v1.0.0 // indirect
 	github.com/google/go-querystring v1.1.0 // indirect
 	github.com/gorilla/websocket v1.4.2 // indirect
+	github.com/hashicorp/errwrap v1.0.0 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/hpcloud/tail v1.0.0 // indirect
 	github.com/imkira/go-interpol v1.1.0 // indirect

+ 2 - 0
go.sum

@@ -296,10 +296,12 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
 github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
 github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
+github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
 github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
 github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
 github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
 github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
+github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
 github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
 github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
 github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=

+ 21 - 0
internal/repository/globallimit.go

@@ -28,6 +28,8 @@ type GlobalLimitRepository interface {
 	EditHostState(ctx context.Context, hostId int64, state bool) error
 	// 获取指定到期时间
 	GetGlobalLimitAlmostExpired(ctx context.Context, addTime int64) ([]model.GlobalLimit, error)
+	// GetGlobalLimitsByExpirationRange 获取在指定时间范围内到期的全局限制
+	GetGlobalLimitsByExpirationRange(ctx context.Context, startTime, endTime int64) ([]model.GlobalLimit, error)
 }
 
 func NewGlobalLimitRepository(
@@ -172,6 +174,25 @@ func (r *globalLimitRepository) EditHostState(ctx context.Context, hostId int64,
 	return nil
 }
 
+// GetGlobalLimitsByExpirationRange 获取在指定时间范围内到期的全局限制
+func (r *globalLimitRepository) GetGlobalLimitsByExpirationRange(ctx context.Context, startTime, endTime int64) ([]model.GlobalLimit, error) {
+	var res []model.GlobalLimit
+	db := r.DB(ctx).Where("state = ?", true)
+
+	if startTime != 0 {
+		db = db.Where("expired_at >= ?", startTime)
+	}
+	if endTime != 0 {
+		db = db.Where("expired_at < ?", endTime)
+	}
+
+	if err := db.Find(&res).Error; err != nil {
+		return nil, err
+	}
+	return res, nil
+}
+
+
 // 获取指定到期时间
 func (r *globalLimitRepository) GetGlobalLimitAlmostExpired(ctx context.Context, addTime int64) ([]model.GlobalLimit, error) {
 	var res []model.GlobalLimit

+ 2 - 2
internal/service/cc.go

@@ -16,7 +16,7 @@ func NewCcService(
     service *Service,
     ccRepository repository.CcRepository,
 	webForwardingRep repository.WebForwardingRepository,
-	cdn cdnService,
+	cdn CdnService,
 ) CcService {
 	return &ccService{
 		Service:        service,
@@ -30,7 +30,7 @@ type ccService struct {
 	*Service
 	ccRepository repository.CcRepository
 	webForwardingRep repository.WebForwardingRepository
-	cdn cdnService
+	cdn CdnService
 }
 
 func (s *ccService) GetCcList(ctx context.Context, req v1.CCListRequest) ([]v1.CCListResponse, error) {

+ 2 - 0
internal/service/cdn.go

@@ -59,6 +59,8 @@ type CdnService interface {
 	DelUserPlan(ctx context.Context,planId int64) error
 	// 删除网站分组
 	DelServerGroup(ctx context.Context,serverId int64) error
+	// 删除IP
+	DelIpItem(ctx context.Context,ipitemId int64,value string,ipFrom string,ipTo string,ipListId int64) error
 }
 
 func NewCdnService(