From 0c1b15468c1d3c04d8246e40709226744787d99a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 10:58:48 +0800 Subject: [PATCH] fix --- .../logic/getproducttemplatetagslogic.go | 66 ++++++++++++------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 9eaa40f8..57280c4d 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -45,41 +45,57 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } var ( productTemplateTags []gmodel.FsProductTemplateTags + err error ) - //获取用户元数据 - userMaterial, err := l.svcCtx.AllModels.FsUserMaterial.FindLatestOne(l.ctx, userinfo.UserId, userinfo.GuestId) - if err != nil { - if !errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get ai recommend product template tag list") - } + //白板用户 + if !userinfo.IsUser() && !userinfo.IsGuest() { // 返回固定模板标签列表 productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC") } else { - //元数据是空的 - if userMaterial.Metadata == nil { + //获取用户元数据 + userMaterial, err := l.svcCtx.AllModels.FsUserMaterial.FindLatestOne(l.ctx, userinfo.UserId, userinfo.GuestId) + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + 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") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") + } } else { - //解析元数据 - var metaData map[string]interface{} - if err = json.Unmarshal([]byte(*userMaterial.Metadata), &metaData); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + //元数据是空的 + if userMaterial.Metadata == nil { + // 返回固定模板标签列表 + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") + } + } else { + //解析元数据 + var metaData map[string]interface{} + if err = json.Unmarshal([]byte(*userMaterial.Metadata), &metaData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + } + var templateTagNameList []string + b, _ := json.Marshal(metaData["template_tagid"]) + if err = json.Unmarshal(b, &templateTagNameList); err != nil { + 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") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") + } } - var templateTagNameList []string - b, _ := json.Marshal(metaData["template_tagid"]) - if err = json.Unmarshal(b, &templateTagNameList); err != nil { - 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") } } - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") - } + list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, v := range productTemplateTags { list = append(list, types.GetProductTemplateTagsRsp{