This commit is contained in:
laodaming 2023-08-17 15:11:32 +08:00
parent 05f61fc8b2
commit 666147cfe6

View File

@ -209,9 +209,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
logx.Error(err) logx.Error(err)
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
} }
//组装等级从属关系
rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel)
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
TotalCategoryProduct: len(productList), TotalCategoryProduct: TotalCategoryProduct,
TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系 TagList: rspTagList,
}) })
} }
@ -274,7 +276,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
} }
// 组织等级从属关系 // 组织等级从属关系
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem { func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) (rspTagList []types.TagItem, productCount int) {
mapTop := make(map[string]struct{}) mapTop := make(map[string]struct{})
//设置归属关系 //设置归属关系
for prefix, tagItem := range mapTagLevel { for prefix, tagItem := range mapTagLevel {
@ -316,13 +318,14 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
if len(mapTagLevel[prefix].TagProductList) == 0 { if len(mapTagLevel[prefix].TagProductList) == 0 {
continue continue
} }
productCount += len(mapTagLevel[prefix].TagProductList)
rspList = append(rspList, *mapTagLevel[prefix]) rspList = append(rspList, *mapTagLevel[prefix])
} }
//排序 //排序
sort.SliceStable(rspList, func(i, j int) bool { sort.SliceStable(rspList, func(i, j int) bool {
return rspList[i].Sort < rspList[j].Sort return rspList[i].Sort < rspList[j].Sort
}) })
return rspList return rspList, productCount
} }
// 获取对应tag的产品列表 // 获取对应tag的产品列表