From cb682a7ac0d01959399614d88be70124c32477ce Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 18:28:19 +0800 Subject: [PATCH 1/6] fix --- model/gmodel/fs_change_code_gen.go | 1 + model/gmodel/fs_product_gen.go | 1 + model/gmodel/fs_quotation_gen.go | 1 + model/gmodel/fs_resource_gen.go | 3 +-- server/product/internal/logic/getrecommandproductlistlogic.go | 1 + server/product/internal/logic/gettagproductlistlogic.go | 1 + .../internal/logic/homepagerecommendproductlistlogic.go | 1 + server/product/internal/types/types.go | 3 +++ server_api/product.api | 3 +++ 9 files changed, 13 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_change_code_gen.go b/model/gmodel/fs_change_code_gen.go index 6a58a515..73f2ea66 100644 --- a/model/gmodel/fs_change_code_gen.go +++ b/model/gmodel/fs_change_code_gen.go @@ -11,6 +11,7 @@ type FsChangeCode struct { Code *string `gorm:"default:'';" json:"code"` // CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间 IsUse *int64 `gorm:"default:0;" json:"is_use"` // 是否使用 1已使用 0未使用 + Metadata *[]byte `gorm:"default:'';" json:"metadata"` // } type FsChangeCodeModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_gen.go b/model/gmodel/fs_product_gen.go index f2b22738..52b458ba 100644 --- a/model/gmodel/fs_product_gen.go +++ b/model/gmodel/fs_product_gen.go @@ -35,6 +35,7 @@ type FsProduct struct { RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // RecommendProductSort *string `gorm:"default:'';" json:"recommend_product_sort"` // SceneIds *string `gorm:"default:'';" json:"scene_ids"` // + IsCustomization *int64 `gorm:"default:0;" json:"is_customization"` // 是否可定制 } type FsProductModel struct { db *gorm.DB diff --git a/model/gmodel/fs_quotation_gen.go b/model/gmodel/fs_quotation_gen.go index 041bbb84..b766f060 100644 --- a/model/gmodel/fs_quotation_gen.go +++ b/model/gmodel/fs_quotation_gen.go @@ -14,6 +14,7 @@ type FsQuotation struct { PageNum *int64 `gorm:"default:0;" json:"page_num"` // 页数 ProductNum *int64 `gorm:"default:0;" json:"product_num"` // 产品数量 GiftNum *int64 `gorm:"default:0;" json:"gift_num"` // 赠品数 + SequenceNum *string `gorm:"default:'';" json:"sequence_num"` // Status *int64 `gorm:"default:0;" json:"status"` // 状态位 0停用 1待设计 2设计中 3待报价 4报价中 5完成 Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 DesignId *int64 `gorm:"default:0;" json:"design_id"` // 设计人员 diff --git a/model/gmodel/fs_resource_gen.go b/model/gmodel/fs_resource_gen.go index 4edaddb9..8671c7fe 100644 --- a/model/gmodel/fs_resource_gen.go +++ b/model/gmodel/fs_resource_gen.go @@ -1,9 +1,8 @@ package gmodel import ( - "time" - "gorm.io/gorm" + "time" ) // fs_resource 资源表 diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 339064f1..1f3d2326 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -193,6 +193,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec Intro: *v.Intro, IsRecommend: isRecommend, MinPrice: minPrice, + IsCustomization: *productInfo.IsCustomization, } if _, ok := mapTagProp[productInfo.Id]; ok { item.CoverDefault = mapTagProp[productInfo.Id] diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 1213c414..f0538caf 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -444,6 +444,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL Recommended: *productInfo.IsRecommend > 0, Cover: *productInfo.Cover, CoverMetadata: req.MapResourceMetadata[*productInfo.Cover], + IsCustomization: *productInfo.IsCustomization, } if _, ok = req.MapTagProp[productInfo.Id]; ok { item.CoverDefault = req.MapTagProp[productInfo.Id] diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 9f5df115..75d8963f 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -217,6 +217,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, + IsCustomization: *productInfo.IsCustomization, } if _, ok = mapTagProp[productInfo.Id]; ok { item.CoverDefault = mapTagProp[productInfo.Id] diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index ee0a001e..a7e2b48b 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -246,6 +246,7 @@ type GetRecommandProductListRsp struct { Intro string `json:"intro"` IsRecommend int64 `json:"is_recommend"` MinPrice int64 `json:"min_price"` + IsCustomization int64 `json:"is_customization"` } type GetTagProductListReq struct { @@ -281,6 +282,7 @@ type TagProduct struct { CoverDefault []CoverDefaultItem `json:"cover_default"` HaveOptionalFitting bool `json:"have_optional_fitting"` Recommended bool `json:"recommended"` + IsCustomization int64 `json:"is_customization"` } type CoverDefaultItem struct { @@ -409,6 +411,7 @@ type HomePageRecommendProductListRsp struct { MinPrice int64 `json:"min_price"` CoverDefault []CoverDefaultItem `json:"cover_default"` HaveOptionalFitting bool `json:"have_optional_fitting"` + IsCustomization int64 `json:"is_customization"` } type Request struct { diff --git a/server_api/product.api b/server_api/product.api index bb95a9d9..b309c6dd 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -298,6 +298,7 @@ type GetRecommandProductListRsp { Intro string `json:"intro"` IsRecommend int64 `json:"is_recommend"` MinPrice int64 `json:"min_price"` + IsCustomization int64 `json:"is_customization"` } //获取分类产品列表 type GetTagProductListReq { @@ -331,6 +332,7 @@ type TagProduct { CoverDefault []CoverDefaultItem `json:"cover_default"` HaveOptionalFitting bool `json:"have_optional_fitting"` Recommended bool `json:"recommended"` + IsCustomization int64 `json:"is_customization"` } type CoverDefaultItem { TemplateTag string `json:"template_tag"` @@ -451,4 +453,5 @@ type HomePageRecommendProductListRsp { MinPrice int64 `json:"min_price"` CoverDefault []CoverDefaultItem `json:"cover_default"` HaveOptionalFitting bool `json:"have_optional_fitting"` + IsCustomization int64 `json:"is_customization"` } \ No newline at end of file From b61a6a48f79e6e83cf826c4aeafcaf917b1845e7 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 18:39:31 +0800 Subject: [PATCH 2/6] fix --- go.mod | 1 + go.sum | 2 + model/gmodel/fs_user_logic.go | 45 +++++++++++++++++--- server/info/internal/logic/infologic_test.go | 30 +++++++++++++ 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 01c94f65..069b20a9 100644 --- a/go.mod +++ b/go.mod @@ -123,4 +123,5 @@ require ( google.golang.org/grpc v1.56.2 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v2 v2.4.0 + gorm.io/datatypes v1.2.0 ) diff --git a/go.sum b/go.sum index 67d9f1b0..cabd1d03 100644 --- a/go.sum +++ b/go.sum @@ -986,6 +986,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco= +gorm.io/datatypes v1.2.0/go.mod h1:o1dh0ZvjIjhH/bngTpypG6lVRJ5chTBxE09FH/71k04= gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64= diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index c72bb9d9..e795973d 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -9,6 +9,7 @@ import ( "time" "github.com/zeromicro/go-zero/core/logx" + "gorm.io/gorm" ) @@ -146,15 +147,16 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg // SubscriptionStatus 订阅状态 type SubscriptionStatus struct { SubEmail bool `json:"all_emails"` - ItemMap struct { + ItemMap *struct { } `json:"item_map"` } // UserProfile 个人信息 type UserProfile struct { - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - Resetaurant string `json:"resetaurant"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Resetaurant string `json:"resetaurant"` + SubStatus SubscriptionStatus `json:"sub_status"` } // 自平台的注册流程 @@ -188,6 +190,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT // 继承guest_id的资源表 err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error { + userProfile := &UserProfile{ FirstName: FirstName, LastName: LastName, @@ -197,6 +200,9 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT if err != nil { return err } + + // txUserInfo.Where("user_id = ?", user.Id).Row().Err() + now := time.Now() uinfo := &FsUserInfo{ Module: FsString("profile"), @@ -207,11 +213,36 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT Utime: &now, } - err = txUserInfo.Create(uinfo).Error - if err == gorm.ErrRecordNotFound { - return nil + err = txUserInfo.Where("user_id = ?", uinfo.UserId).Take(nil).Error + // txUserInfo.Statement.Table + + if err == nil { + + updatesql := `UPDATE %s + SET metadata = CASE + WHEN metadata IS NULL THEN '%s' + ELSE JSON_MERGE_PATCH(metadata, '%s') + END + WHERE id = ?;` + updatesql = fmt.Sprintf(updatesql, txUserInfo.Statement.Table) + + txUserInfo.Raw(`UPDATE fusen.fs_change_code + SET metadata = CASE + WHEN metadata IS NULL THEN '%s' + ELSE JSON_MERGE_PATCH(metadata, '%s') + END + WHERE id = ?;`) } + + if err == gorm.ErrRecordNotFound { + err = txUserInfo.Create(uinfo).Error + if err == gorm.ErrRecordNotFound { + return nil + } + } + return err + }) if err == gorm.ErrRecordNotFound { diff --git a/server/info/internal/logic/infologic_test.go b/server/info/internal/logic/infologic_test.go index fec09e59..0c11f2d4 100644 --- a/server/info/internal/logic/infologic_test.go +++ b/server/info/internal/logic/infologic_test.go @@ -4,7 +4,9 @@ import ( "encoding/json" "fmt" "fusenapi/initalize" + "fusenapi/model/gmodel" "fusenapi/utils/check" + "log" "strings" "testing" @@ -96,3 +98,31 @@ func TestMain(t *testing.T) { } } + +func TestCaseJSON_EXTRACT(t *testing.T) { + + userProfile := &gmodel.UserProfile{ + FirstName: "FirstName", + LastName: "LastName", + Resetaurant: "Resetaurant", + } + metadata, err := json.Marshal(userProfile) + if err != nil { + panic(err) + } + + updatesql := `UPDATE fusen.fs_change_code + SET metadata = CASE + WHEN metadata IS NULL THEN '%s' + ELSE JSON_MERGE_PATCH(metadata, '%s') + END + WHERE id = ?;` + + updatesql = fmt.Sprintf(updatesql, metadata, metadata) + log.Println(string(updatesql)) + + conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen") + // err = conn.Exec(updatesql, 6).Error + log.Println(conn.Model(&gmodel.FsChangeCode{}).Select("id").Where("id = 5").Take(nil).Error) + log.Println(err) +} From c8740978046bdb30afa4cec6a62edaabfd0cb200 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 18:47:00 +0800 Subject: [PATCH 3/6] fix --- server/websocket/internal/logic/ws_render_image.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 6e06329e..d60ae168 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -94,6 +94,20 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } + //获取产品信息 + productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + logx.Error(err) + } + //不可定制 + if *productInfo.IsCustomization == 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + } //获取上传最近的logo userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId) if err != nil { From ea58b2316ddffeb4d85ce7b48a6f1dff0e36fc2c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 18:48:48 +0800 Subject: [PATCH 4/6] fix --- server/websocket/internal/logic/ws_render_image.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index d60ae168..26976272 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -103,10 +103,12 @@ func (w *wsConnectItem) renderImage(data []byte) { } w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) logx.Error(err) + return } //不可定制 if *productInfo.IsCustomization == 0 { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return } //获取上传最近的logo userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId) From 9ad045c8f40ecccb8280dfed5b7102ce2f400d68 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 10:52:51 +0800 Subject: [PATCH 5/6] fix --- model/gmodel/fs_user_logic.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index e795973d..466b122c 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -216,38 +216,31 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT err = txUserInfo.Where("user_id = ?", uinfo.UserId).Take(nil).Error // txUserInfo.Statement.Table - if err == nil { + if err != nil { + if err == gorm.ErrRecordNotFound { + err = txUserInfo.Create(uinfo).Error + if err == gorm.ErrRecordNotFound { + return nil + } + } + } else { updatesql := `UPDATE %s SET metadata = CASE - WHEN metadata IS NULL THEN '%s' - ELSE JSON_MERGE_PATCH(metadata, '%s') + WHEN metadata IS NULL THEN ? + ELSE JSON_MERGE_PATCH(metadata, ?) END WHERE id = ?;` updatesql = fmt.Sprintf(updatesql, txUserInfo.Statement.Table) - - txUserInfo.Raw(`UPDATE fusen.fs_change_code - SET metadata = CASE - WHEN metadata IS NULL THEN '%s' - ELSE JSON_MERGE_PATCH(metadata, '%s') - END - WHERE id = ?;`) + txUserInfo.Raw(updatesql, metadata, metadata, uinfo.UserId) } - - if err == gorm.ErrRecordNotFound { - err = txUserInfo.Create(uinfo).Error - if err == gorm.ErrRecordNotFound { - return nil - } - } - return err - }) if err == gorm.ErrRecordNotFound { return nil } + return err } From a4363d0a477b873e154e3e8e2c4c0be703087967 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 11:08:13 +0800 Subject: [PATCH 6/6] fix --- model/gmodel/fs_user_logic.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 466b122c..1bae52d5 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -232,7 +232,11 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT END WHERE id = ?;` updatesql = fmt.Sprintf(updatesql, txUserInfo.Statement.Table) - txUserInfo.Raw(updatesql, metadata, metadata, uinfo.UserId) + logx.Error(updatesql) + err = txUserInfo.Raw(updatesql, metadata, metadata, uinfo.UserId).Error + if err != nil { + return err + } } return err })