diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index c0384d90..6563272a 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -54,33 +54,31 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return } - var colors interface{} + var colors map[string][]types.ColorsItem if logoInfo.Metadata == nil || *logoInfo.Metadata == "" { - // 返回固定模板A1a - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 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(*logoInfo.Metadata), &metaData); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") - } - colors = metaData["colors"] - 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, 1, "id DESC") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") - } + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "logo info`s metadata is not set") + } + //解析元数据 + var metaData map[string]interface{} + if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + } + b, _ := json.Marshal(metaData["colors"]) + if err = json.Unmarshal(b, &colors); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s colors") + } + 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, 1, "id DESC") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") } //资源id集合 resourceIds := make([]string, 0, 5) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index e81cb040..eeca764b 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,11 +10,20 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors interface{} `json:"colors"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors map[string][]ColorsItem `json:"colors"` +} + +type ColorsItem struct { + Color []ColorItem `json:"color"` +} + +type ColorItem struct { + Value string `json:"value"` + Selected bool `json:"selected"` } type Request struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index d663e109..94d2d35e 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,9 +20,16 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors interface{} `json:"colors"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors map[string][]ColorsItem `json:"colors"` +} +type ColorsItem { + Color []ColorItem `json:"color"` +} +type ColorItem { + Value string `json:"value"` + Selected bool `json:"selected"` } \ No newline at end of file