feat: 添加数据库配置和相关模型定义
This commit is contained in:
@@ -10,12 +10,13 @@ import (
|
||||
"gitea.com/red-future/common/utils"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// GetTenantInfo 获取租户信息
|
||||
// 优先从 token 获取,失败则从请求参数 customerServiceId 查询 customer_service_account 表
|
||||
func GetTenantInfo(ctx context.Context) (user beans.User, err error) {
|
||||
func GetTenantInfo(ctx context.Context) (user *beans.User, err error) {
|
||||
// 1. 优先从 token 获取
|
||||
user, err = utils.GetUserInfo(ctx)
|
||||
if err == nil {
|
||||
@@ -51,7 +52,7 @@ func GetTenantInfo(ctx context.Context) (user beans.User, err error) {
|
||||
cacheKey := fmt.Sprintf("tenant:account:%s", accountName)
|
||||
cached, cacheErr := redis.RedisClient().Get(ctx, cacheKey)
|
||||
if cacheErr == nil && !g.IsEmpty(cached) {
|
||||
user.TenantId = cached.Interface()
|
||||
user.TenantId = gconv.Uint64(cached.Interface())
|
||||
user.UserName = accountName
|
||||
return user, nil
|
||||
}
|
||||
@@ -59,7 +60,7 @@ func GetTenantInfo(ctx context.Context) (user beans.User, err error) {
|
||||
// 4. 缓存未命中,查询 customer_service_account 表
|
||||
filter := bson.M{"accountName": accountName, "isDeleted": false}
|
||||
var account struct {
|
||||
TenantId interface{} `bson:"tenantId"`
|
||||
TenantId uint64 `bson:"tenantId"`
|
||||
}
|
||||
if findErr := mongo.GetDB().Collection("customer_service_account").FindOne(ctx, filter).Decode(&account); findErr != nil {
|
||||
return user, gerror.Newf("通过 accountName 查询租户失败: %v", findErr)
|
||||
|
||||
Reference in New Issue
Block a user