fix:裁剪业务逻辑调整

This commit is contained in:
momo 2023-08-23 11:41:02 +08:00
parent 7f23905e76
commit 1e25f79d4a
4 changed files with 36 additions and 18 deletions

View File

@ -78,6 +78,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
UserId: userId,
GuestId: guestId,
Source: req.Source,
Refresh: req.Refresh,
})
if err != nil {

View File

@ -22,7 +22,7 @@ type UploadFileBaseReq struct {
GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
Source string `form:"source"` // 上传来源
Refresh bool `form:"refresh,optional"` // 强制更新
Refresh int64 `form:"refresh,optional"` // 强制更新 10
}
type UploadLogoReq struct {

View File

@ -67,7 +67,7 @@ type (
GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
Source string `form:"source"` // 上传来源
Refresh bool `form:"refresh,optional"` // 强制更新
Refresh int64 `form:"refresh,optional"` // 强制更新 10
}
)

View File

@ -22,7 +22,7 @@ type Upload struct {
}
type UploadBaseReq struct {
Refresh bool
Refresh int64
Source string
FileHash string
FileData string
@ -71,11 +71,11 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) {
var resourceInfo *gmodel.FsResource
if !req.Refresh {
if req.Refresh == 0 {
err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
}
if !req.Refresh && err == nil && resourceInfo.ResourceId != "" {
if req.Refresh == 0 && err == nil && resourceInfo.ResourceId != "" {
uploadBaseRes.Status = 1
uploadBaseRes.ResourceId = resourceId
uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl
@ -114,6 +114,21 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
uploadBaseRes.ResourceUrl = url
var version string = "0.0.1"
var nowTime = time.Now().UTC()
if req.Refresh == 1 {
err = tx.Save(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
GuestId: &req.GuestId,
ResourceType: &contentType,
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
}).Error
} else {
err = tx.Create(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
@ -127,6 +142,8 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
BucketName: bucketName,
Source: &req.Source,
}).Error
}
if err != nil {
logx.Errorf("err:%+vdesc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
return err