|
@@ -2,12 +2,16 @@ package admin
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "fmt"
|
|
v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
|
|
v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
|
|
adminApi "github.com/go-nunu/nunu-layout-advanced/api/v1/admin"
|
|
adminApi "github.com/go-nunu/nunu-layout-advanced/api/v1/admin"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/repository"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/repository"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/repository/admin"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/repository/admin"
|
|
wafRep "github.com/go-nunu/nunu-layout-advanced/internal/repository/api/waf"
|
|
wafRep "github.com/go-nunu/nunu-layout-advanced/internal/repository/api/waf"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/service"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/service"
|
|
|
|
+ "go.uber.org/zap"
|
|
|
|
+ "slices"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
type WafManageService interface {
|
|
type WafManageService interface {
|
|
@@ -60,8 +64,25 @@ func (s *wafManageService) SyncExecuteRenewalActions(ctx context.Context,req adm
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ wafExpireTime, err := s.globalLimitRep.GetGlobalLimitsByHostIds(ctx, req.HostIds)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var notExpiredHostIds []int
|
|
|
|
+
|
|
|
|
+ for _, limit := range *wafExpireTime {
|
|
|
|
+ if limit.ExpiredAt <= time.Now().Unix() - 1 * 60 * 60 {
|
|
|
|
+ notExpiredHostIds = append(notExpiredHostIds, limit.HostId)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
var renewalRequest []RenewalRequest
|
|
var renewalRequest []RenewalRequest
|
|
for i := range wafData {
|
|
for i := range wafData {
|
|
|
|
+ if slices.Contains(notExpiredHostIds, wafData[i].HostId) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
renewalRequest = append(renewalRequest, RenewalRequest{
|
|
renewalRequest = append(renewalRequest, RenewalRequest{
|
|
HostId: wafData[i].HostId,
|
|
HostId: wafData[i].HostId,
|
|
ExpiredAt: wafData[i].ExpiredAt,
|
|
ExpiredAt: wafData[i].ExpiredAt,
|
|
@@ -71,5 +92,10 @@ func (s *wafManageService) SyncExecuteRenewalActions(ctx context.Context,req adm
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if len(renewalRequest) != 0 {
|
|
|
|
+ return fmt.Errorf("续费失败,套餐距离到期时间不能小于一小时", zap.Any("实例Id", notExpiredHostIds))
|
|
|
|
+ }
|
|
|
|
+
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|