From e24fc4825c17773fdfd51255861ddd7d4de5cd30 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 16:47:14 +0800 Subject: [PATCH 01/10] fix --- .../internal/logic/gettagproductlistlogic.go | 95 +++++++++++++------ 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 3043ec68..29334af2 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -186,7 +186,46 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR } //map tag菜单 mapTagLevel := make(map[string]*types.TagItem) - for _, tagInfo := range tagList { + //处理tags数据 + l.delWithTagMenuData(delWithTagMenuDataReq{ + TagList: tagList, + WithProduct: req.WithProduct, + WithRecommendProduct: req.WithRecommendProduct, + ProductList: productList, + MapProductMinPrice: mapProductMinPrice, + MapProductTemplate: mapProductTemplate, + MapProductSizeCount: mapProductSizeCount, + MapTagLevel: mapTagLevel, + MapProduct: mapProduct, + Size: req.Size, + user: user, + }) + return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ + TotalCategory: len(mapTagLevel), + TagList: l.organizationLevelRelation(mapTagLevel),//组装等级从属关系 + }) +} +//排序推荐产品结构体 +type sortRecommendProduct struct { + ProductId int64 + Sort int64 +} +//处理tag菜单数据 +type delWithTagMenuDataReq struct { + TagList []gmodel.FsTags + WithProduct bool + WithRecommendProduct bool + ProductList []gmodel.FsProduct + MapProductMinPrice map[int64]int64 + MapProductTemplate map[int64]struct{} + MapProductSizeCount map[int64]int64 + MapTagLevel map[string]*types.TagItem + MapProduct map[int64]int + Size uint32 + user gmodel.FsUser +} +func (l *GetTagProductListLogic)delWithTagMenuData(req delWithTagMenuDataReq)error{ + for _, tagInfo := range req.TagList { tagTem := types.TagItem{ TagProductList: nil, TagRecommendProductList: nil, @@ -197,19 +236,19 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR Icon: *tagInfo.Icon, Sort: *tagInfo.Sort, Description: *tagInfo.Description, - ChildTagList: make([]*types.TagItem, 0, 100), + ChildTagList: make([]*types.TagItem, 0, 50), } //携带产品 if req.WithProduct { //获取分类产品列表 productListRsp := l.getTagProducts(getTagProductsReq{ TagId: tagInfo.Id, - ProductList: productList, - MapProductMinPrice: mapProductMinPrice, - MapProductTemplate: mapProductTemplate, - MapProductSizeCount: mapProductSizeCount, + ProductList: req.ProductList, + MapProductMinPrice: req.MapProductMinPrice, + MapProductTemplate: req.MapProductTemplate, + MapProductSizeCount: req.MapProductSizeCount, Size: req.Size, - User: user, + User: req.user, }) //赋值 tagTem.TagProductList = productListRsp @@ -225,35 +264,27 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR return nil } if len(recommendProductIds) != len(recommendProductIdsSort){ - return resp.SetStatusWithMessage(basic.CodeServiceErr,fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d",tagInfo.Id)) + return errors.New(fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d",tagInfo.Id)) } recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{ TagInfo: tagInfo, - ProductList: productList, - MapProduct: mapProduct, - MapProductMinPrice: mapProductMinPrice, - MapProductTemplate: mapProductTemplate, - MapProductSizeCount: mapProductSizeCount, + ProductList: req.ProductList, + MapProduct: req.MapProduct, + MapProductMinPrice: req.MapProductMinPrice, + MapProductTemplate: req.MapProductTemplate, + MapProductSizeCount: req.MapProductSizeCount, RecommendProductIds: recommendProductIds, RecommendProductIdsSort: recommendProductIdsSort, Size: req.Size, - User: user, + User: req.user, }) //赋值 tagTem.TagRecommendProductList = recommendProductListRsp } //加入分类 - mapTagLevel[*tagInfo.LevelPrefix] = &tagTem + req.MapTagLevel[*tagInfo.LevelPrefix] = &tagTem } - return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ - TotalCategory: len(mapTagLevel), - TagList: l.organizationLevelRelation(mapTagLevel),//组装等级从属关系 - }) -} -//排序推荐产品结构体 -type sortRecommendProduct struct { - ProductId int64 - Sort int64 + return nil } //组织等级从属关系 func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string]*types.TagItem)[]types.TagItem{ @@ -267,14 +298,16 @@ func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string prefixSlice := strings.Split(prefix, "/") //有父级 parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/") - if parent, ok := mapTagLevel[parentPrefix]; ok { - parent.ChildTagList = append(parent.ChildTagList, tagItem) - //排序 - sort.SliceStable(parent.ChildTagList, func(i, j int) bool { - return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort - }) - mapTagLevel[parentPrefix] = parent + parent, ok := mapTagLevel[parentPrefix] + if !ok{ + continue } + parent.ChildTagList = append(parent.ChildTagList, tagItem) + //排序 + sort.SliceStable(parent.ChildTagList, func(i, j int) bool { + return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort + }) + mapTagLevel[parentPrefix] = parent } //最终值提取最高级别那一层出来 rspList := make([]types.TagItem, 0, len(mapTagLevel)) From 7ebc7f8476c02c67303e28b84311bdaaf28a6259 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 16:51:08 +0800 Subject: [PATCH 02/10] fix --- .../product/internal/logic/gettagproductlistlogic.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 29334af2..c9eb27c9 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -187,7 +187,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR //map tag菜单 mapTagLevel := make(map[string]*types.TagItem) //处理tags数据 - l.delWithTagMenuData(delWithTagMenuDataReq{ + if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ TagList: tagList, WithProduct: req.WithProduct, WithRecommendProduct: req.WithRecommendProduct, @@ -199,7 +199,10 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR MapProduct: mapProduct, Size: req.Size, user: user, - }) + });err != nil{ + logx.Error(err) + return resp.SetStatusAddMessage(basic.CodeServiceErr,"failed to dealwith ") + } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ TotalCategory: len(mapTagLevel), TagList: l.organizationLevelRelation(mapTagLevel),//组装等级从属关系 @@ -211,7 +214,7 @@ type sortRecommendProduct struct { Sort int64 } //处理tag菜单数据 -type delWithTagMenuDataReq struct { +type dealWithTagMenuDataReq struct { TagList []gmodel.FsTags WithProduct bool WithRecommendProduct bool @@ -224,7 +227,7 @@ type delWithTagMenuDataReq struct { Size uint32 user gmodel.FsUser } -func (l *GetTagProductListLogic)delWithTagMenuData(req delWithTagMenuDataReq)error{ +func (l *GetTagProductListLogic)dealWithTagMenuData(req dealWithTagMenuDataReq)error{ for _, tagInfo := range req.TagList { tagTem := types.TagItem{ TagProductList: nil, From c49874fec770075ae8b6c000ccd3b0261c2fd618 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 16:53:24 +0800 Subject: [PATCH 03/10] fix --- server/product/internal/logic/gettagproductlistlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index c9eb27c9..45896187 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -201,7 +201,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR user: user, });err != nil{ logx.Error(err) - return resp.SetStatusAddMessage(basic.CodeServiceErr,"failed to dealwith ") + return resp.SetStatusAddMessage(basic.CodeServiceErr,"failed to deal with tag data") } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ TotalCategory: len(mapTagLevel), From d4c77b2a133f345200737213a0d39d78dd59380e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 16:57:34 +0800 Subject: [PATCH 04/10] fix --- server/product/internal/logic/gettagproductlistlogic.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 45896187..3a2bd556 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -114,15 +114,15 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR pIsDel := int64(0) pStatus := int64(1) pIsShelf := int64(1) - pReq := gmodel.GetProductListByParamsReq{ + //获取产品列表 + productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, + gmodel.GetProductListByParamsReq{ Type: typeIds, IsDel: &pIsDel, IsShelf: &pIsShelf, Status: &pStatus, OrderBy: "`sort` DESC", - } - //获取产品列表 - productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, pReq) + }) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") From 99bd3592af15e8faddb65f4cdf3b3dd4510a5c82 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 17:34:07 +0800 Subject: [PATCH 05/10] fix --- .../internal/logic/gettagproductlistlogic.go | 121 +++++++++--------- 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 3a2bd556..b0beee0e 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -87,14 +87,14 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR mapProductTemplate = make(map[int64]struct{}) //产品模板map ) //携带推荐产品 - if req.WithRecommendProduct{ + if req.WithRecommendProduct { //提取tag推荐产品 allTagRecommendProductIds := make([]int64, 0, len(tagList)*5) for _, v := range tagList { if v.RecommendProduct == nil || *v.RecommendProduct == "" { continue } - sl, err := format.StrSlicToInt64Slice(strings.Split(*v.RecommendProductSort, ",")) + sl, err := format.StrSlicToInt64Slice(strings.Split(*v.RecommendProduct, ",")) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse recommend product ids,id=%d", v.Id)) @@ -117,23 +117,20 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR //获取产品列表 productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, gmodel.GetProductListByParamsReq{ - Type: typeIds, - IsDel: &pIsDel, - IsShelf: &pIsShelf, - Status: &pStatus, - OrderBy: "`sort` DESC", - }) + Type: typeIds, + IsDel: &pIsDel, + IsShelf: &pIsShelf, + Status: &pStatus, + OrderBy: "`sort` DESC", + }) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") } } //任意一个不为空 - if len(productList) != 0 || len(recommendProductList) != 0{ - //提取产品ids - productIds := make([]int64, 0, len(productList)) + if len(productList) != 0 || len(recommendProductList) != 0 { for k, v := range productList { - productIds = append(productIds, v.Id) mapProduct[v.Id] = k } //合并产品列表 @@ -145,6 +142,10 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR productList = append(productList, v) mapProduct[v.Id] = len(productList) - 1 } + productIds := make([]int64,0,len(productList)) + for _,product := range productList{ + productIds = append(productIds,product.Id) + } //获取产品价格列表 productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) if err != nil { @@ -199,35 +200,38 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR MapProduct: mapProduct, Size: req.Size, user: user, - });err != nil{ + }); err != nil { 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") } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ TotalCategory: len(mapTagLevel), - TagList: l.organizationLevelRelation(mapTagLevel),//组装等级从属关系 + TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系 }) } -//排序推荐产品结构体 + +// 排序推荐产品结构体 type sortRecommendProduct struct { ProductId int64 - Sort int64 + Sort int64 } -//处理tag菜单数据 + +// 处理tag菜单数据 type dealWithTagMenuDataReq struct { - TagList []gmodel.FsTags - WithProduct bool + TagList []gmodel.FsTags + WithProduct bool WithRecommendProduct bool - ProductList []gmodel.FsProduct - MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} - MapProductSizeCount map[int64]int64 - MapTagLevel map[string]*types.TagItem - MapProduct map[int64]int - Size uint32 - user gmodel.FsUser + ProductList []gmodel.FsProduct + MapProductMinPrice map[int64]int64 + MapProductTemplate map[int64]struct{} + MapProductSizeCount map[int64]int64 + MapTagLevel map[string]*types.TagItem + MapProduct map[int64]int + Size uint32 + user gmodel.FsUser } -func (l *GetTagProductListLogic)dealWithTagMenuData(req dealWithTagMenuDataReq)error{ + +func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error { for _, tagInfo := range req.TagList { tagTem := types.TagItem{ TagProductList: nil, @@ -242,7 +246,7 @@ func (l *GetTagProductListLogic)dealWithTagMenuData(req dealWithTagMenuDataReq)e ChildTagList: make([]*types.TagItem, 0, 50), } //携带产品 - if req.WithProduct { + if req.WithProduct { //获取分类产品列表 productListRsp := l.getTagProducts(getTagProductsReq{ TagId: tagInfo.Id, @@ -262,12 +266,12 @@ func (l *GetTagProductListLogic)dealWithTagMenuData(req dealWithTagMenuDataReq)e recommendProductIds, _ := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ",")) //推荐产品的排序 recommendProductIdsSort, err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProductSort, ",")) - if err != nil{ + if err != nil { logx.Error(err) return nil } - if len(recommendProductIds) != len(recommendProductIdsSort){ - return errors.New(fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d",tagInfo.Id)) + if len(recommendProductIds) != len(recommendProductIdsSort) { + return errors.New(fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d", tagInfo.Id)) } recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{ TagInfo: tagInfo, @@ -289,8 +293,9 @@ func (l *GetTagProductListLogic)dealWithTagMenuData(req dealWithTagMenuDataReq)e } return nil } -//组织等级从属关系 -func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string]*types.TagItem)[]types.TagItem{ + +// 组织等级从属关系 +func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[string]*types.TagItem) []types.TagItem { mapTop := make(map[string]struct{}) for prefix, tagItem := range mapTagLevel { //最上级没有父级 @@ -302,7 +307,7 @@ func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string //有父级 parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/") parent, ok := mapTagLevel[parentPrefix] - if !ok{ + if !ok { continue } parent.ChildTagList = append(parent.ChildTagList, tagItem) @@ -315,7 +320,7 @@ func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string //最终值提取最高级别那一层出来 rspList := make([]types.TagItem, 0, len(mapTagLevel)) for prefix, _ := range mapTop { - rspList = append(rspList,*mapTagLevel[prefix]) + rspList = append(rspList, *mapTagLevel[prefix]) } //排序 sort.SliceStable(rspList, func(i, j int) bool { @@ -323,36 +328,37 @@ func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string }) return rspList } -//获取tag推荐产品列表 + +// 获取tag推荐产品列表 type getTagRecommendProductsReq struct { - TagInfo gmodel.FsTags - ProductList []gmodel.FsProduct - MapProduct map[int64]int - MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} - MapProductSizeCount map[int64]int64 - RecommendProductIds []int64 + TagInfo gmodel.FsTags + ProductList []gmodel.FsProduct + MapProduct map[int64]int + MapProductMinPrice map[int64]int64 + MapProductTemplate map[int64]struct{} + MapProductSizeCount map[int64]int64 + RecommendProductIds []int64 RecommendProductIdsSort []int64 - Size uint32 - User gmodel.FsUser + Size uint32 + User gmodel.FsUser } -func (l *GetTagProductListLogic)getTagRecommendProducts(req getTagRecommendProductsReq)(productListRsp []types.TagProduct){ +func (l *GetTagProductListLogic) getTagRecommendProducts(req getTagRecommendProductsReq) (productListRsp []types.TagProduct) { //排序 - sortList := make([]sortRecommendProduct,0,len(req.RecommendProductIds)) - for sortIndex,pid := range req.RecommendProductIds{ - sortList = append(sortList,sortRecommendProduct{ + sortList := make([]sortRecommendProduct, 0, len(req.RecommendProductIds)) + for sortIndex, pid := range req.RecommendProductIds { + sortList = append(sortList, sortRecommendProduct{ ProductId: pid, - Sort: req.RecommendProductIdsSort[sortIndex], + Sort: req.RecommendProductIdsSort[sortIndex], }) } sort.SliceStable(sortList, func(i, j int) bool { return sortList[i].Sort < sortList[j].Sort }) - productListRsp = make([]types.TagProduct,0,len(sortList)) - for _,sortVal := range sortList{ - productIndex,ok := req.MapProduct[sortVal.ProductId] - if !ok{ + productListRsp = make([]types.TagProduct, 0, len(sortList)) + for _, sortVal := range sortList { + productIndex, ok := req.MapProduct[sortVal.ProductId] + if !ok { continue } productInfo := req.ProductList[productIndex] @@ -394,10 +400,11 @@ func (l *GetTagProductListLogic)getTagRecommendProducts(req getTagRecommendProdu item.CoverImg = r.CoverImg item.CoverDefault = r.CoverDefault //加入切片 - productListRsp = append(productListRsp,item) + productListRsp = append(productListRsp, item) } return productListRsp } + // 获取对应tag的产品列表 type getTagProductsReq struct { TagId int64 From 37078d5772a2a66951e00d4f57843abf9129ff98 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 17:36:27 +0800 Subject: [PATCH 06/10] fix --- server/product/internal/logic/getproductlistlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product/internal/logic/getproductlistlogic.go b/server/product/internal/logic/getproductlistlogic.go index ed7bfa8e..4e0c04e0 100644 --- a/server/product/internal/logic/getproductlistlogic.go +++ b/server/product/internal/logic/getproductlistlogic.go @@ -45,7 +45,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri } return resp.SetStatusWithMessage(basic.CodeOK, "success", demo) } - if req.Page <= 0 && req.Page > 10000 { + if req.Page <= 0{ req.Page = constants.DEFAULT_PAGE } //获取合适尺寸 From 3ef96dab1318e8a2fabfda4abe64a9569e32ea03 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 18:27:27 +0800 Subject: [PATCH 07/10] fix --- server/product/internal/logic/gettagproductlistlogic.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index b0beee0e..e8946b8b 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -60,6 +60,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found") } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get tag info") } tReq.LevelPrefixLeftLike = *tagData.LevelPrefix } From 31132364adef8e191732fb8f1fdabf66b236c8fb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 19:29:50 +0800 Subject: [PATCH 08/10] fix --- .../internal/logic/gettagproductlistlogic.go | 73 ------------------- server/product/internal/types/types.go | 26 +++---- server_api/product.api | 26 +++---- 3 files changed, 24 insertions(+), 101 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index e8946b8b..34b03831 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -2,7 +2,6 @@ package logic import ( "errors" - "fmt" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -79,8 +78,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR } var ( productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方) - recommendProductList []gmodel.FsProduct //tag推荐产品列表(select 字段需要看查询的地方) - mapProduct = make(map[int64]int) //产品map productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方) mapProductMinPrice = make(map[int64]int64) //产品最小价格map productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方) @@ -88,28 +85,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map mapProductTemplate = make(map[int64]struct{}) //产品模板map ) - //携带推荐产品 - if req.WithRecommendProduct { - //提取tag推荐产品 - allTagRecommendProductIds := make([]int64, 0, len(tagList)*5) - for _, v := range tagList { - if v.RecommendProduct == nil || *v.RecommendProduct == "" { - continue - } - sl, err := format.StrSlicToInt64Slice(strings.Split(*v.RecommendProduct, ",")) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse recommend product ids,id=%d", v.Id)) - } - allTagRecommendProductIds = append(allTagRecommendProductIds, sl...) - } - //获取推荐的产品列表 - recommendProductList, err = l.svcCtx.AllModels.FsProduct.FindAllOnlyByIds(l.ctx, allTagRecommendProductIds) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag recommend products") - } - } //携带产品 if req.WithProduct { //查询符合的产品列表 @@ -129,21 +104,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") } - } - //任意一个不为空 - if len(productList) != 0 || len(recommendProductList) != 0 { - for k, v := range productList { - mapProduct[v.Id] = k - } - //合并产品列表 - for _, v := range recommendProductList { - //存在则不并入 - if _, ok := mapProduct[v.Id]; ok { - continue - } - productList = append(productList, v) - mapProduct[v.Id] = len(productList) - 1 - } productIds := make([]int64,0,len(productList)) for _,product := range productList{ productIds = append(productIds,product.Id) @@ -193,13 +153,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ TagList: tagList, WithProduct: req.WithProduct, - WithRecommendProduct: req.WithRecommendProduct, ProductList: productList, MapProductMinPrice: mapProductMinPrice, MapProductTemplate: mapProductTemplate, MapProductSizeCount: mapProductSizeCount, MapTagLevel: mapTagLevel, - MapProduct: mapProduct, Size: req.Size, user: user, }); err != nil { @@ -222,13 +180,11 @@ type sortRecommendProduct struct { type dealWithTagMenuDataReq struct { TagList []gmodel.FsTags WithProduct bool - WithRecommendProduct bool ProductList []gmodel.FsProduct MapProductMinPrice map[int64]int64 MapProductTemplate map[int64]struct{} MapProductSizeCount map[int64]int64 MapTagLevel map[string]*types.TagItem - MapProduct map[int64]int Size uint32 user gmodel.FsUser } @@ -237,7 +193,6 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) for _, tagInfo := range req.TagList { tagTem := types.TagItem{ TagProductList: nil, - TagRecommendProductList: nil, TypeName: *tagInfo.Title, TypeId: tagInfo.Id, Level: *tagInfo.Level, @@ -262,34 +217,6 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) //赋值 tagTem.TagProductList = productListRsp } - //获取推荐产品列表 - if req.WithRecommendProduct && tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" { - //上面解析过,这里就无需判断错误 - recommendProductIds, _ := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ",")) - //推荐产品的排序 - recommendProductIdsSort, err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProductSort, ",")) - if err != nil { - logx.Error(err) - return nil - } - if len(recommendProductIds) != len(recommendProductIdsSort) { - return errors.New(fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d", tagInfo.Id)) - } - recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{ - TagInfo: tagInfo, - ProductList: req.ProductList, - MapProduct: req.MapProduct, - MapProductMinPrice: req.MapProductMinPrice, - MapProductTemplate: req.MapProductTemplate, - MapProductSizeCount: req.MapProductSizeCount, - RecommendProductIds: recommendProductIds, - RecommendProductIdsSort: recommendProductIdsSort, - Size: req.Size, - User: req.user, - }) - //赋值 - tagTem.TagRecommendProductList = recommendProductListRsp - } //加入分类 req.MapTagLevel[*tagInfo.LevelPrefix] = &tagTem } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 5f5e3768..5802ad5f 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -245,10 +245,9 @@ type GetRecommandProductListRsp struct { } type GetTagProductListReq struct { - Cid int64 `form:"cid,optional"` //分类id - Size uint32 `form:"size,optional"` //尺寸 - WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 - WithRecommendProduct bool `form:"with_recommend_product"` //是否携带分类推荐产品 + Cid int64 `form:"cid,optional"` //分类id + Size uint32 `form:"size,optional"` //尺寸 + WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp struct { @@ -257,16 +256,15 @@ type GetTagProductListRsp struct { } type TagItem struct { - TypeName string `json:"type_name"` - TypeId int64 `json:"type_id"` - Description string `json:"description"` - Level int64 `json:"level"` - LevelPrefix string `json:"level_prefix"` - Icon string `json:"icon"` - Sort int64 `json:"sort"` - TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品 - TagRecommendProductList []TagProduct `json:"tag_recommend_product_list"` //分类推荐产品 - ChildTagList []*TagItem `json:"child_tag_list"` + TypeName string `json:"type_name"` + TypeId int64 `json:"type_id"` + Description string `json:"description"` + Level int64 `json:"level"` + LevelPrefix string `json:"level_prefix"` + Icon string `json:"icon"` + Sort int64 `json:"sort"` + TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品 + ChildTagList []*TagItem `json:"child_tag_list"` } type TagProduct struct { diff --git a/server_api/product.api b/server_api/product.api index b1e80c00..aec9f87e 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -291,26 +291,24 @@ type GetRecommandProductListRsp { } //获取分类产品列表 type GetTagProductListReq { - Cid int64 `form:"cid,optional"` //分类id - Size uint32 `form:"size,optional"` //尺寸 - WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 - WithRecommendProduct bool `form:"with_recommend_product"` //是否携带分类推荐产品 + Cid int64 `form:"cid,optional"` //分类id + Size uint32 `form:"size,optional"` //尺寸 + WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp { TotalCategory int `json:"total_category"` TagList []TagItem `json:"tag_list"` } type TagItem { - TypeName string `json:"type_name"` - TypeId int64 `json:"type_id"` - Description string `json:"description"` - Level int64 `json:"level"` - LevelPrefix string `json:"level_prefix"` - Icon string `json:"icon"` - Sort int64 `json:"sort"` - TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品 - TagRecommendProductList []TagProduct `json:"tag_recommend_product_list"` //分类推荐产品 - ChildTagList []*TagItem `json:"child_tag_list"` + TypeName string `json:"type_name"` + TypeId int64 `json:"type_id"` + Description string `json:"description"` + Level int64 `json:"level"` + LevelPrefix string `json:"level_prefix"` + Icon string `json:"icon"` + Sort int64 `json:"sort"` + TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品 + ChildTagList []*TagItem `json:"child_tag_list"` } type TagProduct { ProductId int64 `json:"product_id"` From 3bd08c8c2b44f8e69f2e0110a208f387745ecedf Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 19:33:26 +0800 Subject: [PATCH 09/10] fix --- server/product/internal/logic/gettagproductlistlogic.go | 2 +- server/product/internal/types/types.go | 4 ++-- server_api/product.api | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 34b03831..96f48d25 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -165,7 +165,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ - TotalCategory: len(mapTagLevel), + TotalCategoryProduct: len(productList), TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系 }) } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 5802ad5f..b1e3d42f 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -251,8 +251,8 @@ type GetTagProductListReq struct { } type GetTagProductListRsp struct { - TotalCategory int `json:"total_category"` - TagList []TagItem `json:"tag_list"` + TotalCategoryProduct int `json:"total_category_product"` + TagList []TagItem `json:"tag_list"` } type TagItem struct { diff --git a/server_api/product.api b/server_api/product.api index aec9f87e..1d7f60a7 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -296,8 +296,8 @@ type GetTagProductListReq { WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp { - TotalCategory int `json:"total_category"` - TagList []TagItem `json:"tag_list"` + TotalCategoryProduct int `json:"total_category_product"` + TagList []TagItem `json:"tag_list"` } type TagItem { TypeName string `json:"type_name"` From 47e22e6891faaaac7371f7c631b6ffd74136fecf Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 19:41:35 +0800 Subject: [PATCH 10/10] fix --- .../internal/logic/gettagproductlistlogic.go | 77 ------------------- 1 file changed, 77 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 96f48d25..b357c026 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -257,83 +257,6 @@ func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[strin }) return rspList } - -// 获取tag推荐产品列表 -type getTagRecommendProductsReq struct { - TagInfo gmodel.FsTags - ProductList []gmodel.FsProduct - MapProduct map[int64]int - MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} - MapProductSizeCount map[int64]int64 - RecommendProductIds []int64 - RecommendProductIdsSort []int64 - Size uint32 - User gmodel.FsUser -} - -func (l *GetTagProductListLogic) getTagRecommendProducts(req getTagRecommendProductsReq) (productListRsp []types.TagProduct) { - //排序 - sortList := make([]sortRecommendProduct, 0, len(req.RecommendProductIds)) - for sortIndex, pid := range req.RecommendProductIds { - sortList = append(sortList, sortRecommendProduct{ - ProductId: pid, - Sort: req.RecommendProductIdsSort[sortIndex], - }) - } - sort.SliceStable(sortList, func(i, j int) bool { - return sortList[i].Sort < sortList[j].Sort - }) - productListRsp = make([]types.TagProduct, 0, len(sortList)) - for _, sortVal := range sortList { - productIndex, ok := req.MapProduct[sortVal.ProductId] - if !ok { - continue - } - productInfo := req.ProductList[productIndex] - minPrice, ok := req.MapProductMinPrice[productInfo.Id] - _, tmpOk := req.MapProductTemplate[productInfo.Id] - //无最小价格则不显示 || 没有模板也不显示 - if !ok || !tmpOk { - continue - } - sizeNum := int64(0) - if mapSizeNum, ok := req.MapProductSizeCount[productInfo.Id]; ok { - sizeNum = mapSizeNum - } - item := types.TagProduct{ - ProductId: productInfo.Id, - Sn: *productInfo.Sn, - Title: *productInfo.Title, - Intro: *productInfo.Intro, - IsEnv: *productInfo.IsProtection, - IsMicro: *productInfo.IsMicrowave, - SizeNum: uint32(sizeNum), - MiniPrice: minPrice, - } - //千人千面处理 - r := image.ThousandFaceImageFormatReq{ - Size: int(req.Size), - IsThousandFace: 0, - Cover: *productInfo.Cover, - CoverImg: *productInfo.CoverImg, - CoverDefault: *productInfo.CoverImg, - ProductId: productInfo.Id, - UserId: req.User.Id, - } - if req.User.Id != 0 { - r.IsThousandFace = int(*req.User.IsThousandFace) - } - image.ThousandFaceImageFormat(&r) - item.Cover = r.Cover - item.CoverImg = r.CoverImg - item.CoverDefault = r.CoverDefault - //加入切片 - productListRsp = append(productListRsp, item) - } - return productListRsp -} - // 获取对应tag的产品列表 type getTagProductsReq struct { TagId int64