Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-09-06 12:29:38 +08:00
commit 310c3af9dc
3 changed files with 79 additions and 32 deletions

View File

@ -1,6 +1,7 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/model/gmodel"
"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")
}
}
//资源id集合
resourceIds := make([]string, 0, 50)
//需要填充时需要忽略的id
ignoreProductIds := 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)
productIds = append(productIds, v.Id)
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)
@ -86,6 +99,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
recommendProductList = append(recommendProductList, v)
}
}
//查询产品价格
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds)
if err != nil {
@ -124,11 +138,38 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
logx.Error(err)
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)
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{
Tag: v.TemplateTag,
Cover: *v.Cover,
CoverMetadata: mapResourceMetadata[*v.Cover],
})
}
list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList))
@ -161,7 +202,9 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
Title: *v.Title,
TitleCn: *v.TitleCn,
Cover: *v.Cover,
CoverMetadata: mapResourceMetadata[*v.Cover],
CoverImg: *v.CoverImg,
CoverImgMetadata: mapResourceMetadata[*v.CoverImg],
CoverDefault: []types.CoverDefaultItem{},
Intro: *v.Intro,
IsRecommend: isRecommend,

View File

@ -239,7 +239,9 @@ type GetRecommandProductListRsp struct {
Title string `json:"title"`
TitleCn string `json:"title_cn"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
CoverImg string `json:"cover_img"`
CoverImgMetadata interface{} `json:"cover_img_metadata"`
CoverDefault []CoverDefaultItem `json:"cover_default"`
Intro string `json:"intro"`
IsRecommend int64 `json:"is_recommend"`

View File

@ -291,7 +291,9 @@ type GetRecommandProductListRsp {
Title string `json:"title"`
TitleCn string `json:"title_cn"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
CoverImg string `json:"cover_img"`
CoverImgMetadata interface{} `json:"cover_img_metadata"`
CoverDefault []CoverDefaultItem `json:"cover_default"`
Intro string `json:"intro"`
IsRecommend int64 `json:"is_recommend"`