From 80a9517a1ff76189b54075b5148d91991b3be110 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 22 Aug 2023 10:48:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:base=E4=B8=8A=E4=BC=A0=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/internal/types/types.go | 1 + server_api/upload.api | 1 + utils/file/upload.go | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index 8aa84e78..4d077417 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -22,6 +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"` // 强制更新 } type UploadLogoReq struct { diff --git a/server_api/upload.api b/server_api/upload.api index 7aaa9ec0..c4af90f2 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -67,6 +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"` // 强制更新 } ) diff --git a/utils/file/upload.go b/utils/file/upload.go index d561ae28..e50c0070 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -22,6 +22,7 @@ type Upload struct { } type UploadBaseReq struct { + Refresh bool Source string FileHash string FileData string @@ -67,10 +68,14 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er var resourceId string = req.FileHash var uploadBaseRes = UploadBaseRes{} - err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error { + err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) { var resourceInfo *gmodel.FsResource - err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error - if err == nil && resourceInfo.ResourceId != "" { + + if !req.Refresh { + err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error + } + + if !req.Refresh && err == nil && resourceInfo.ResourceId != "" { uploadBaseRes.Status = 1 uploadBaseRes.ResourceId = resourceId uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl From 462ac4915bc3ec9463c149e4a7347794fb687eb2 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 22 Aug 2023 10:54:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:base=E4=B8=8A=E4=BC=A0=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/product/internal/logic/savedesignlogic.go | 9 +++++---- .../internal/logic/cartaddlogic.go | 5 +++-- .../internal/logic/createorderlogic.go | 6 +++--- server/upload/internal/logic/uploadfilefrontendlogic.go | 2 +- server/upload/internal/types/types.go | 2 +- server_api/upload.api | 2 +- utils/file/upload.go | 4 ++-- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/server/product/internal/logic/savedesignlogic.go b/server/product/internal/logic/savedesignlogic.go index 21d2c226..55fa1322 100644 --- a/server/product/internal/logic/savedesignlogic.go +++ b/server/product/internal/logic/savedesignlogic.go @@ -10,9 +10,6 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/encryption_decryption" "fusenapi/utils/id_generator" - "github.com/google/uuid" - "github.com/nfnt/resize" - "gorm.io/gorm" "image" "image/gif" "image/jpeg" @@ -22,6 +19,10 @@ import ( "path" "time" + "github.com/google/uuid" + "github.com/nfnt/resize" + "gorm.io/gorm" + "context" "fusenapi/server/product/internal/svc" @@ -77,7 +78,7 @@ func (l *SaveDesignLogic) SaveDesign(req *types.SaveDesignReq, userinfo *auth.Us } infoBytes, _ := json.Marshal(postInfo.Data) info := string(infoBytes) - now := time.Now() + now := time.Now().UTC() logoColorBytes, _ := json.Marshal(postInfo.Data.Logo.Colors) logoColor := string(logoColorBytes) saveData := gmodel.FsProductDesign{ diff --git a/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go b/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go index 50248582..54d345bf 100644 --- a/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go @@ -5,10 +5,11 @@ import ( "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" - "gorm.io/gorm" "strings" "time" + "gorm.io/gorm" + "context" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -101,7 +102,7 @@ func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) ( return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get cart info") } now := time.Now().Unix() - nowTime := time.Now() + nowTime := time.Now().UTC() data := gmodel.FsCart{ UserId: &userinfo.UserId, ProductId: productPriceInfo.ProductId, diff --git a/server/shopping-cart-confirmation/internal/logic/createorderlogic.go b/server/shopping-cart-confirmation/internal/logic/createorderlogic.go index 21823c98..55c54953 100644 --- a/server/shopping-cart-confirmation/internal/logic/createorderlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/createorderlogic.go @@ -1,7 +1,6 @@ package logic import ( - "errors" "fmt" "fusenapi/model/gmodel" "fusenapi/utils/auth" @@ -9,11 +8,12 @@ import ( "fusenapi/utils/format" "fusenapi/utils/id_generator" "fusenapi/utils/step_price" - "gorm.io/gorm" "math" "strings" "time" + "gorm.io/gorm" + "context" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -109,7 +109,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth for _, cart := range cartList { priceIndex, ok := mapPrice[*cart.PriceId] if !ok { - return errors.New(fmt.Sprintf("price info is not exists,id = %d", *cart.PriceId)) + return fmt.Errorf("price info is not exists,id = %d", *cart.PriceId) } //订单详情模板数据 orderDetailTemplateSn, err := id_generator.GenSnowFlakeId() diff --git a/server/upload/internal/logic/uploadfilefrontendlogic.go b/server/upload/internal/logic/uploadfilefrontendlogic.go index 7789c86f..ed76bc82 100644 --- a/server/upload/internal/logic/uploadfilefrontendlogic.go +++ b/server/upload/internal/logic/uploadfilefrontendlogic.go @@ -60,7 +60,7 @@ func (l *UploadFileFrontendLogic) UploadFileFrontend(req *types.RequestUploadFil return resp.SetStatus(basic.CodeS3CategoryErr) } - now := time.Now() + now := time.Now().UTC() category := format.TypeCategory(req.Category) ObjectKey := aws.String(format.FormatS3KeyName( keytype, diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index 4d077417..5d38ea5a 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -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"` // 强制更新 + Refresh bool `form:"refresh,optional"` // 强制更新 } type UploadLogoReq struct { diff --git a/server_api/upload.api b/server_api/upload.api index c4af90f2..47d17443 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -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"` // 强制更新 + Refresh bool `form:"refresh,optional"` // 强制更新 } ) diff --git a/utils/file/upload.go b/utils/file/upload.go index e50c0070..04fe7c69 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -113,7 +113,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er uploadBaseRes.ResourceId = resourceId uploadBaseRes.ResourceUrl = url var version string = "0.0.1" - var nowTime = time.Now() + var nowTime = time.Now().UTC() err = tx.Create(&gmodel.FsResource{ ResourceId: resourceId, UserId: &req.UserId, @@ -207,7 +207,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro uploadBaseRes.ResourceId = resourceId uploadBaseRes.ResourceUrl = url var version string = "0.0.1" - var nowTime = time.Now() + var nowTime = time.Now().UTC() err = tx.Create(&gmodel.FsResource{ ResourceId: resourceId, UserId: &req.UserId,