This commit is contained in:
laodaming 2023-09-05 10:58:48 +08:00
parent 2f839ac85b
commit 0c1b15468c

View File

@ -45,41 +45,57 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
} }
var ( var (
productTemplateTags []gmodel.FsProductTemplateTags productTemplateTags []gmodel.FsProductTemplateTags
err error
) )
//获取用户元数据 //白板用户
userMaterial, err := l.svcCtx.AllModels.FsUserMaterial.FindLatestOne(l.ctx, userinfo.UserId, userinfo.GuestId) if !userinfo.IsUser() && !userinfo.IsGuest() {
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") productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC")
} else { } 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") 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 { } else {
//解析元数据 //元数据是空的
var metaData map[string]interface{} if userMaterial.Metadata == nil {
if err = json.Unmarshal([]byte(*userMaterial.Metadata), &metaData); err != nil { // 返回固定模板标签列表
logx.Error(err) productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, 0, 1, "`id` DESC")
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") 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)) list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
for _, v := range productTemplateTags { for _, v := range productTemplateTags {
list = append(list, types.GetProductTemplateTagsRsp{ list = append(list, types.GetProductTemplateTagsRsp{