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 (
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{