From 542c609d60dc6d74fd9bd0da358f6511dad2da42 Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Mon, 12 Jan 2026 19:08:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A7=9F=E6=88=B7ID=E5=92=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=80=85=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=BAinterface{}=EF=BC=8C=E4=BC=98=E5=8C=96=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E5=AD=98=E5=82=A8=E5=AE=B9=E9=87=8F=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/dto/file_dto.go | 8 ++++---- model/dto/tenant_oss_total.go | 2 +- service/file_service.go | 15 ++++++++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/model/dto/file_dto.go b/model/dto/file_dto.go index f9c495c..8df638f 100644 --- a/model/dto/file_dto.go +++ b/model/dto/file_dto.go @@ -18,8 +18,8 @@ type UploadFileRes struct { } type TenantOssTotal struct { - TenantId string `json:"tenantId"` - UsedOssSize int `json:"usedOssSize"` - TotalOssSize int `json:"totalOssSize"` - Updater string `json:"updater"` + TenantId interface{} `json:"tenantId"` + UsedOssSize int `json:"usedOssSize"` + TotalOssSize int `json:"totalOssSize"` + Updater interface{} `json:"updater"` } diff --git a/model/dto/tenant_oss_total.go b/model/dto/tenant_oss_total.go index c355acc..e70549c 100644 --- a/model/dto/tenant_oss_total.go +++ b/model/dto/tenant_oss_total.go @@ -8,7 +8,7 @@ import ( // GetByTenantIdReq 根据租户id获取存储总量请求 type GetByTenantIdReq struct { g.Meta `path:"/GetOneByTenantId" method:"get" tags:"租户存储总量管理" summary:"获取存储总量" dc:"获取存储总量"` - TenantId string `json:"tenantId" v:"required#租户id不能为空"` + TenantId interface{} `json:"tenantId" v:"required#租户id不能为空"` } // GetByTenantIdRes 根据租户id获取存储总量响应 diff --git a/service/file_service.go b/service/file_service.go index 19c2fc1..3e8d622 100644 --- a/service/file_service.go +++ b/service/file_service.go @@ -32,7 +32,7 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto glog.Errorf(ctx, "获取用户信息失败: %v", err) return } - tenantId := gconv.String(user.TenantId) + tenantId := user.TenantId // 获取redis-租户存储容量总数key tenantOssTotalKey := fmt.Sprintf(consts.TenantOssTotalKey, gconv.String(user.TenantId)) // 获取redis-租户存储-锁key @@ -49,19 +49,20 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto if g.IsEmpty(get) { //查询数据库-获取租户存储容量总数 getByTenantIdReq := &dto.GetByTenantIdReq{ - TenantId: gconv.String(user.TenantId), + TenantId: user.TenantId, } - tenantOssTotal, err := TenantOssTotal.GetOneByTenantId(ctx, getByTenantIdReq) + tenantOssTotalRes, err := TenantOssTotal.GetOneByTenantId(ctx, getByTenantIdReq) if err != nil { glog.Errorf(ctx, "查询数据库-获取租户存储容量总数失败: %v", err) return err } - if tenantOssTotal.Id.IsZero() { + if tenantOssTotalRes == nil || tenantOssTotalRes.TenantOssTotal == nil || g.IsEmpty(tenantOssTotalRes.Id) || tenantOssTotalRes.Id.IsZero() { + // 数据库中没有该租户的记录,创建默认配置 tenantOssTotalEntity.TenantId = user.TenantId tenantOssTotalEntity.UsedOssSize = 0 tenantOssTotalEntity.TotalOssSize = g.Cfg().MustGet(ctx, "oss.capacitySize").Int() * 1024 * 1024 } else { - tenantOssTotalEntity = tenantOssTotal.TenantOssTotal + tenantOssTotalEntity = tenantOssTotalRes.TenantOssTotal } } else { // 反序列化-redis获取租户存储容量总数 @@ -70,7 +71,7 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto return err } } - tenantId = gconv.String(tenantOssTotalEntity.TenantId) + tenantId = tenantOssTotalEntity.TenantId fileSize = tenantOssTotalEntity.UsedOssSize + fileSize totalFileSize = tenantOssTotalEntity.TotalOssSize // 设置redis-租户存储容量总数 @@ -78,7 +79,7 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto TenantId: tenantId, UsedOssSize: fileSize, TotalOssSize: totalFileSize, - Updater: gconv.String(user.UserName), + Updater: user.UserName, } // 修改redis-租户存储容量总数 超时时间10分钟 if err = redis.RedisClient.SetEX(ctx, tenantOssTotalKey, tenantOssTotalKeyMap, gconv.Int64(time.Minute*10)); err != nil {