From 74cadf6e5b430124e58ff20f8ca8ac6aa6cbb729 Mon Sep 17 00:00:00 2001 From: Hiven Date: Thu, 10 Aug 2023 16:13:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/file/upload.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/utils/file/upload.go b/utils/file/upload.go index 5665bf10..d19752e7 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -67,8 +67,8 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er var uploadBaseRes = UploadBaseRes{} err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error { - resourceModelTS := gmodel.NewFsResourceModel(tx) - resourceInfo, err := resourceModelTS.FindOneById(upload.Ctx, resourceId) + var resourceInfo *gmodel.FsResource + err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error if err == nil && resourceInfo.ResourceId != "" { uploadBaseRes.Status = 1 uploadBaseRes.ResourceId = resourceId @@ -108,7 +108,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now() - _, err = resourceModelTS.Create(upload.Ctx, &gmodel.FsResource{ + err = tx.Create(&gmodel.FsResource{ ResourceId: resourceId, UserId: &req.UserId, GuestId: &req.GuestId, @@ -119,7 +119,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er Metadata: &req.Metadata, ApiType: &apiType, BucketName: bucketName, - }) + }).Error if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql") return err @@ -163,10 +163,11 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro var resourceId string = req.FileHash var uploadBaseRes = UploadBaseRes{} - ctx := upload.Ctx - err := upload.MysqlConn.Transaction(func(connGorm *gorm.DB) error { - resourceModelTS := gmodel.NewFsResourceModel(connGorm) - resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId) + + err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error { + var resourceInfo *gmodel.FsResource + err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error + // resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId) if err == nil && resourceInfo.ResourceId != "" { uploadBaseRes.Status = 1 uploadBaseRes.ResourceId = resourceId @@ -200,7 +201,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now() - _, err = resourceModelTS.Create(ctx, &gmodel.FsResource{ + err = tx.Create(&gmodel.FsResource{ ResourceId: resourceId, UserId: &req.UserId, GuestId: &req.GuestId, @@ -211,7 +212,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro Metadata: &req.Metadata, ApiType: &apiType, BucketName: bucketName, - }) + }).Error if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql") return err