文件存储-增加文件上传记录接口,增加定时同步租户文件存储容量信息接口
This commit is contained in:
40
dao/tenant_oss_total.go
Normal file
40
dao/tenant_oss_total.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitee.com/red-future---jilin-g/common/mongo"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"oss/consts"
|
||||
"oss/model/entity"
|
||||
)
|
||||
|
||||
var TenantOssTotal = &tenantOssTotal{}
|
||||
|
||||
type tenantOssTotal struct{}
|
||||
|
||||
// Insert 插入
|
||||
func (d *tenantOssTotal) Insert(ctx context.Context, entity []interface{}) (err error) {
|
||||
_, err = mongo.Insert(ctx, entity, consts.TenantOssTotalCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// SaveOrUpdate 增加或更新
|
||||
func (d *tenantOssTotal) SaveOrUpdate(ctx context.Context, filterData []*entity.TenantOssTotal, updateData []*entity.TenantOssTotal) (err error) {
|
||||
if !g.IsEmpty(updateData) {
|
||||
var filter, update []bson.M
|
||||
for i, v := range filterData {
|
||||
filter = append(filter, bson.M{"tenantId": v.TenantId})
|
||||
update = append(update, bson.M{"$set": bson.M{"usedOssSize": updateData[i].UsedOssSize, "totalOssSize": updateData[i].TotalOssSize}})
|
||||
}
|
||||
_, err = mongo.SaveOrUpdate(ctx, filter, update, consts.TenantOssTotalCollection)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *tenantOssTotal) GetOneByTenantId(ctx context.Context, tenantId string) (e *entity.TenantOssTotal, err error) {
|
||||
filter := bson.M{"tenantId": tenantId}
|
||||
e = &entity.TenantOssTotal{}
|
||||
err = mongo.FindOne(ctx, filter, e, consts.TenantOssTotalCollection)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user