mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 23:00:25 +08:00
将带宽限制改为流量限制
This commit is contained in:
@@ -77,19 +77,19 @@ func (this *PlanDAO) FindPlanName(tx *dbs.Tx, id int64) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreatePlan 创建套餐
|
// 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()
|
var op = NewPlanOperator()
|
||||||
op.Name = name
|
op.Name = name
|
||||||
op.ClusterId = clusterId
|
op.ClusterId = clusterId
|
||||||
if len(bandwidthLimitJSON) > 0 {
|
if len(trafficLimitJSON) > 0 {
|
||||||
op.BandwidthLimit = bandwidthLimitJSON
|
op.TrafficLimit = trafficLimitJSON
|
||||||
}
|
}
|
||||||
if len(featuresJSON) > 0 {
|
if len(featuresJSON) > 0 {
|
||||||
op.Features = featuresJSON
|
op.Features = featuresJSON
|
||||||
}
|
}
|
||||||
op.PriceType = priceType
|
op.PriceType = priceType
|
||||||
if len(bandwidthPriceJSON) > 0 {
|
if len(trafficPriceJSON) > 0 {
|
||||||
op.BandwidthPrice = bandwidthPriceJSON
|
op.TrafficPrice = trafficPriceJSON
|
||||||
}
|
}
|
||||||
if monthlyPrice >= 0 {
|
if monthlyPrice >= 0 {
|
||||||
op.MonthlyPrice = monthlyPrice
|
op.MonthlyPrice = monthlyPrice
|
||||||
@@ -106,7 +106,7 @@ func (this *PlanDAO) CreatePlan(tx *dbs.Tx, name string, clusterId int64, bandwi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePlan 修改套餐
|
// 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 {
|
if planId <= 0 {
|
||||||
return errors.New("invalid planId")
|
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.Name = name
|
||||||
op.IsOn = isOn
|
op.IsOn = isOn
|
||||||
op.ClusterId = clusterId
|
op.ClusterId = clusterId
|
||||||
if len(bandwidthLimitJSON) > 0 {
|
if len(trafficLimitJSON) > 0 {
|
||||||
op.BandwidthLimit = bandwidthLimitJSON
|
op.TrafficLimit = trafficLimitJSON
|
||||||
}
|
}
|
||||||
if len(featuresJSON) > 0 {
|
if len(featuresJSON) > 0 {
|
||||||
op.Features = featuresJSON
|
op.Features = featuresJSON
|
||||||
}
|
}
|
||||||
op.PriceType = priceType
|
op.PriceType = priceType
|
||||||
if len(bandwidthPriceJSON) > 0 {
|
if len(trafficPriceJSON) > 0 {
|
||||||
op.BandwidthPrice = bandwidthPriceJSON
|
op.TrafficPrice = trafficPriceJSON
|
||||||
}
|
}
|
||||||
if monthlyPrice >= 0 {
|
if monthlyPrice >= 0 {
|
||||||
op.MonthlyPrice = monthlyPrice
|
op.MonthlyPrice = monthlyPrice
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ type Plan struct {
|
|||||||
IsOn uint8 `field:"isOn"` // 是否启用
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
Name string `field:"name"` // 套餐名
|
Name string `field:"name"` // 套餐名
|
||||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
BandwidthLimit string `field:"bandwidthLimit"` // 带宽限制
|
TrafficLimit string `field:"trafficLimit"` // 流量限制
|
||||||
Features string `field:"features"` // 允许的功能
|
Features string `field:"features"` // 允许的功能
|
||||||
BandwidthPrice string `field:"bandwidthPrice"` // 带宽价格设定
|
TrafficPrice string `field:"trafficPrice"` // 流量价格设定
|
||||||
MonthlyPrice float64 `field:"monthlyPrice"` // 月付
|
MonthlyPrice float64 `field:"monthlyPrice"` // 月付
|
||||||
SeasonallyPrice float64 `field:"seasonallyPrice"` // 季付
|
SeasonallyPrice float64 `field:"seasonallyPrice"` // 季付
|
||||||
YearlyPrice float64 `field:"yearlyPrice"` // 年付
|
YearlyPrice float64 `field:"yearlyPrice"` // 年付
|
||||||
@@ -22,9 +22,9 @@ type PlanOperator struct {
|
|||||||
IsOn interface{} // 是否启用
|
IsOn interface{} // 是否启用
|
||||||
Name interface{} // 套餐名
|
Name interface{} // 套餐名
|
||||||
ClusterId interface{} // 集群ID
|
ClusterId interface{} // 集群ID
|
||||||
BandwidthLimit interface{} // 带宽限制
|
TrafficLimit interface{} // 流量限制
|
||||||
Features interface{} // 允许的功能
|
Features interface{} // 允许的功能
|
||||||
BandwidthPrice interface{} // 带宽价格设定
|
TrafficPrice interface{} // 流量价格设定
|
||||||
MonthlyPrice interface{} // 月付
|
MonthlyPrice interface{} // 月付
|
||||||
SeasonallyPrice interface{} // 季付
|
SeasonallyPrice interface{} // 季付
|
||||||
YearlyPrice interface{} // 年付
|
YearlyPrice interface{} // 年付
|
||||||
|
|||||||
@@ -104,13 +104,13 @@ func (this *ServerDailyStatDAO) SaveStats(tx *dbs.Tx, stats []*pb.ServerDailySta
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新带宽限制状态
|
// 更新流量限制状态
|
||||||
bandwidthLimit, err := SharedServerDAO.FindServerBandwidthLimitConfig(tx, stat.ServerId, cacheMap)
|
trafficLimit, err := SharedServerDAO.FindServerTrafficLimitConfig(tx, stat.ServerId, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if bandwidthLimit != nil && bandwidthLimit.IsOn && !bandwidthLimit.IsEmpty() {
|
if trafficLimit != nil && trafficLimit.IsOn && !trafficLimit.IsEmpty() {
|
||||||
err = SharedServerDAO.UpdateServerBandwidthLimitStatus(tx, bandwidthLimit, stat.ServerId, false)
|
err = SharedServerDAO.UpdateServerTrafficLimitStatus(tx, trafficLimit, stat.ServerId, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1031,24 +1031,24 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
|
|||||||
config.HTTPCachePolicyId = httpCachePolicyId
|
config.HTTPCachePolicyId = httpCachePolicyId
|
||||||
}
|
}
|
||||||
|
|
||||||
// bandwidth limit
|
// traffic limit
|
||||||
if len(server.BandwidthLimit) > 0 {
|
if len(server.TrafficLimit) > 0 {
|
||||||
var bandwidthLimitConfig = &serverconfigs.BandwidthLimitConfig{}
|
var trafficLimitConfig = &serverconfigs.TrafficLimitConfig{}
|
||||||
err = json.Unmarshal([]byte(server.BandwidthLimit), bandwidthLimitConfig)
|
err = json.Unmarshal([]byte(server.TrafficLimit), trafficLimitConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.BandwidthLimit = bandwidthLimitConfig
|
config.TrafficLimit = trafficLimitConfig
|
||||||
|
|
||||||
if bandwidthLimitConfig.IsOn && !bandwidthLimitConfig.IsEmpty() {
|
if trafficLimitConfig.IsOn && !trafficLimitConfig.IsEmpty() {
|
||||||
if len(server.BandwidthLimitStatus) > 0 {
|
if len(server.TrafficLimitStatus) > 0 {
|
||||||
var status = &serverconfigs.BandwidthLimitStatus{}
|
var status = &serverconfigs.TrafficLimitStatus{}
|
||||||
err = json.Unmarshal([]byte(server.BandwidthLimitStatus), status)
|
err = json.Unmarshal([]byte(server.TrafficLimitStatus), status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if status.IsValid() {
|
if status.IsValid() {
|
||||||
config.BandwidthLimitStatus = status
|
config.TrafficLimitStatus = status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1060,13 +1060,30 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if userPlan != nil {
|
if userPlan != nil && userPlan.IsOn == 1 {
|
||||||
if len(userPlan.DayTo) == 0 {
|
if len(userPlan.DayTo) == 0 {
|
||||||
userPlan.DayTo = DefaultUserPlanMaxDay
|
userPlan.DayTo = DefaultUserPlanMaxDay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 套餐是否依然有效
|
||||||
|
plan, err := SharedPlanDAO.FindEnabledPlan(tx, int64(userPlan.PlanId))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if plan != nil {
|
||||||
config.UserPlan = &serverconfigs.UserPlanConfig{
|
config.UserPlan = &serverconfigs.UserPlanConfig{
|
||||||
DayTo: userPlan.DayTo,
|
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()
|
UpdateQuickly()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindServerBandwidthLimitConfig 查找服务的带宽限制
|
// FindServerTrafficLimitConfig 查找服务的流量限制
|
||||||
func (this *ServerDAO) FindServerBandwidthLimitConfig(tx *dbs.Tx, serverId int64, cacheMap maps.Map) (*serverconfigs.BandwidthLimitConfig, error) {
|
func (this *ServerDAO) FindServerTrafficLimitConfig(tx *dbs.Tx, serverId int64, cacheMap maps.Map) (*serverconfigs.TrafficLimitConfig, error) {
|
||||||
if cacheMap == nil {
|
if cacheMap == nil {
|
||||||
cacheMap = maps.Map{}
|
cacheMap = maps.Map{}
|
||||||
}
|
}
|
||||||
var cacheKey = this.Table + ":FindServerBandwidthLimitConfig:" + types.String(serverId)
|
var cacheKey = this.Table + ":FindServerTrafficLimitConfig:" + types.String(serverId)
|
||||||
result, ok := cacheMap[cacheKey]
|
result, ok := cacheMap[cacheKey]
|
||||||
if ok {
|
if ok {
|
||||||
return result.(*serverconfigs.BandwidthLimitConfig), nil
|
return result.(*serverconfigs.TrafficLimitConfig), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bandwidthLimit, err := this.Query(tx).
|
trafficLimit, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Result("bandwidthLimit").
|
Result("trafficLimit").
|
||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var limit = &serverconfigs.BandwidthLimitConfig{}
|
var limit = &serverconfigs.TrafficLimitConfig{}
|
||||||
if len(bandwidthLimit) == 0 {
|
if len(trafficLimit) == 0 {
|
||||||
return limit, nil
|
return limit, nil
|
||||||
}
|
}
|
||||||
err = json.Unmarshal([]byte(bandwidthLimit), limit)
|
err = json.Unmarshal([]byte(trafficLimit), limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 套餐
|
||||||
|
|
||||||
cacheMap[cacheKey] = limit
|
cacheMap[cacheKey] = limit
|
||||||
|
|
||||||
return limit, nil
|
return limit, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateServerBandwidthLimitConfig 修改服务的带宽限制
|
// UpdateServerTrafficLimitConfig 修改服务的流量限制
|
||||||
func (this *ServerDAO) UpdateServerBandwidthLimitConfig(tx *dbs.Tx, serverId int64, bandwidthLimitConfig *serverconfigs.BandwidthLimitConfig) error {
|
func (this *ServerDAO) UpdateServerTrafficLimitConfig(tx *dbs.Tx, serverId int64, trafficLimitConfig *serverconfigs.TrafficLimitConfig) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("invalid serverId")
|
return errors.New("invalid serverId")
|
||||||
}
|
}
|
||||||
limitJSON, err := json.Marshal(bandwidthLimitConfig)
|
limitJSON, err := json.Marshal(trafficLimitConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = this.Query(tx).
|
err = this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Set("bandwidthLimit", limitJSON).
|
Set("trafficLimit", limitJSON).
|
||||||
UpdateQuickly()
|
UpdateQuickly()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
func (this *ServerDAO) UpdateServerTrafficLimitStatus(tx *dbs.Tx, trafficLimitConfig *serverconfigs.TrafficLimitConfig, serverId int64, isUpdatingConfig bool) error {
|
||||||
if !bandwidthLimitConfig.IsOn {
|
if !trafficLimitConfig.IsOn {
|
||||||
if isUpdatingConfig {
|
if isUpdatingConfig {
|
||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
@@ -1856,12 +1875,12 @@ func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLim
|
|||||||
|
|
||||||
oldStatusString, err := this.Query(tx).
|
oldStatusString, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Result("bandwidthLimitStatus").
|
Result("trafficLimitStatus").
|
||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var oldStatus = &serverconfigs.BandwidthLimitStatus{}
|
var oldStatus = &serverconfigs.TrafficLimitStatus{}
|
||||||
if len(oldStatusString) > 0 {
|
if len(oldStatusString) > 0 {
|
||||||
err = json.Unmarshal([]byte(oldStatusString), oldStatus)
|
err = json.Unmarshal([]byte(oldStatusString), oldStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1877,52 +1896,52 @@ func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLim
|
|||||||
var untilDay = ""
|
var untilDay = ""
|
||||||
|
|
||||||
// daily
|
// daily
|
||||||
if bandwidthLimitConfig.DailyBytes() > 0 {
|
if trafficLimitConfig.DailyBytes() > 0 {
|
||||||
stat, err := SharedServerDailyStatDAO.SumDailyStat(tx, serverId, timeutil.Format("Ymd"))
|
stat, err := SharedServerDailyStatDAO.SumDailyStat(tx, serverId, timeutil.Format("Ymd"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if stat != nil && stat.Bytes >= bandwidthLimitConfig.DailyBytes() {
|
if stat != nil && stat.Bytes >= trafficLimitConfig.DailyBytes() {
|
||||||
untilDay = timeutil.Format("Ymd")
|
untilDay = timeutil.Format("Ymd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// monthly
|
// monthly
|
||||||
if bandwidthLimitConfig.MonthlyBytes() > 0 {
|
if trafficLimitConfig.MonthlyBytes() > 0 {
|
||||||
stat, err := SharedServerDailyStatDAO.SumMonthlyStat(tx, serverId, timeutil.Format("Ym"))
|
stat, err := SharedServerDailyStatDAO.SumMonthlyStat(tx, serverId, timeutil.Format("Ym"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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")))
|
untilDay = timeutil.Format("Ym") + fmt.Sprintf("%02d", types.Int(timeutil.Format("t")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// totally
|
// totally
|
||||||
if bandwidthLimitConfig.TotalBytes() > 0 {
|
if trafficLimitConfig.TotalBytes() > 0 {
|
||||||
totalBandwidth, err := this.Query(tx).
|
totalTraffic, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Result("totalBandwidth").
|
Result("totalTraffic").
|
||||||
FindFloat64Col(0)
|
FindFloat64Col(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalBandwidth >= float64(bandwidthLimitConfig.TotalBytes()) {
|
if totalTraffic >= float64(trafficLimitConfig.TotalBytes()) {
|
||||||
untilDay = "20990101"
|
untilDay = "20990101"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isChanged = oldStatus.UntilDay != untilDay
|
var isChanged = oldStatus.UntilDay != untilDay
|
||||||
if isChanged {
|
if isChanged {
|
||||||
statusJSON, err := json.Marshal(&serverconfigs.BandwidthLimitStatus{UntilDay: untilDay})
|
statusJSON, err := json.Marshal(&serverconfigs.TrafficLimitStatus{UntilDay: untilDay})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = this.Query(tx).
|
err = this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Set("bandwidthLimitStatus", statusJSON).
|
Set("trafficLimitStatus", statusJSON).
|
||||||
UpdateQuickly()
|
UpdateQuickly()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1936,22 +1955,22 @@ func (this *ServerDAO) UpdateServerBandwidthLimitStatus(tx *dbs.Tx, bandwidthLim
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncreaseServerTotalBandwidth 增加服务的总带宽
|
// IncreaseServerTotalTraffic 增加服务的总流量
|
||||||
func (this *ServerDAO) IncreaseServerTotalBandwidth(tx *dbs.Tx, serverId int64, bytes int64) error {
|
func (this *ServerDAO) IncreaseServerTotalTraffic(tx *dbs.Tx, serverId int64, bytes int64) error {
|
||||||
var gb = float64(bytes) / 1024 / 1024 / 1024
|
var gb = float64(bytes) / 1024 / 1024 / 1024
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Set("totalBandwidth", dbs.SQL("totalBandwidth+:bandwidthGB")).
|
Set("totalTraffic", dbs.SQL("totalTraffic+:trafficGB")).
|
||||||
Param("bandwidthGB", gb).
|
Param("trafficGB", gb).
|
||||||
UpdateQuickly()
|
UpdateQuickly()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetServerTotalBandwidth 重置服务总带宽
|
// ResetServerTotalTraffic 重置服务总流量
|
||||||
func (this *ServerDAO) ResetServerTotalBandwidth(tx *dbs.Tx, serverId int64) error {
|
func (this *ServerDAO) ResetServerTotalTraffic(tx *dbs.Tx, serverId int64) error {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Set("totalBandwidth", 0).
|
Set("totalTraffic", 0).
|
||||||
UpdateQuickly()
|
UpdateQuickly()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ func TestServerDAO_FindAllEnabledServersWithDomain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerDAO_UpdateServerBandwidthLimitStatus(t *testing.T) {
|
func TestServerDAO_UpdateServerTrafficLimitStatus(t *testing.T) {
|
||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
var tx *dbs.Tx
|
var tx *dbs.Tx
|
||||||
@@ -172,7 +172,7 @@ func TestServerDAO_UpdateServerBandwidthLimitStatus(t *testing.T) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
t.Log(time.Since(before).Seconds()*1000, "ms")
|
t.Log(time.Since(before).Seconds()*1000, "ms")
|
||||||
}()
|
}()
|
||||||
err := NewServerDAO().UpdateServerBandwidthLimitStatus(tx, &serverconfigs.BandwidthLimitConfig{
|
err := NewServerDAO().UpdateServerTrafficLimitStatus(tx, &serverconfigs.TrafficLimitConfig{
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
DailySize: &shared.SizeCapacity{Count: 1, Unit: "mb"},
|
DailySize: &shared.SizeCapacity{Count: 1, Unit: "mb"},
|
||||||
MonthlySize: &shared.SizeCapacity{Count: 10, Unit: "mb"},
|
MonthlySize: &shared.SizeCapacity{Count: 10, Unit: "mb"},
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ type Server struct {
|
|||||||
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
|
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
|
||||||
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
|
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
|
||||||
SupportCNAME uint8 `field:"supportCNAME"` // 允许CNAME不在域名名单
|
SupportCNAME uint8 `field:"supportCNAME"` // 允许CNAME不在域名名单
|
||||||
BandwidthLimit string `field:"bandwidthLimit"` // 带宽限制
|
TrafficLimit string `field:"trafficLimit"` // 流量限制
|
||||||
TotalBandwidth float64 `field:"totalBandwidth"` // 总带宽用量(单位GB)
|
TotalTraffic float64 `field:"totalTraffic"` // 总流量用量(单位GB)
|
||||||
BandwidthLimitStatus string `field:"bandwidthLimitStatus"` // 带宽限制状态
|
TrafficLimitStatus string `field:"trafficLimitStatus"` // 流量限制状态
|
||||||
UserPlanId uint32 `field:"userPlanId"` // 所属套餐ID
|
UserPlanId uint32 `field:"userPlanId"` // 所属套餐ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +73,9 @@ type ServerOperator struct {
|
|||||||
TcpPorts interface{} // 所包含TCP端口
|
TcpPorts interface{} // 所包含TCP端口
|
||||||
UdpPorts interface{} // 所包含UDP端口
|
UdpPorts interface{} // 所包含UDP端口
|
||||||
SupportCNAME interface{} // 允许CNAME不在域名名单
|
SupportCNAME interface{} // 允许CNAME不在域名名单
|
||||||
BandwidthLimit interface{} // 带宽限制
|
TrafficLimit interface{} // 流量限制
|
||||||
TotalBandwidth interface{} // 总带宽用量(单位GB)
|
TotalTraffic interface{} // 总流量用量(单位GB)
|
||||||
BandwidthLimitStatus interface{} // 带宽限制状态
|
TrafficLimitStatus interface{} // 流量限制状态
|
||||||
UserPlanId interface{} // 所属套餐ID
|
UserPlanId interface{} // 所属套餐ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1711,8 +1711,8 @@ func (this *ServerService) PurgeServerCache(ctx context.Context, req *pb.PurgeSe
|
|||||||
return purgeResponse, nil
|
return purgeResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindEnabledServerBandwidthLimit 查找带宽限制
|
// FindEnabledServerTrafficLimit 查找流量限制
|
||||||
func (this *ServerService) FindEnabledServerBandwidthLimit(ctx context.Context, req *pb.FindEnabledServerBandwidthLimitRequest) (*pb.FindEnabledServerBandwidthLimitResponse, error) {
|
func (this *ServerService) FindEnabledServerTrafficLimit(ctx context.Context, req *pb.FindEnabledServerTrafficLimitRequest) (*pb.FindEnabledServerTrafficLimitResponse, error) {
|
||||||
_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1721,7 +1721,7 @@ func (this *ServerService) FindEnabledServerBandwidthLimit(ctx context.Context,
|
|||||||
// TODO 检查用户权限
|
// TODO 检查用户权限
|
||||||
|
|
||||||
var tx = this.NullTx()
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1729,26 +1729,26 @@ func (this *ServerService) FindEnabledServerBandwidthLimit(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &pb.FindEnabledServerBandwidthLimitResponse{
|
return &pb.FindEnabledServerTrafficLimitResponse{
|
||||||
BandwidthLimitJSON: limitConfigJSON,
|
TrafficLimitJSON: limitConfigJSON,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateServerBandwidthLimit 设置带宽限制
|
// UpdateServerTrafficLimit 设置流量限制
|
||||||
func (this *ServerService) UpdateServerBandwidthLimit(ctx context.Context, req *pb.UpdateServerBandwidthLimitRequest) (*pb.RPCSuccess, error) {
|
func (this *ServerService) UpdateServerTrafficLimit(ctx context.Context, req *pb.UpdateServerTrafficLimitRequest) (*pb.RPCSuccess, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
var config = &serverconfigs.BandwidthLimitConfig{}
|
var config = &serverconfigs.TrafficLimitConfig{}
|
||||||
err = json.Unmarshal(req.BandwidthLimitJSON, config)
|
err = json.Unmarshal(req.TrafficLimitJSON, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.SharedServerDAO.UpdateServerBandwidthLimitConfig(tx, req.ServerId, config)
|
err = models.SharedServerDAO.UpdateServerTrafficLimitConfig(tx, req.ServerId, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1814,7 +1814,5 @@ func (this *ServerService) UpdateServerUserPlan(ctx context.Context, req *pb.Upd
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user