This commit is contained in:
laodaming 2023-09-06 12:21:58 +08:00
parent 3cdfe3c38a
commit 9dc6581a8c
3 changed files with 79 additions and 32 deletions

View File

@ -1,6 +1,7 @@
package logic package logic
import ( import (
"encoding/json"
"errors" "errors"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
@ -61,6 +62,8 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get recommend product list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get recommend product list")
} }
} }
//资源id集合
resourceIds := make([]string, 0, 50)
//需要填充时需要忽略的id //需要填充时需要忽略的id
ignoreProductIds := make([]int64, 0, len(recommendProductList)) ignoreProductIds := make([]int64, 0, len(recommendProductList))
productIds := make([]int64, 0, len(recommendProductList)) productIds := make([]int64, 0, len(recommendProductList))
@ -70,6 +73,16 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
ignoreProductIds = append(ignoreProductIds, v.Id) ignoreProductIds = append(ignoreProductIds, v.Id)
productIds = append(productIds, v.Id) productIds = append(productIds, v.Id)
mapRecommend[v.Id] = struct{}{} mapRecommend[v.Id] = struct{}{}
coverSlice := strings.Split(*v.Cover, "/")
coverImgSlice := strings.Split(*v.CoverImg, "/")
lenCoverSlice := len(coverSlice)
lenCoverImgSlice := len(coverImgSlice)
if lenCoverSlice > 1 {
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
}
if lenCoverImgSlice > 1 {
resourceIds = append(resourceIds, coverImgSlice[lenCoverImgSlice-1])
}
} }
//小于请求的数量则需要从产品表中随机填补上(不包含上面的产品) //小于请求的数量则需要从产品表中随机填补上(不包含上面的产品)
lenRecommendProduct := len(recommendProductList) lenRecommendProduct := len(recommendProductList)
@ -86,6 +99,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
recommendProductList = append(recommendProductList, v) recommendProductList = append(recommendProductList, v)
} }
} }
//查询产品价格 //查询产品价格
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds) priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds)
if err != nil { if err != nil {
@ -124,11 +138,38 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property")
} }
for _, v := range productTagPropList {
coverSlice := strings.Split(*v.Cover, "/")
lenCoverSlice := len(coverSlice)
if lenCoverSlice > 1 {
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
}
}
//根据resourceUrls找到对应的元数据
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get resource list")
}
mapResourceMetadata := make(map[string]map[string]interface{})
for _, v := range resourceMetadataList {
var metadata map[string]interface{}
if v.Metadata != nil {
_ = json.Unmarshal([]byte(*v.Metadata), &metadata)
}
mapResourceMetadata[*v.ResourceUrl] = metadata
}
mapTagProp := make(map[int64][]types.CoverDefaultItem) mapTagProp := make(map[int64][]types.CoverDefaultItem)
for _, v := range productTagPropList { for _, v := range productTagPropList {
coverSlice := strings.Split(*v.Cover, "/")
lenCoverSlice := len(coverSlice)
if lenCoverSlice > 1 {
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
}
mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{
Tag: v.TemplateTag, Tag: v.TemplateTag,
Cover: *v.Cover, Cover: *v.Cover,
CoverMetadata: mapResourceMetadata[*v.Cover],
}) })
} }
list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList)) list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList))
@ -156,16 +197,18 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
minPrice = minVal minPrice = minVal
} }
item := types.GetRecommandProductListRsp{ item := types.GetRecommandProductListRsp{
Id: v.Id, Id: v.Id,
Sn: *v.Sn, Sn: *v.Sn,
Title: *v.Title, Title: *v.Title,
TitleCn: *v.TitleCn, TitleCn: *v.TitleCn,
Cover: *v.Cover, Cover: *v.Cover,
CoverImg: *v.CoverImg, CoverMetadata: mapResourceMetadata[*v.Cover],
CoverDefault: []types.CoverDefaultItem{}, CoverImg: *v.CoverImg,
Intro: *v.Intro, CoverImgMetadata: mapResourceMetadata[*v.CoverImg],
IsRecommend: isRecommend, CoverDefault: []types.CoverDefaultItem{},
MinPrice: minPrice, Intro: *v.Intro,
IsRecommend: isRecommend,
MinPrice: minPrice,
} }
if _, ok := mapTagProp[productInfo.Id]; ok { if _, ok := mapTagProp[productInfo.Id]; ok {
item.CoverDefault = mapTagProp[productInfo.Id] item.CoverDefault = mapTagProp[productInfo.Id]

View File

@ -234,16 +234,18 @@ type GetRecommandProductListReq struct {
} }
type GetRecommandProductListRsp struct { type GetRecommandProductListRsp struct {
Id int64 `json:"id"` Id int64 `json:"id"`
Sn string `json:"sn"` Sn string `json:"sn"`
Title string `json:"title"` Title string `json:"title"`
TitleCn string `json:"title_cn"` TitleCn string `json:"title_cn"`
Cover string `json:"cover"` Cover string `json:"cover"`
CoverImg string `json:"cover_img"` CoverMetadata interface{} `json:"cover_metadata"`
CoverDefault []CoverDefaultItem `json:"cover_default"` CoverImg string `json:"cover_img"`
Intro string `json:"intro"` CoverImgMetadata interface{} `json:"cover_img_metadata"`
IsRecommend int64 `json:"is_recommend"` CoverDefault []CoverDefaultItem `json:"cover_default"`
MinPrice int64 `json:"min_price"` Intro string `json:"intro"`
IsRecommend int64 `json:"is_recommend"`
MinPrice int64 `json:"min_price"`
} }
type GetTagProductListReq struct { type GetTagProductListReq struct {

View File

@ -286,16 +286,18 @@ type GetRecommandProductListReq {
Sn string `form:"sn"` Sn string `form:"sn"`
} }
type GetRecommandProductListRsp { type GetRecommandProductListRsp {
Id int64 `json:"id"` Id int64 `json:"id"`
Sn string `json:"sn"` Sn string `json:"sn"`
Title string `json:"title"` Title string `json:"title"`
TitleCn string `json:"title_cn"` TitleCn string `json:"title_cn"`
Cover string `json:"cover"` Cover string `json:"cover"`
CoverImg string `json:"cover_img"` CoverMetadata interface{} `json:"cover_metadata"`
CoverDefault []CoverDefaultItem `json:"cover_default"` CoverImg string `json:"cover_img"`
Intro string `json:"intro"` CoverImgMetadata interface{} `json:"cover_img_metadata"`
IsRecommend int64 `json:"is_recommend"` CoverDefault []CoverDefaultItem `json:"cover_default"`
MinPrice int64 `json:"min_price"` Intro string `json:"intro"`
IsRecommend int64 `json:"is_recommend"`
MinPrice int64 `json:"min_price"`
} }
//获取分类产品列表 //获取分类产品列表
type GetTagProductListReq { type GetTagProductListReq {