From 77cb2591244917b5438f61a99549a59df860d16d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 11 Oct 2023 11:49:04 +0800 Subject: [PATCH 1/2] fix --- .../internal/logic/gettagproductlistlogic.go | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index afb6c5aa..c71d45e2 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -113,10 +113,12 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR mapTagLevel := make(map[string]*types.TagItem) //处理tags数据 minLevel := 0 //层级最高层(即prefix层级路径最短) + mapTagProduct := make(map[int64]types.TagProduct) if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ TagList: tagList, WithProduct: req.WithProduct, ProductList: productList, + MapTagProduct: mapTagProduct, MapTagProp: mapTagProp, MapProductMinPrice: mapProductMinPrice, MapProductTemplate: mapProductTemplate, @@ -132,7 +134,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") } //组装等级从属关系 - rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel) + rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel, productList, mapTagProduct) return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ TotalCategoryProduct: TotalCategoryProduct, TagList: rspTagList, @@ -262,6 +264,7 @@ type dealWithTagMenuDataReq struct { TagList []gmodel.FsTags WithProduct bool ProductList []gmodel.FsProduct + MapTagProduct map[int64]types.TagProduct MapTagProp map[int64][]types.CoverDefaultItem ProductTagPropList []gmodel.FsProductTagProp MapProductMinPrice map[int64]int64 @@ -308,7 +311,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) }) //tag中产品 for _, tmpProduct := range productListRsp { - tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct) + tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct.ProductId) } } //加入分类 @@ -318,7 +321,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) } // 组织等级从属关系 -func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) (rspTagList []types.TagItem, productCount int) { +func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem, productList []gmodel.FsProduct, mapTagProduct map[int64]types.TagProduct) (rspTagList []types.TagItem, productCount int) { mapTop := make(map[string]struct{}) //设置归属关系 for prefix, tagItem := range mapTagLevel { @@ -346,11 +349,24 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL if _, ok := mapTop[v.LevelPrefix]; ok { continue } - topPrefixSlic := strings.Split(v.LevelPrefix, "/")[:minLevel] - topPrefix := strings.Join(topPrefixSlic, "/") - for k, tmpProduct := range v.TagProductList { - v.TagProductList[k] = tmpProduct.(types.TagProduct).ProductId - mapTagLevel[topPrefix].TagProductList = append(mapTagLevel[topPrefix].TagProductList, tmpProduct) + //初始化 + v.TagProductList = make([]interface{}, 0, 20) + mapTypeId := make(map[int64]struct{}) + for _, v2 := range mapTagLevel { + if strings.Contains(v2.LevelPrefix, v.LevelPrefix) { + mapTypeId[v.TypeId] = struct{}{} + } + } + for _, p := range productList { + _, ok := mapTypeId[*p.Type] + if !ok { + continue + } + tagProduct, ok := mapTagProduct[p.Id] + if !ok { + continue + } + v.TagProductList = append(v.TagProductList, tagProduct) } } //最终值提取最高级别那一层出来 From 543099c8d7ab233c56c110077c6a2f669dcab8f9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 11 Oct 2023 11:52:54 +0800 Subject: [PATCH 2/2] fix --- server/product/internal/logic/gettagproductlistlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index c71d45e2..73d75f9c 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -344,9 +344,9 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL }) mapTagLevel[parentPrefix] = parent } - //把子类的产品列表变成产品id列表并且把产品列表都放到最顶级父级中 + //顶层集子类产品于一身 for _, v := range mapTagLevel { - if _, ok := mapTop[v.LevelPrefix]; ok { + if _, ok := mapTop[v.LevelPrefix]; !ok { continue } //初始化