将带宽限制改为流量限制

This commit is contained in:
GoEdgeLab
2021-11-09 17:36:54 +08:00
parent 36ce7f0acd
commit ab1686bca5
7 changed files with 169 additions and 152 deletions

View File

@@ -77,19 +77,19 @@ func (this *PlanDAO) FindPlanName(tx *dbs.Tx, id int64) (string, error) {
}
// CreatePlan 创建套餐
func (this *PlanDAO) CreatePlan(tx *dbs.Tx, name string, clusterId int64, bandwidthLimitJSON []byte, featuresJSON []byte, priceType serverconfigs.PlanPriceType, bandwidthPriceJSON []byte, monthlyPrice float32, seasonallyPrice float32, yearlyPrice float32) (int64, error) {
func (this *PlanDAO) CreatePlan(tx *dbs.Tx, name string, clusterId int64, trafficLimitJSON []byte, featuresJSON []byte, priceType serverconfigs.PlanPriceType, trafficPriceJSON []byte, monthlyPrice float32, seasonallyPrice float32, yearlyPrice float32) (int64, error) {
var op = NewPlanOperator()
op.Name = name
op.ClusterId = clusterId
if len(bandwidthLimitJSON) > 0 {
op.BandwidthLimit = bandwidthLimitJSON
if len(trafficLimitJSON) > 0 {
op.TrafficLimit = trafficLimitJSON
}
if len(featuresJSON) > 0 {
op.Features = featuresJSON
}
op.PriceType = priceType
if len(bandwidthPriceJSON) > 0 {
op.BandwidthPrice = bandwidthPriceJSON
if len(trafficPriceJSON) > 0 {
op.TrafficPrice = trafficPriceJSON
}
if monthlyPrice >= 0 {
op.MonthlyPrice = monthlyPrice
@@ -106,7 +106,7 @@ func (this *PlanDAO) CreatePlan(tx *dbs.Tx, name string, clusterId int64, bandwi
}
// UpdatePlan 修改套餐
func (this *PlanDAO) UpdatePlan(tx *dbs.Tx, planId int64, name string, isOn bool, clusterId int64, bandwidthLimitJSON []byte, featuresJSON []byte, priceType serverconfigs.PlanPriceType, bandwidthPriceJSON []byte, monthlyPrice float32, seasonallyPrice float32, yearlyPrice float32) error {
func (this *PlanDAO) UpdatePlan(tx *dbs.Tx, planId int64, name string, isOn bool, clusterId int64, trafficLimitJSON []byte, featuresJSON []byte, priceType serverconfigs.PlanPriceType, trafficPriceJSON []byte, monthlyPrice float32, seasonallyPrice float32, yearlyPrice float32) error {
if planId <= 0 {
return errors.New("invalid planId")
}
@@ -125,15 +125,15 @@ func (this *PlanDAO) UpdatePlan(tx *dbs.Tx, planId int64, name string, isOn bool
op.Name = name
op.IsOn = isOn
op.ClusterId = clusterId
if len(bandwidthLimitJSON) > 0 {
op.BandwidthLimit = bandwidthLimitJSON
if len(trafficLimitJSON) > 0 {
op.TrafficLimit = trafficLimitJSON
}
if len(featuresJSON) > 0 {
op.Features = featuresJSON
}
op.PriceType = priceType
if len(bandwidthPriceJSON) > 0 {
op.BandwidthPrice = bandwidthPriceJSON
if len(trafficPriceJSON) > 0 {
op.TrafficPrice = trafficPriceJSON
}
if monthlyPrice >= 0 {
op.MonthlyPrice = monthlyPrice

View File

@@ -6,9 +6,9 @@ type Plan struct {
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 套餐名
ClusterId uint32 `field:"clusterId"` // 集群ID
BandwidthLimit string `field:"bandwidthLimit"` // 带宽限制
TrafficLimit string `field:"trafficLimit"` // 流量限制
Features string `field:"features"` // 允许的功能
BandwidthPrice string `field:"bandwidthPrice"` // 带宽价格设定
TrafficPrice string `field:"trafficPrice"` // 流量价格设定
MonthlyPrice float64 `field:"monthlyPrice"` // 月付
SeasonallyPrice float64 `field:"seasonallyPrice"` // 季付
YearlyPrice float64 `field:"yearlyPrice"` // 年付
@@ -22,9 +22,9 @@ type PlanOperator struct {
IsOn interface{} // 是否启用
Name interface{} // 套餐名
ClusterId interface{} // 集群ID
BandwidthLimit interface{} // 带宽限制
TrafficLimit interface{} // 流量限制
Features interface{} // 允许的功能
BandwidthPrice interface{} // 带宽价格设定
TrafficPrice interface{} // 流量价格设定
MonthlyPrice interface{} // 月付
SeasonallyPrice interface{} // 季付
YearlyPrice interface{} // 年付

View File

@@ -104,13 +104,13 @@ func (this *ServerDailyStatDAO) SaveStats(tx *dbs.Tx, stats []*pb.ServerDailySta
return err
}
// 更新带宽限制状态
bandwidthLimit, err := SharedServerDAO.FindServerBandwidthLimitConfig(tx, stat.ServerId, cacheMap)
// 更新流量限制状态
trafficLimit, err := SharedServerDAO.FindServerTrafficLimitConfig(tx, stat.ServerId, cacheMap)
if err != nil {
return err
}
if bandwidthLimit != nil && bandwidthLimit.IsOn && !bandwidthLimit.IsEmpty() {
err = SharedServerDAO.UpdateServerBandwidthLimitStatus(tx, bandwidthLimit, stat.ServerId, false)
if trafficLimit != nil && trafficLimit.IsOn && !trafficLimit.IsEmpty() {
err = SharedServerDAO.UpdateServerTrafficLimitStatus(tx, trafficLimit, stat.ServerId, false)
if err != nil {
return err
}

View File

@@ -1031,24 +1031,24 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
config.HTTPCachePolicyId = httpCachePolicyId
}
// bandwidth limit
if len(server.BandwidthLimit) > 0 {
var bandwidthLimitConfig = &serverconfigs.BandwidthLimitConfig{}
err = json.Unmarshal([]byte(server.BandwidthLimit), bandwidthLimitConfig)
// traffic limit
if len(server.TrafficLimit) > 0 {
var trafficLimitConfig = &serverconfigs.TrafficLimitConfig{}
err = json.Unmarshal([]byte(server.TrafficLimit), trafficLimitConfig)
if err != nil {
return nil, err
}
config.BandwidthLimit = bandwidthLimitConfig
config.TrafficLimit = trafficLimitConfig
if bandwidthLimitConfig.IsOn && !bandwidthLimitConfig.IsEmpty() {
if len(server.BandwidthLimitStatus) > 0 {
var status = &serverconfigs.BandwidthLimitStatus{}
err = json.Unmarshal([]byte(server.BandwidthLimitStatus), status)
if trafficLimitConfig.IsOn && !trafficLimitConfig.IsEmpty() {
if len(server.TrafficLimitStatus) > 0 {
var status = &serverconfigs.TrafficLimitStatus{}
err = json.Unmarshal([]byte(server.TrafficLimitStatus), status)
if err != nil {
return nil, err
}
if status.IsValid() {
config.BandwidthLimitStatus = status
config.TrafficLimitStatus = status
}
}
}
@@ -1060,12 +1060,29 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
if err != nil {
return nil, err
}
if userPlan != nil {
if userPlan != nil && userPlan.IsOn == 1 {
if len(userPlan.DayTo) == 0 {
userPlan.DayTo = DefaultUserPlanMaxDay
}
config.UserPlan = &serverconfigs.UserPlanConfig{
DayTo: userPlan.DayTo,
// 套餐是否依然有效
plan, err := SharedPlanDAO.FindEnabledPlan(tx, int64(userPlan.PlanId))
if err != nil {
return nil, err
}
if plan != nil {
config.UserPlan = &serverconfigs.UserPlanConfig{
DayTo: userPlan.DayTo,
}
if len(plan.TrafficLimit) > 0 && (config.TrafficLimit == nil || !config.TrafficLimit.IsOn) {
var trafficLimitConfig = &serverconfigs.TrafficLimitConfig{}
err = json.Unmarshal([]byte(plan.TrafficLimit), trafficLimitConfig)
if err != nil {
return nil, err
}
config.TrafficLimit = trafficLimitConfig
}
}
}
}
@@ -1791,63 +1808,65 @@ func (this *ServerDAO) NotifyServerPortsUpdate(tx *dbs.Tx, serverId int64) error
UpdateQuickly()
}
// FindServerBandwidthLimitConfig 查找服务的带宽限制
func (this *ServerDAO) FindServerBandwidthLimitConfig(tx *dbs.Tx, serverId int64, cacheMap maps.Map) (*serverconfigs.BandwidthLimitConfig, error) {
// FindServerTrafficLimitConfig 查找服务的流量限制
func (this *ServerDAO) FindServerTrafficLimitConfig(tx *dbs.Tx, serverId int64, cacheMap maps.Map) (*serverconfigs.TrafficLimitConfig, error) {
if cacheMap == nil {
cacheMap = maps.Map{}
}
var cacheKey = this.Table + ":FindServerBandwidthLimitConfig:" + types.String(serverId)
var cacheKey = this.Table + ":FindServerTrafficLimitConfig:" + types.String(serverId)
result, ok := cacheMap[cacheKey]
if ok {
return result.(*serverconfigs.BandwidthLimitConfig), nil
return result.(*serverconfigs.TrafficLimitConfig), nil
}
bandwidthLimit, err := this.Query(tx).
trafficLimit, err := this.Query(tx).
Pk(serverId).
Result("bandwidthLimit").
Result("trafficLimit").
FindStringCol("")
if err != nil {
return nil, err
}
var limit = &serverconfigs.BandwidthLimitConfig{}
if len(bandwidthLimit) == 0 {
var limit = &serverconfigs.TrafficLimitConfig{}
if len(trafficLimit) == 0 {
return limit, nil
}
err = json.Unmarshal([]byte(bandwidthLimit), limit)
err = json.Unmarshal([]byte(trafficLimit), limit)
if err != nil {
return nil, err
}
// TODO 套餐
cacheMap[cacheKey] = limit
return limit, nil
}
// UpdateServerBandwidthLimitConfig 修改服务的带宽限制
func (this *ServerDAO) UpdateServerBandwidthLimitConfig(tx *dbs.Tx, serverId int64, bandwidthLimitConfig *serverconfigs.BandwidthLimitConfig) error {
// UpdateServerTrafficLimitConfig 修改服务的流量限制
func (this *ServerDAO) UpdateServerTrafficLimitConfig(tx *dbs.Tx, serverId int64, trafficLimitConfig *serverconfigs.TrafficLimitConfig) error {
if serverId <= 0 {
return errors.New("invalid serverId")
}
limitJSON, err := json.Marshal(bandwidthLimitConfig)
limitJSON, err := json.Marshal(trafficLimitConfig)
if err != nil {
return err
}
err = this.Query(tx).
Pk(serverId).
Set("bandwidthLimit", limitJSON).
Set("trafficLimit", limitJSON).
UpdateQuickly()
if err != nil {
return err
}
// 更新状态
return this.UpdateServerBandwidthLimitStatus(tx, bandwidthLimitConfig, serverId, true)
return this.UpdateServerTrafficLimitStatus(tx, trafficLimitConfig, serverId, true)
}
func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLimitConfig *serverconfigs.BandwidthLimitConfig, serverId int64, isUpdatingConfig bool) error {
if !bandwidthLimitConfig.IsOn {
func (this *ServerDAO) UpdateServerTrafficLimitStatus(tx *dbs.Tx, trafficLimitConfig *serverconfigs.TrafficLimitConfig, serverId int64, isUpdatingConfig bool) error {
if !trafficLimitConfig.IsOn {
if isUpdatingConfig {
return this.NotifyUpdate(tx, serverId)
}
@@ -1856,12 +1875,12 @@ func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLim
oldStatusString, err := this.Query(tx).
Pk(serverId).
Result("bandwidthLimitStatus").
Result("trafficLimitStatus").
FindStringCol("")
if err != nil {
return err
}
var oldStatus = &serverconfigs.BandwidthLimitStatus{}
var oldStatus = &serverconfigs.TrafficLimitStatus{}
if len(oldStatusString) > 0 {
err = json.Unmarshal([]byte(oldStatusString), oldStatus)
if err != nil {
@@ -1877,52 +1896,52 @@ func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLim
var untilDay = ""
// daily
if bandwidthLimitConfig.DailyBytes() > 0 {
if trafficLimitConfig.DailyBytes() > 0 {
stat, err := SharedServerDailyStatDAO.SumDailyStat(tx, serverId, timeutil.Format("Ymd"))
if err != nil {
return err
}
if stat != nil && stat.Bytes >= bandwidthLimitConfig.DailyBytes() {
if stat != nil && stat.Bytes >= trafficLimitConfig.DailyBytes() {
untilDay = timeutil.Format("Ymd")
}
}
// monthly
if bandwidthLimitConfig.MonthlyBytes() > 0 {
if trafficLimitConfig.MonthlyBytes() > 0 {
stat, err := SharedServerDailyStatDAO.SumMonthlyStat(tx, serverId, timeutil.Format("Ym"))
if err != nil {
return err
}
if stat != nil && stat.Bytes >= bandwidthLimitConfig.MonthlyBytes() {
if stat != nil && stat.Bytes >= trafficLimitConfig.MonthlyBytes() {
untilDay = timeutil.Format("Ym") + fmt.Sprintf("%02d", types.Int(timeutil.Format("t")))
}
}
// totally
if bandwidthLimitConfig.TotalBytes() > 0 {
totalBandwidth, err := this.Query(tx).
if trafficLimitConfig.TotalBytes() > 0 {
totalTraffic, err := this.Query(tx).
Pk(serverId).
Result("totalBandwidth").
Result("totalTraffic").
FindFloat64Col(0)
if err != nil {
return err
}
if totalBandwidth >= float64(bandwidthLimitConfig.TotalBytes()) {
if totalTraffic >= float64(trafficLimitConfig.TotalBytes()) {
untilDay = "20990101"
}
}
var isChanged = oldStatus.UntilDay != untilDay
if isChanged {
statusJSON, err := json.Marshal(&serverconfigs.BandwidthLimitStatus{UntilDay: untilDay})
statusJSON, err := json.Marshal(&serverconfigs.TrafficLimitStatus{UntilDay: untilDay})
if err != nil {
return err
}
err = this.Query(tx).
Pk(serverId).
Set("bandwidthLimitStatus", statusJSON).
Set("trafficLimitStatus", statusJSON).
UpdateQuickly()
if err != nil {
return err
@@ -1936,22 +1955,22 @@ func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLim
return nil
}
// IncreaseServerTotalBandwidth 增加服务的总带宽
func (this *ServerDAO) IncreaseServerTotalBandwidth(tx *dbs.Tx, serverId int64, bytes int64) error {
// IncreaseServerTotalTraffic 增加服务的总流量
func (this *ServerDAO) IncreaseServerTotalTraffic(tx *dbs.Tx, serverId int64, bytes int64) error {
var gb = float64(bytes) / 1024 / 1024 / 1024
return this.Query(tx).
Pk(serverId).
Set("totalBandwidth", dbs.SQL("totalBandwidth+:bandwidthGB")).
Param("bandwidthGB", gb).
Set("totalTraffic", dbs.SQL("totalTraffic+:trafficGB")).
Param("trafficGB", gb).
UpdateQuickly()
}
// ResetServerTotalBandwidth 重置服务总带宽
func (this *ServerDAO) ResetServerTotalBandwidth(tx *dbs.Tx, serverId int64) error {
// ResetServerTotalTraffic 重置服务总流量
func (this *ServerDAO) ResetServerTotalTraffic(tx *dbs.Tx, serverId int64) error {
return this.Query(tx).
Pk(serverId).
Set("totalBandwidth", 0).
Set("totalTraffic", 0).
UpdateQuickly()
}

View File

@@ -164,7 +164,7 @@ func TestServerDAO_FindAllEnabledServersWithDomain(t *testing.T) {
}
}
func TestServerDAO_UpdateServerBandwidthLimitStatus(t *testing.T) {
func TestServerDAO_UpdateServerTrafficLimitStatus(t *testing.T) {
dbs.NotifyReady()
var tx *dbs.Tx
@@ -172,7 +172,7 @@ func TestServerDAO_UpdateServerBandwidthLimitStatus(t *testing.T) {
defer func() {
t.Log(time.Since(before).Seconds()*1000, "ms")
}()
err := NewServerDAO().UpdateServerBandwidthLimitStatus(tx, &serverconfigs.BandwidthLimitConfig{
err := NewServerDAO().UpdateServerTrafficLimitStatus(tx, &serverconfigs.TrafficLimitConfig{
IsOn: true,
DailySize: &shared.SizeCapacity{Count: 1, Unit: "mb"},
MonthlySize: &shared.SizeCapacity{Count: 10, Unit: "mb"},

View File

@@ -2,81 +2,81 @@ package models
// Server 服务
type Server struct {
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
UserId uint32 `field:"userId"` // 用户ID
AdminId uint32 `field:"adminId"` // 管理员ID
Type string `field:"type"` // 服务类型
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
ServerNames string `field:"serverNames"` // 域名列表
AuditingServerNames string `field:"auditingServerNames"` // 审核中的域名
IsAuditing uint8 `field:"isAuditing"` // 是否正在审核
AuditingResult string `field:"auditingResult"` // 审核结果
Http string `field:"http"` // HTTP配置
Https string `field:"https"` // HTTPS配置
Tcp string `field:"tcp"` // TCP配置
Tls string `field:"tls"` // TLS配置
Unix string `field:"unix"` // Unix配置
Udp string `field:"udp"` // UDP配置
WebId uint32 `field:"webId"` // WEB配置
ReverseProxy string `field:"reverseProxy"` // 反向代理配置
GroupIds string `field:"groupIds"` // 分组ID列表
Config string `field:"config"` // 服务配置,自动生成
ConfigMd5 string `field:"configMd5"` // Md5
ClusterId uint32 `field:"clusterId"` // 集群ID
IncludeNodes string `field:"includeNodes"` // 部署条件
ExcludeNodes string `field:"excludeNodes"` // 节点排除条件
Version uint32 `field:"version"` // 版本号
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
DnsName string `field:"dnsName"` // DNS名称
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
SupportCNAME uint8 `field:"supportCNAME"` // 允许CNAME不在域名名单
BandwidthLimit string `field:"bandwidthLimit"` // 带宽限制
TotalBandwidth float64 `field:"totalBandwidth"` // 总带宽用量单位GB
BandwidthLimitStatus string `field:"bandwidthLimitStatus"` // 带宽限制状态
UserPlanId uint32 `field:"userPlanId"` // 所属套餐ID
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
UserId uint32 `field:"userId"` // 用户ID
AdminId uint32 `field:"adminId"` // 管理员ID
Type string `field:"type"` // 服务类型
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
ServerNames string `field:"serverNames"` // 域名列表
AuditingServerNames string `field:"auditingServerNames"` // 审核中的域名
IsAuditing uint8 `field:"isAuditing"` // 是否正在审核
AuditingResult string `field:"auditingResult"` // 审核结果
Http string `field:"http"` // HTTP配置
Https string `field:"https"` // HTTPS配置
Tcp string `field:"tcp"` // TCP配置
Tls string `field:"tls"` // TLS配置
Unix string `field:"unix"` // Unix配置
Udp string `field:"udp"` // UDP配置
WebId uint32 `field:"webId"` // WEB配置
ReverseProxy string `field:"reverseProxy"` // 反向代理配置
GroupIds string `field:"groupIds"` // 分组ID列表
Config string `field:"config"` // 服务配置,自动生成
ConfigMd5 string `field:"configMd5"` // Md5
ClusterId uint32 `field:"clusterId"` // 集群ID
IncludeNodes string `field:"includeNodes"` // 部署条件
ExcludeNodes string `field:"excludeNodes"` // 节点排除条件
Version uint32 `field:"version"` // 版本号
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
DnsName string `field:"dnsName"` // DNS名称
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
SupportCNAME uint8 `field:"supportCNAME"` // 允许CNAME不在域名名单
TrafficLimit string `field:"trafficLimit"` // 流量限制
TotalTraffic float64 `field:"totalTraffic"` // 总流量用量单位GB
TrafficLimitStatus string `field:"trafficLimitStatus"` // 流量限制状态
UserPlanId uint32 `field:"userPlanId"` // 所属套餐ID
}
type ServerOperator struct {
Id interface{} // ID
IsOn interface{} // 是否启用
UserId interface{} // 用户ID
AdminId interface{} // 管理员ID
Type interface{} // 服务类型
Name interface{} // 名称
Description interface{} // 描述
ServerNames interface{} // 域名列表
AuditingServerNames interface{} // 审核中的域名
IsAuditing interface{} // 是否正在审核
AuditingResult interface{} // 审核结果
Http interface{} // HTTP配置
Https interface{} // HTTPS配置
Tcp interface{} // TCP配置
Tls interface{} // TLS配置
Unix interface{} // Unix配置
Udp interface{} // UDP配置
WebId interface{} // WEB配置
ReverseProxy interface{} // 反向代理配置
GroupIds interface{} // 分组ID列表
Config interface{} // 服务配置,自动生成
ConfigMd5 interface{} // Md5
ClusterId interface{} // 集群ID
IncludeNodes interface{} // 部署条件
ExcludeNodes interface{} // 节点排除条件
Version interface{} // 版本号
CreatedAt interface{} // 创建时间
State interface{} // 状态
DnsName interface{} // DNS名称
TcpPorts interface{} // 所包含TCP端口
UdpPorts interface{} // 所包含UDP端口
SupportCNAME interface{} // 允许CNAME不在域名名单
BandwidthLimit interface{} // 带宽限制
TotalBandwidth interface{} // 总带宽用量单位GB
BandwidthLimitStatus interface{} // 带宽限制状态
UserPlanId interface{} // 所属套餐ID
Id interface{} // ID
IsOn interface{} // 是否启用
UserId interface{} // 用户ID
AdminId interface{} // 管理员ID
Type interface{} // 服务类型
Name interface{} // 名称
Description interface{} // 描述
ServerNames interface{} // 域名列表
AuditingServerNames interface{} // 审核中的域名
IsAuditing interface{} // 是否正在审核
AuditingResult interface{} // 审核结果
Http interface{} // HTTP配置
Https interface{} // HTTPS配置
Tcp interface{} // TCP配置
Tls interface{} // TLS配置
Unix interface{} // Unix配置
Udp interface{} // UDP配置
WebId interface{} // WEB配置
ReverseProxy interface{} // 反向代理配置
GroupIds interface{} // 分组ID列表
Config interface{} // 服务配置,自动生成
ConfigMd5 interface{} // Md5
ClusterId interface{} // 集群ID
IncludeNodes interface{} // 部署条件
ExcludeNodes interface{} // 节点排除条件
Version interface{} // 版本号
CreatedAt interface{} // 创建时间
State interface{} // 状态
DnsName interface{} // DNS名称
TcpPorts interface{} // 所包含TCP端口
UdpPorts interface{} // 所包含UDP端口
SupportCNAME interface{} // 允许CNAME不在域名名单
TrafficLimit interface{} // 流量限制
TotalTraffic interface{} // 总流量用量单位GB
TrafficLimitStatus interface{} // 流量限制状态
UserPlanId interface{} // 所属套餐ID
}
func NewServerOperator() *ServerOperator {

View File

@@ -1711,8 +1711,8 @@ func (this *ServerService) PurgeServerCache(ctx context.Context, req *pb.PurgeSe
return purgeResponse, nil
}
// FindEnabledServerBandwidthLimit 查找带宽限制
func (this *ServerService) FindEnabledServerBandwidthLimit(ctx context.Context, req *pb.FindEnabledServerBandwidthLimitRequest) (*pb.FindEnabledServerBandwidthLimitResponse, error) {
// FindEnabledServerTrafficLimit 查找流量限制
func (this *ServerService) FindEnabledServerTrafficLimit(ctx context.Context, req *pb.FindEnabledServerTrafficLimitRequest) (*pb.FindEnabledServerTrafficLimitResponse, error) {
_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
if err != nil {
return nil, err
@@ -1721,7 +1721,7 @@ func (this *ServerService) FindEnabledServerBandwidthLimit(ctx context.Context,
// TODO 检查用户权限
var tx = this.NullTx()
limitConfig, err := models.SharedServerDAO.FindServerBandwidthLimitConfig(tx, req.ServerId, nil)
limitConfig, err := models.SharedServerDAO.FindServerTrafficLimitConfig(tx, req.ServerId, nil)
if err != nil {
return nil, err
}
@@ -1729,26 +1729,26 @@ func (this *ServerService) FindEnabledServerBandwidthLimit(ctx context.Context,
if err != nil {
return nil, err
}
return &pb.FindEnabledServerBandwidthLimitResponse{
BandwidthLimitJSON: limitConfigJSON,
return &pb.FindEnabledServerTrafficLimitResponse{
TrafficLimitJSON: limitConfigJSON,
}, nil
}
// UpdateServerBandwidthLimit 设置带宽限制
func (this *ServerService) UpdateServerBandwidthLimit(ctx context.Context, req *pb.UpdateServerBandwidthLimitRequest) (*pb.RPCSuccess, error) {
// UpdateServerTrafficLimit 设置流量限制
func (this *ServerService) UpdateServerTrafficLimit(ctx context.Context, req *pb.UpdateServerTrafficLimitRequest) (*pb.RPCSuccess, error) {
_, err := this.ValidateAdmin(ctx, 0)
if err != nil {
return nil, err
}
var tx = this.NullTx()
var config = &serverconfigs.BandwidthLimitConfig{}
err = json.Unmarshal(req.BandwidthLimitJSON, config)
var config = &serverconfigs.TrafficLimitConfig{}
err = json.Unmarshal(req.TrafficLimitJSON, config)
if err != nil {
return nil, err
}
err = models.SharedServerDAO.UpdateServerBandwidthLimitConfig(tx, req.ServerId, config)
err = models.SharedServerDAO.UpdateServerTrafficLimitConfig(tx, req.ServerId, config)
if err != nil {
return nil, err
}
@@ -1814,7 +1814,5 @@ func (this *ServerService) UpdateServerUserPlan(ctx context.Context, req *pb.Upd
return nil, err
}
return this.Success()
}