mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	用户看板增加带宽百分位
This commit is contained in:
		@@ -172,6 +172,24 @@ func (this *SysSettingDAO) ReadAdminUIConfig(tx *dbs.Tx, cacheMap *utils.CacheMa
 | 
				
			|||||||
	return &systemconfigs.AdminUIConfig{}, nil
 | 
						return &systemconfigs.AdminUIConfig{}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ReadUserUIConfig 读取用户UI配置
 | 
				
			||||||
 | 
					func (this *SysSettingDAO) ReadUserUIConfig(tx *dbs.Tx) (*systemconfigs.UserUIConfig, error) {
 | 
				
			||||||
 | 
						valueJSON, err := this.ReadSetting(tx, systemconfigs.SettingCodeUserUIConfig)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(valueJSON) == 0 {
 | 
				
			||||||
 | 
							return systemconfigs.DefaultUserUIConfig(), nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var config = systemconfigs.DefaultUserUIConfig()
 | 
				
			||||||
 | 
						err = json.Unmarshal(valueJSON, config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return config, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NotifyUpdate 通知更改
 | 
					// NotifyUpdate 通知更改
 | 
				
			||||||
func (this *SysSettingDAO) NotifyUpdate(tx *dbs.Tx, code string) error {
 | 
					func (this *SysSettingDAO) NotifyUpdate(tx *dbs.Tx, code string) error {
 | 
				
			||||||
	switch code {
 | 
						switch code {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -483,8 +483,16 @@ func (this *UserService) ComposeUserDashboard(ctx context.Context, req *pb.Compo
 | 
				
			|||||||
	var dailyTrafficStats = []*pb.ComposeUserDashboardResponse_DailyTrafficStat{}
 | 
						var dailyTrafficStats = []*pb.ComposeUserDashboardResponse_DailyTrafficStat{}
 | 
				
			||||||
	var dailyPeekBandwidthStats = []*pb.ComposeUserDashboardResponse_DailyPeekBandwidthStat{}
 | 
						var dailyPeekBandwidthStats = []*pb.ComposeUserDashboardResponse_DailyPeekBandwidthStat{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var dayFrom = ""
 | 
				
			||||||
 | 
						var dayTo = ""
 | 
				
			||||||
	for i := 30; i >= 0; i-- {
 | 
						for i := 30; i >= 0; i-- {
 | 
				
			||||||
		var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -i))
 | 
							var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -i))
 | 
				
			||||||
 | 
							if len(dayFrom) == 0 {
 | 
				
			||||||
 | 
								dayFrom = day
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if len(dayTo) == 0 || day > dayTo {
 | 
				
			||||||
 | 
								dayTo = day
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 流量
 | 
							// 流量
 | 
				
			||||||
		trafficBytes, err := models.SharedServerDailyStatDAO.SumUserDaily(tx, req.UserId, 0, day)
 | 
							trafficBytes, err := models.SharedServerDailyStatDAO.SumUserDaily(tx, req.UserId, 0, day)
 | 
				
			||||||
@@ -505,8 +513,7 @@ func (this *UserService) ComposeUserDashboard(ctx context.Context, req *pb.Compo
 | 
				
			|||||||
		dailyTrafficStats = append(dailyTrafficStats, &pb.ComposeUserDashboardResponse_DailyTrafficStat{Day: day, Bytes: trafficBytes})
 | 
							dailyTrafficStats = append(dailyTrafficStats, &pb.ComposeUserDashboardResponse_DailyTrafficStat{Day: day, Bytes: trafficBytes})
 | 
				
			||||||
		dailyPeekBandwidthStats = append(dailyPeekBandwidthStats, &pb.ComposeUserDashboardResponse_DailyPeekBandwidthStat{Day: day, Bytes: peekBandwidthBytes})
 | 
							dailyPeekBandwidthStats = append(dailyPeekBandwidthStats, &pb.ComposeUserDashboardResponse_DailyPeekBandwidthStat{Day: day, Bytes: peekBandwidthBytes})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						var result = &pb.ComposeUserDashboardResponse{
 | 
				
			||||||
	return &pb.ComposeUserDashboardResponse{
 | 
					 | 
				
			||||||
		CountServers:              countServers,
 | 
							CountServers:              countServers,
 | 
				
			||||||
		MonthlyTrafficBytes:       monthlyTrafficBytes,
 | 
							MonthlyTrafficBytes:       monthlyTrafficBytes,
 | 
				
			||||||
		MonthlyPeekBandwidthBytes: monthlyPeekBandwidthBytes,
 | 
							MonthlyPeekBandwidthBytes: monthlyPeekBandwidthBytes,
 | 
				
			||||||
@@ -514,7 +521,24 @@ func (this *UserService) ComposeUserDashboard(ctx context.Context, req *pb.Compo
 | 
				
			|||||||
		DailyPeekBandwidthBytes:   dailyPeekBandwidthBytes,
 | 
							DailyPeekBandwidthBytes:   dailyPeekBandwidthBytes,
 | 
				
			||||||
		DailyTrafficStats:         dailyTrafficStats,
 | 
							DailyTrafficStats:         dailyTrafficStats,
 | 
				
			||||||
		DailyPeekBandwidthStats:   dailyPeekBandwidthStats,
 | 
							DailyPeekBandwidthStats:   dailyPeekBandwidthStats,
 | 
				
			||||||
	}, nil
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 带宽百分位
 | 
				
			||||||
 | 
						var bandwidthPercentile = systemconfigs.DefaultBandwidthPercentile
 | 
				
			||||||
 | 
						userConfig, _ := models.SharedSysSettingDAO.ReadUserUIConfig(tx)
 | 
				
			||||||
 | 
						if userConfig != nil && userConfig.TrafficStats.BandwidthPercentile > 0 {
 | 
				
			||||||
 | 
							bandwidthPercentile = userConfig.TrafficStats.BandwidthPercentile
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						result.BandwidthPercentile = bandwidthPercentile
 | 
				
			||||||
 | 
						stat, err := models.SharedUserBandwidthStatDAO.FindPercentileBetweenDays(tx, req.UserId, 0, dayFrom, dayTo, bandwidthPercentile)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if stat != nil {
 | 
				
			||||||
 | 
							result.BandwidthPercentileBits = int64(stat.Bytes) * 8
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FindUserNodeClusterId 获取用户所在的集群ID
 | 
					// FindUserNodeClusterId 获取用户所在的集群ID
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user