This commit is contained in:
laodaming 2023-09-06 14:35:42 +08:00
parent 310c3af9dc
commit 13d91699f0
7 changed files with 60 additions and 61 deletions

View File

@ -7,7 +7,7 @@ import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"fusenapi/server/product-template-tag/internal/svc"
@ -99,13 +99,32 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
}
}
}
//资源id集合
resourceIds := make([]string, 0, 5)
for _, v := range productTemplateTags {
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
}
//根据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
}
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
for _, v := range productTemplateTags {
list = append(list, types.GetProductTemplateTagsRsp{
Id: v.Id,
TemplateTag: *v.TemplateTag,
Cover: *v.Cover,
Id: v.Id,
TemplateTag: *v.TemplateTag,
Cover: *v.Cover,
CoverMetadata: mapResourceMetadata[*v.Cover],
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)

View File

@ -10,9 +10,10 @@ type GetProductTemplateTagsReq struct {
}
type GetProductTemplateTagsRsp struct {
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
}
type Request struct {

View File

@ -8,6 +8,7 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"sort"
"strings"
@ -73,16 +74,8 @@ 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])
}
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.CoverImg))
}
//小于请求的数量则需要从产品表中随机填补上(不包含上面的产品)
lenRecommendProduct := len(recommendProductList)
@ -139,11 +132,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
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])
}
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
}
//根据resourceUrls找到对应的元数据
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
@ -161,11 +150,6 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
}
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,

View File

@ -8,6 +8,7 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"sort"
"strings"
@ -180,16 +181,8 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
productIds := make([]int64, 0, len(productList))
for _, product := range productList {
productIds = append(productIds, product.Id)
coverSlice := strings.Split(*product.Cover, "/")
coverImgSlice := strings.Split(*product.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])
}
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*product.Cover))
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*product.CoverImg))
}
//获取商品可选配件
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
@ -213,11 +206,7 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
return nil, errors.New("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])
}
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
}
//根据resourceUrls找到对应的元数据
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)

View File

@ -7,6 +7,7 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"sort"
"strings"
@ -95,16 +96,8 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
productIds := make([]int64, 0, len(recommendProductList))
for _, product := range recommendProductList {
productIds = append(productIds, product.Id)
coverSlice := strings.Split(*product.Cover, "/")
coverImgSlice := strings.Split(*product.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])
}
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*product.Cover))
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*product.CoverImg))
}
//获取商品可选配件
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
@ -172,11 +165,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
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])
}
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
}
//根据resourceUrls找到对应的元数据
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)

View File

@ -20,7 +20,8 @@ type GetProductTemplateTagsReq {
Limit int `form:"limit"`
}
type GetProductTemplateTagsRsp {
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
}

View File

@ -0,0 +1,16 @@
package s3url_to_s3id
import "strings"
// 通过url解析资源id
func GetS3ResourceIdFormUrl(s3Url string) string {
if !strings.Contains(s3Url, "http") {
return ""
}
s := strings.Split(s3Url, "/")
lens := len(s)
if lens <= 1 {
return ""
}
return s[lens-1]
}