39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"oss/consts"
|
|
"oss/model/dto"
|
|
"oss/model/entity"
|
|
|
|
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var TenantOssTotal = &tenantOssTotal{}
|
|
|
|
type tenantOssTotal struct{}
|
|
|
|
// SaveOrUpdate 增加或更新
|
|
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
|
|
}
|
|
r, err := gfdb.DB(ctx).Model(ctx, consts.TableNameTenantOssTotal).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) {
|
|
model := gfdb.DB(ctx).Model(ctx, consts.TableNameTenantOssTotal).Where(entity.TenantOssCol.TenantId, req.TenantId)
|
|
record, err := model.One()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = record.Struct(&res)
|
|
return
|
|
}
|