refactor: 移除业务ID字段并优化DAO层实现
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
)
|
||||
|
||||
var File = &file{}
|
||||
@@ -16,11 +15,14 @@ var File = &file{}
|
||||
type file struct{}
|
||||
|
||||
// Insert 插入
|
||||
func (d *file) Insert(ctx context.Context, req *dto.UploadFile) (res *entity.File, err error) {
|
||||
func (d *file) Insert(ctx context.Context, req *dto.UploadFile) (id int64, err error) {
|
||||
var res *entity.File
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
res.Bid = guid.S()
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.FileCollection).Insert(&res)
|
||||
return
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.FileCollection).Insert(&res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ import (
|
||||
"oss/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var TenantOssTotal = &tenantOssTotal{}
|
||||
@@ -17,25 +15,16 @@ var TenantOssTotal = &tenantOssTotal{}
|
||||
type tenantOssTotal struct{}
|
||||
|
||||
// SaveOrUpdate 增加或更新
|
||||
func (d *tenantOssTotal) SaveOrUpdate(ctx context.Context, updateData []*dto.UpdateUsedOssReq) (err error) {
|
||||
if !g.IsEmpty(updateData) {
|
||||
data := make([]gdb.Map, 0, len(updateData))
|
||||
for _, v := range updateData {
|
||||
data = append(data, gdb.Map{
|
||||
entity.TenantOssCol.Bid: guid.S(),
|
||||
entity.TenantOssCol.TenantId: v.TenantId,
|
||||
entity.TenantOssCol.UsedOssSize: v.UsedOssSize,
|
||||
entity.TenantOssCol.TotalOssSize: v.TotalOssSize,
|
||||
entity.TenantOssCol.Creator: v.Updater,
|
||||
entity.TenantOssCol.Updater: v.Updater,
|
||||
})
|
||||
}
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.TenantOssTotalCollection).Data(data).OnConflict(entity.TenantOssCol.TenantId).Save()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (d *tenantOssTotal) SaveOrUpdate(ctx context.Context, updateData []*dto.UpdateUsedOssReq) (rows int64, err error) {
|
||||
var res []*entity.TenantOssTotal
|
||||
if err = gconv.Structs(updateData, &res); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.TenantOssTotalCollection).Data(res).OnConflict(entity.TenantOssCol.TenantId).Save()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
func (d *tenantOssTotal) GetOneByTenantId(ctx context.Context, req *dto.GetByTenantIdReq) (res *entity.TenantOssTotal, err error) {
|
||||
|
||||
Reference in New Issue
Block a user