From b9069a8a16df0fd67e9676b1372329dc9bc185d6 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 19:11:04 +0800 Subject: [PATCH 01/12] fix --- model/gmodel/fs_user_logic.go | 2 +- {server => utils}/fssql/metadata.go | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {server => utils}/fssql/metadata.go (100%) diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 440eeaac..158f1503 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -5,8 +5,8 @@ import ( "encoding/json" "fmt" - "fusenapi/server/fssql" "fusenapi/utils/auth" + "fusenapi/utils/fssql" "time" "github.com/zeromicro/go-zero/core/logx" diff --git a/server/fssql/metadata.go b/utils/fssql/metadata.go similarity index 100% rename from server/fssql/metadata.go rename to utils/fssql/metadata.go From 00be036e590bb7fce94b8e30afa59d8de6d565b6 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 19:14:01 +0800 Subject: [PATCH 02/12] fix --- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 6560a00c..df99866a 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -278,11 +278,11 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData websocket_data.R productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3d.Id, renderImageData.RenderData.TemplateTag) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应开启云渲染的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) logx.Error("template info is not found") return nil, nil, nil, err } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应开启云渲染模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) logx.Error("failed to get template info:", err) return nil, nil, nil, err } From 14f0dd2b22a24c4df202e046a04c81f3c1b38de0 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 10 Sep 2023 02:58:56 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_user_logic.go | 2 +- utils/fssql/metadata.go | 69 ++++++++++++++++++++++++++++++++--- utils/fssql/metadata_test.go | 28 ++++++++++++++ 3 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 utils/fssql/metadata_test.go diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 158f1503..dd0cf675 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -228,7 +228,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT } else { - err = fssql.MetadataPATCH(txUserInfo, "profile", FsUser{}, metadata, "user_id = ?", *uinfo.UserId) + err = fssql.MetadataModulePATCH(txUserInfo, "profile", FsUser{}, metadata, "user_id = ?", *uinfo.UserId) if err != nil { return err } diff --git a/utils/fssql/metadata.go b/utils/fssql/metadata.go index bc97da9d..e56385b0 100644 --- a/utils/fssql/metadata.go +++ b/utils/fssql/metadata.go @@ -47,7 +47,7 @@ import ( // } // tableStructPointer 表结构 updateMetadata 可以是json的[]byte也可以结构体 -func MetadataPATCH(tx *gorm.DB, module string, tableStructPointer any, updateMetadata any, WhereKeysCond string, value ...any) error { +func MetadataModulePATCH(tx *gorm.DB, module string, tableStructPointer any, updateMetadata any, WhereKeysCond string, values ...any) error { stype := reflect.TypeOf(tableStructPointer) if stype.Kind() == reflect.Pointer { stype = stype.Elem() @@ -75,14 +75,73 @@ func MetadataPATCH(tx *gorm.DB, module string, tableStructPointer any, updateMet } } - var values []any + var args []any - values = append(values, metadata, metadata) - values = append(values, value...) + args = append(args, metadata, metadata) + args = append(args, values...) updatesql = fmt.Sprintf(updatesql, tx.NamingStrategy.TableName(stype.Name()), module, WhereKeysCond) // logx.Error(updatesql) - err = tx.Exec(updatesql, values).Error + err = tx.Exec(updatesql, args...).Error + if err != nil { + return err + } + + return nil +} + +func MetadataResourcePATCH(tx *gorm.DB, rid string, updateMetadata any, values ...any) error { + // stype := reflect.TypeOf(tableStructPointer) + // if stype.Kind() == reflect.Pointer { + // stype = stype.Elem() + // } + + var updatesql string + + if len(values) == 0 { + updatesql = `UPDATE fs_resource + SET metadata = CASE + WHEN metadata IS NULL THEN ? + ELSE JSON_MERGE_PATCH(metadata, ?) + END + WHERE resource_id = '%s';` + } else { + cond, ok := values[0].(string) + if !ok { + return fmt.Errorf("values[0] must be wherecond") + } + updatesql = `UPDATE fs_resource + SET metadata = CASE + WHEN metadata IS NULL THEN ? + ELSE JSON_MERGE_PATCH(metadata, ?) + END + cond, ok := values[0].(string) + WHERE resource_id = '%s'` + "and " + cond + `;` + } + + var err error + var metadata []byte + + switch mdata := updateMetadata.(type) { + case []byte: + metadata = mdata + case string: + metadata = []byte(mdata) + default: + metadata, err = json.Marshal(updateMetadata) + if err != nil { + return err + } + } + + var args []any + + args = append(args, metadata, metadata) + args = append(args, values...) + + updatesql = fmt.Sprintf(updatesql, rid) + // logx.Error(updatesql) + err = tx.Exec(updatesql, args...).Error if err != nil { return err } diff --git a/utils/fssql/metadata_test.go b/utils/fssql/metadata_test.go new file mode 100644 index 00000000..4c12011d --- /dev/null +++ b/utils/fssql/metadata_test.go @@ -0,0 +1,28 @@ +package fssql_test + +import ( + "fusenapi/initalize" + "fusenapi/model/gmodel" + "fusenapi/utils/fssql" + "testing" +) + +func TestCase1(t *testing.T) { + u := gmodel.UserProfile{ + FirstName: "h", + LastName: "sm", + } + + conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen") + err := fssql.MetadataModulePATCH(conn, "logo", gmodel.FsChangeCode{}, u, "id = ?", 6) + if err != nil { + panic(err) + } + + err = fssql.MetadataResourcePATCH(conn, + "f8932c0379fa5aa3397dc0a963696ca90536cc273ea10119b0137fd15ecfe673", u) + + if err != nil { + panic(err) + } +} From 5bedfc923717824e01f9c41e89926fba2da48afe Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 10 Sep 2023 03:09:48 +0800 Subject: [PATCH 04/12] fix --- model/gmodel/fs_user_logic.go | 6 +----- utils/fssql/metadata.go | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index dd0cf675..79a3d1fa 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -218,21 +218,17 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT // txUserInfo.Statement.Table if err != nil { - if err == gorm.ErrRecordNotFound { err = txUserInfo.Create(uinfo).Error if err == gorm.ErrRecordNotFound { return nil } } - } else { - - err = fssql.MetadataModulePATCH(txUserInfo, "profile", FsUser{}, metadata, "user_id = ?", *uinfo.UserId) + err = fssql.MetadataModulePATCH(txUserInfo, "profile", FsUserInfo{}, metadata, "user_id = ?", *uinfo.UserId) if err != nil { return err } - } return err }) diff --git a/utils/fssql/metadata.go b/utils/fssql/metadata.go index e56385b0..143354c0 100644 --- a/utils/fssql/metadata.go +++ b/utils/fssql/metadata.go @@ -116,7 +116,7 @@ func MetadataResourcePATCH(tx *gorm.DB, rid string, updateMetadata any, values . ELSE JSON_MERGE_PATCH(metadata, ?) END cond, ok := values[0].(string) - WHERE resource_id = '%s'` + "and " + cond + `;` + WHERE resource_id = '%s'` + " and " + cond + `;` } var err error From 71352cc5b9dd8b6bb191297693d58f94aebb95f5 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 10 Sep 2023 03:11:35 +0800 Subject: [PATCH 05/12] fix --- model/gmodel/fs_user_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 79a3d1fa..e938690c 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -204,7 +204,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT // txUserInfo.Where("user_id = ?", user.Id).Row().Err() - now := time.Now() + now := time.Now().UTC() uinfo := &FsUserInfo{ Module: FsString("profile"), UserId: &user.Id, From 65ccfcb84e6e8a1e01e0141b7a467dd6f32c6f63 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 10 Sep 2023 23:50:42 +0800 Subject: [PATCH 06/12] fix --- server/auth/internal/logic/usergoogleloginlogic.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index 56a8e498..b12b9ebb 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -89,10 +89,11 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us logx.Error(err) return resp.SetStatus(basic.CodeOK) } - + gemail := gresult.Get("email").String() l.registerInfo = &auth.RegisterToken{ Password: base64.RawURLEncoding.EncodeToString(nonce), Platform: string(auth.PLATFORM_GOOGLE), + Email: gemail, OperateType: auth.OpTypeRegister, TraceId: uuid.NewString(), CreateAt: time.Now().UTC(), @@ -110,7 +111,7 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us return resp.SetStatus(basic.CodeOAuthRegisterTokenErr) } l.registerToken = token - l.defaultEmail = gresult.Get("email").String() + l.defaultEmail = gemail return resp.SetStatus(basic.CodeOK) } From 467cf3c5a31bbd4a27636fcbaadb7eb24deb9950 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 10 Sep 2023 23:54:02 +0800 Subject: [PATCH 07/12] fix --- server/auth/internal/logic/usergoogleloginlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index b12b9ebb..a16dd503 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -104,6 +104,7 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us }, } + l.defaultEmail = gemail l.isRegistered = false token, err := l.svcCtx.OAuthTokenManger.Encrypt(l.registerInfo) if err != nil { @@ -111,7 +112,6 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us return resp.SetStatus(basic.CodeOAuthRegisterTokenErr) } l.registerToken = token - l.defaultEmail = gemail return resp.SetStatus(basic.CodeOK) } From a0438230453720fcb120f9499c580eb3197952f0 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 10 Sep 2023 23:58:17 +0800 Subject: [PATCH 08/12] fix --- server/auth/internal/logic/usergoogleloginlogic.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index a16dd503..c9808571 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -104,7 +104,6 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us }, } - l.defaultEmail = gemail l.isRegistered = false token, err := l.svcCtx.OAuthTokenManger.Encrypt(l.registerInfo) if err != nil { @@ -112,7 +111,7 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us return resp.SetStatus(basic.CodeOAuthRegisterTokenErr) } l.registerToken = token - + l.defaultEmail = gemail return resp.SetStatus(basic.CodeOK) } @@ -143,7 +142,7 @@ func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request l.token, l.isRegistered, l.registerToken, - l.registerInfo.Email, + l.defaultEmail, ) html := fmt.Sprintf(` From ac11753274298bb9cfb29e1acf87d6730f01b8f1 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 11 Sep 2023 12:17:07 +0800 Subject: [PATCH 09/12] fix --- .../internal/logic/gettemplatebypidlogic.go | 11 ++- .../internal/logic/ws_render_image.go | 7 +- utils/template_switch_info/template_switch.go | 88 ++++++++++++++----- 3 files changed, 76 insertions(+), 30 deletions(-) diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 7764fcc7..16e9fff8 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -105,14 +105,13 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id)) } - //后台隐藏/显示信息(现在下面是写死了) - /*var switchInfo interface{} - if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" { - _ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo) - }*/ modelInfo := modelList[modelIndex] mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId) - rsp[mapKey] = template_switch_info.GetTemplateSwitchInfo(templateInfo.Id, *templateInfo.MaterialImg) + switchInfo, err := template_switch_info.GetTemplateSwitchInfo(templateInfo.Id, templateInfo.TemplateInfo, *templateInfo.MaterialImg) + if err != nil { + return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()) + } + rsp[mapKey] = switchInfo } return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp) } diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index df99866a..81e895f2 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -153,7 +153,12 @@ func (w *wsConnectItem) renderImage(data []byte) { return } //获取模板开关信息并且对于没有默认值的给赋值默认值 - templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, *productTemplate.MaterialImg) + templateSwitchInfo, err := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg) + if err != nil { + logx.Error(err) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) + return + } if renderImageData.RenderData.Website == "" { renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue } diff --git a/utils/template_switch_info/template_switch.go b/utils/template_switch_info/template_switch.go index c262baa6..86a133cd 100644 --- a/utils/template_switch_info/template_switch.go +++ b/utils/template_switch_info/template_switch.go @@ -1,5 +1,11 @@ package template_switch_info +import ( + "encoding/json" + "errors" + "github.com/zeromicro/go-zero/core/logx" +) + type GetTemplateSwitchInfoRsp struct { Id int64 `json:"id"` Material string `json:"material"` @@ -36,36 +42,72 @@ type Logo struct { Material string `json:"material"` } +// 模板开关信息简单结构 +type TemplateSimpleParseInfo struct { + MaterialList []MaterialItem `json:"materialList"` +} +type MaterialItem struct { + Type string `json:"type"` + Tag string `json:"tag"` + Visible bool `json:"visible"` + Text string `json:"text"` +} + // 获取模板开关信息(目前写死,以后后台做好了功能再更新变动) -func GetTemplateSwitchInfo(templateId int64, templateMaterialImg string) GetTemplateSwitchInfoRsp { - return GetTemplateSwitchInfoRsp{ +func GetTemplateSwitchInfo(templateId int64, templateInfo *string, templateMaterialImg string) (resp GetTemplateSwitchInfoRsp, err error) { + if templateInfo == nil || *templateInfo == "" { + return GetTemplateSwitchInfoRsp{}, nil + } + var templateJsonInfo TemplateSimpleParseInfo + if err = json.Unmarshal([]byte(*templateInfo), &templateJsonInfo); err != nil { + logx.Error(err) + return GetTemplateSwitchInfoRsp{}, errors.New("解析模板json获取DIY开关设置失败") + } + mapSwitchInfo := GetTemplateSwitchInfoRsp{ Id: templateId, Material: templateMaterialImg, MaterialData: MaterialData{ - QRcode: QRcode{ - IfShow: true, - Text: "qrcode", - DefaultValue: "default qrcode", - }, - Website: Website{ - IfShow: true, - Text: "website", - DefaultValue: "default website", - }, - Address: Address{ - IfShow: true, - Text: "address", - DefaultValue: "default address", - }, - Phone: Phone{ - IfShow: true, - Text: "phone", - DefaultValue: "17557283679", - }, Logo: Logo{ Material: "/image/logo/aHnT1_rzubdwax_scale.png", }, }, } - + for _, v := range templateJsonInfo.MaterialList { + if v.Type == "combine" && !v.Visible { + return GetTemplateSwitchInfoRsp{ + MaterialData: MaterialData{ + Logo: Logo{ + Material: "/image/logo/aHnT1_rzubdwax_scale.png", + }, + }, + }, nil + } + switch v.Tag { + case "Phone": //电话 + mapSwitchInfo.MaterialData.Phone = Phone{ + IfShow: v.Visible, + Text: v.Text, + DefaultValue: "xxx xxx xxx xxxx", + } + case "Address": //地址 + mapSwitchInfo.MaterialData.Address = Address{ + IfShow: v.Visible, + Text: v.Text, + DefaultValue: "USA", + } + case "Website": + mapSwitchInfo.MaterialData.Website = Website{ + IfShow: v.Visible, + Text: v.Text, + DefaultValue: "https://www.xxxxxx.com", + } + case "QRcode": + mapSwitchInfo.MaterialData.QRcode = QRcode{ + IfShow: v.Visible, + Text: v.Text, + DefaultValue: "xxxxxxx", + } + } + } + return mapSwitchInfo, nil } From e6f2651704707820e4a0c5083c2d1c3ffe9ef5b3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 11 Sep 2023 12:19:24 +0800 Subject: [PATCH 10/12] fix --- utils/template_switch_info/template_switch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/template_switch_info/template_switch.go b/utils/template_switch_info/template_switch.go index 86a133cd..6e903ab3 100644 --- a/utils/template_switch_info/template_switch.go +++ b/utils/template_switch_info/template_switch.go @@ -54,12 +54,12 @@ type MaterialItem struct { } // 获取模板开关信息(目前写死,以后后台做好了功能再更新变动) -func GetTemplateSwitchInfo(templateId int64, templateInfo *string, templateMaterialImg string) (resp GetTemplateSwitchInfoRsp, err error) { - if templateInfo == nil || *templateInfo == "" { +func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMaterialImg string) (resp GetTemplateSwitchInfoRsp, err error) { + if templateJsonStr == nil || *templateJsonStr == "" { return GetTemplateSwitchInfoRsp{}, nil } var templateJsonInfo TemplateSimpleParseInfo - if err = json.Unmarshal([]byte(*templateInfo), &templateJsonInfo); err != nil { + if err = json.Unmarshal([]byte(*templateJsonStr), &templateJsonInfo); err != nil { logx.Error(err) return GetTemplateSwitchInfoRsp{}, errors.New("解析模板json获取DIY开关设置失败") } From 2553c6c82112214b731f477c6ec26e5882a07cb4 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 11 Sep 2023 12:24:10 +0800 Subject: [PATCH 11/12] fix --- .../internal/logic/ws_render_image.go | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 81e895f2..524d766c 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -152,24 +152,26 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("failed to get element ,", err) return } - //获取模板开关信息并且对于没有默认值的给赋值默认值 - templateSwitchInfo, err := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg) - if err != nil { - logx.Error(err) - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) - return - } - if renderImageData.RenderData.Website == "" { - renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue - } - if renderImageData.RenderData.Phone == "" { - renderImageData.RenderData.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue - } - if renderImageData.RenderData.Address == "" { - renderImageData.RenderData.Address = templateSwitchInfo.MaterialData.Address.DefaultValue - } - if renderImageData.RenderData.Qrcode == "" { - renderImageData.RenderData.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue + //获取模板开关信息并且对于没有默认值的给赋值默认值(但凡DIY有一个是空的就要请求默认数据) + if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" { + templateSwitchInfo, err := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg) + if err != nil { + logx.Error(err) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) + return + } + if renderImageData.RenderData.Website == "" { + renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue + } + if renderImageData.RenderData.Phone == "" { + renderImageData.RenderData.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue + } + if renderImageData.RenderData.Address == "" { + renderImageData.RenderData.Address = templateSwitchInfo.MaterialData.Address.DefaultValue + } + if renderImageData.RenderData.Qrcode == "" { + renderImageData.RenderData.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue + } } //获取刀版图 combineReq := repositories.LogoCombineReq{ From cc7fcb213384ff186c9f0fd0d3aadbe213bf8441 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 11 Sep 2023 13:05:31 +0800 Subject: [PATCH 12/12] fix --- model/gmodel/fs_product_template_tags_logic.go | 8 ++++---- .../internal/logic/getproducttemplatetagslogic.go | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/model/gmodel/fs_product_template_tags_logic.go b/model/gmodel/fs_product_template_tags_logic.go index d0492bd2..b2529fcf 100755 --- a/model/gmodel/fs_product_template_tags_logic.go +++ b/model/gmodel/fs_product_template_tags_logic.go @@ -23,8 +23,8 @@ func (pt *FsProductTemplateTagsModel) FindOne(ctx context.Context, id int64, fie err = db.Take(&resp).Error return resp, err } -func (pt *FsProductTemplateTagsModel) GetList(ctx context.Context, page, limit int, isHide, status int64, orderBy string) (resp []FsProductTemplateTags, err error) { - db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`is_hide` = ? and `status` = ?", isHide, status) +func (pt *FsProductTemplateTagsModel) GetList(ctx context.Context, page, limit int, status int64, orderBy string) (resp []FsProductTemplateTags, err error) { + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where(" `status` = ?", status) if orderBy != "" { db = db.Order(orderBy) } @@ -32,11 +32,11 @@ func (pt *FsProductTemplateTagsModel) GetList(ctx context.Context, page, limit i err = db.Offset(offset).Limit(limit).Find(&resp).Error return resp, err } -func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tagNames []string, limit int, isHide, status int64, orderBy string) (resp []FsProductTemplateTags, err error) { +func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tagNames []string, limit int, status int64, orderBy string) (resp []FsProductTemplateTags, err error) { if len(tagNames) == 0 { return nil, nil } - db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` in (?) and `is_hide` = ? and `status` = ?", tagNames, isHide, status) + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` in (?) and `status` = ?", tagNames, status) if orderBy != "" { db = db.Order(orderBy) } diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 184de958..8211d783 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -50,7 +50,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu //白板用户 if !userinfo.IsUser() && !userinfo.IsGuest() { // 返回固定模板标签列表 - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC") + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1a"}, req.Limit, 1, "`id` DESC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") @@ -63,8 +63,8 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get ai recommend product template tag list") } - // 返回固定模板标签列表 - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC") + // 返回固定模板A1a + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1a"}, req.Limit, 1, "`id` DESC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") @@ -72,8 +72,8 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } else { //元数据是空的 if userMaterial.Metadata == nil { - // 返回固定模板标签列表 - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC") + // 返回固定模板A1a + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1a"}, req.Limit, 1, "`id` DESC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") @@ -81,7 +81,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } else { //解析元数据 var metaData map[string]interface{} - if err = json.Unmarshal([]byte(*userMaterial.Metadata), &metaData); err != nil { + if err = json.Unmarshal(*userMaterial.Metadata, &metaData); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") } @@ -91,7 +91,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") } - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 0, 1, "id DESC") + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")