mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	商业版增加UAM功能
This commit is contained in:
		@@ -3,6 +3,7 @@ package models
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
 | 
						teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
 | 
						"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
 | 
				
			||||||
	dbutils "github.com/TeaOSLab/EdgeAPI/internal/db/utils"
 | 
						dbutils "github.com/TeaOSLab/EdgeAPI/internal/db/utils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
						"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
				
			||||||
@@ -1130,6 +1131,18 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// UAM
 | 
				
			||||||
 | 
						if teaconst.IsPlus && IsNotNull(server.Uam) {
 | 
				
			||||||
 | 
							var uamConfig = &serverconfigs.UAMConfig{}
 | 
				
			||||||
 | 
							err = json.Unmarshal(server.Uam, uamConfig)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if uamConfig.IsOn {
 | 
				
			||||||
 | 
								config.UAM = uamConfig
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if cacheMap != nil {
 | 
						if cacheMap != nil {
 | 
				
			||||||
		cacheMap.Put(cacheKey, config)
 | 
							cacheMap.Put(cacheKey, config)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -2276,6 +2289,35 @@ func (this *ServerDAO) FindServerLastUserPlanIdAndUserId(tx *dbs.Tx, serverId in
 | 
				
			|||||||
	return int64(one.(*Server).LastUserPlanId), int64(one.(*Server).UserId), nil
 | 
						return int64(one.(*Server).LastUserPlanId), int64(one.(*Server).UserId), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateServerUAM 开启UAM
 | 
				
			||||||
 | 
					func (this *ServerDAO) UpdateServerUAM(tx *dbs.Tx, serverId int64, uamConfig *serverconfigs.UAMConfig) error {
 | 
				
			||||||
 | 
						if uamConfig == nil {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						configJSON, err := json.Marshal(uamConfig)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = this.Query(tx).
 | 
				
			||||||
 | 
							Pk(serverId).
 | 
				
			||||||
 | 
							Set("uam", configJSON).
 | 
				
			||||||
 | 
							UpdateQuickly()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return this.NotifyUpdate(tx, serverId)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FindServerUAM 查找服务的UAM配置
 | 
				
			||||||
 | 
					func (this *ServerDAO) FindServerUAM(tx *dbs.Tx, serverId int64) ([]byte, error) {
 | 
				
			||||||
 | 
						return this.Query(tx).
 | 
				
			||||||
 | 
							Pk(serverId).
 | 
				
			||||||
 | 
							Result("uam").
 | 
				
			||||||
 | 
							FindJSONCol()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NotifyUpdate 同步集群
 | 
					// NotifyUpdate 同步集群
 | 
				
			||||||
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
 | 
					func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
 | 
				
			||||||
	// 创建任务
 | 
						// 创建任务
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,7 @@ type Server struct {
 | 
				
			|||||||
	TotalTraffic        float64  `field:"totalTraffic"`        // 总流量
 | 
						TotalTraffic        float64  `field:"totalTraffic"`        // 总流量
 | 
				
			||||||
	UserPlanId          uint32   `field:"userPlanId"`          // 所属套餐ID
 | 
						UserPlanId          uint32   `field:"userPlanId"`          // 所属套餐ID
 | 
				
			||||||
	LastUserPlanId      uint32   `field:"lastUserPlanId"`      // 上一次使用的套餐
 | 
						LastUserPlanId      uint32   `field:"lastUserPlanId"`      // 上一次使用的套餐
 | 
				
			||||||
 | 
						Uam                 dbs.JSON `field:"uam"`                 // UAM设置
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ServerOperator struct {
 | 
					type ServerOperator struct {
 | 
				
			||||||
@@ -91,6 +92,7 @@ type ServerOperator struct {
 | 
				
			|||||||
	TotalTraffic        interface{} // 总流量
 | 
						TotalTraffic        interface{} // 总流量
 | 
				
			||||||
	UserPlanId          interface{} // 所属套餐ID
 | 
						UserPlanId          interface{} // 所属套餐ID
 | 
				
			||||||
	LastUserPlanId      interface{} // 上一次使用的套餐
 | 
						LastUserPlanId      interface{} // 上一次使用的套餐
 | 
				
			||||||
 | 
						Uam                 interface{} // UAM设置
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewServerOperator() *ServerOperator {
 | 
					func NewServerOperator() *ServerOperator {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								internal/rpc/services/service_server_community.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								internal/rpc/services/service_server_community.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
				
			||||||
 | 
					//go:build !plus
 | 
				
			||||||
 | 
					// +build !plus
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package services
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateServerUAM 修改服务UAM设置
 | 
				
			||||||
 | 
					func (this *ServerService) UpdateServerUAM(ctx context.Context, req *pb.UpdateServerUAMRequest) (*pb.RPCSuccess, error) {
 | 
				
			||||||
 | 
						return this.Success()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FindEnabledServerUAM 查找服务UAM设置
 | 
				
			||||||
 | 
					func (this *ServerService) FindEnabledServerUAM(ctx context.Context, req *pb.FindEnabledServerUAMRequest) (*pb.FindEnabledServerUAMResponse, error) {
 | 
				
			||||||
 | 
						return &pb.FindEnabledServerUAMResponse{
 | 
				
			||||||
 | 
							UamJSON: nil,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user