fix
This commit is contained in:
parent
310c3af9dc
commit
13d91699f0
|
@ -7,7 +7,7 @@ import (
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"fusenapi/server/product-template-tag/internal/svc"
|
"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))
|
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
|
||||||
for _, v := range productTemplateTags {
|
for _, v := range productTemplateTags {
|
||||||
list = append(list, types.GetProductTemplateTagsRsp{
|
list = append(list, types.GetProductTemplateTagsRsp{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
TemplateTag: *v.TemplateTag,
|
TemplateTag: *v.TemplateTag,
|
||||||
Cover: *v.Cover,
|
Cover: *v.Cover,
|
||||||
|
CoverMetadata: mapResourceMetadata[*v.Cover],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
||||||
|
|
|
@ -13,6 +13,7 @@ type GetProductTemplateTagsRsp struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
TemplateTag string `json:"template_tag"`
|
TemplateTag string `json:"template_tag"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
|
CoverMetadata interface{} `json:"cover_metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -73,16 +74,8 @@ 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, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
|
||||||
coverImgSlice := strings.Split(*v.CoverImg, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*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)
|
||||||
|
@ -139,11 +132,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||||
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 {
|
for _, v := range productTagPropList {
|
||||||
coverSlice := strings.Split(*v.Cover, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
|
||||||
lenCoverSlice := len(coverSlice)
|
|
||||||
if lenCoverSlice > 1 {
|
|
||||||
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//根据resourceUrls找到对应的元数据
|
//根据resourceUrls找到对应的元数据
|
||||||
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
|
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)
|
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,
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -180,16 +181,8 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
||||||
productIds := make([]int64, 0, len(productList))
|
productIds := make([]int64, 0, len(productList))
|
||||||
for _, product := range productList {
|
for _, product := range productList {
|
||||||
productIds = append(productIds, product.Id)
|
productIds = append(productIds, product.Id)
|
||||||
coverSlice := strings.Split(*product.Cover, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*product.Cover))
|
||||||
coverImgSlice := strings.Split(*product.CoverImg, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*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])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//获取商品可选配件
|
//获取商品可选配件
|
||||||
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
|
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")
|
return nil, errors.New("failed to get product tag property")
|
||||||
}
|
}
|
||||||
for _, v := range productTagPropList {
|
for _, v := range productTagPropList {
|
||||||
coverSlice := strings.Split(*v.Cover, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
|
||||||
lenCoverSlice := len(coverSlice)
|
|
||||||
if lenCoverSlice > 1 {
|
|
||||||
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//根据resourceUrls找到对应的元数据
|
//根据resourceUrls找到对应的元数据
|
||||||
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
|
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -95,16 +96,8 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
||||||
productIds := make([]int64, 0, len(recommendProductList))
|
productIds := make([]int64, 0, len(recommendProductList))
|
||||||
for _, product := range recommendProductList {
|
for _, product := range recommendProductList {
|
||||||
productIds = append(productIds, product.Id)
|
productIds = append(productIds, product.Id)
|
||||||
coverSlice := strings.Split(*product.Cover, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*product.Cover))
|
||||||
coverImgSlice := strings.Split(*product.CoverImg, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*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])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//获取商品可选配件
|
//获取商品可选配件
|
||||||
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
|
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")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property")
|
||||||
}
|
}
|
||||||
for _, v := range productTagPropList {
|
for _, v := range productTagPropList {
|
||||||
coverSlice := strings.Split(*v.Cover, "/")
|
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
|
||||||
lenCoverSlice := len(coverSlice)
|
|
||||||
if lenCoverSlice > 1 {
|
|
||||||
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//根据resourceUrls找到对应的元数据
|
//根据resourceUrls找到对应的元数据
|
||||||
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
|
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
|
||||||
|
|
|
@ -23,4 +23,5 @@ type GetProductTemplateTagsRsp {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
TemplateTag string `json:"template_tag"`
|
TemplateTag string `json:"template_tag"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
|
CoverMetadata interface{} `json:"cover_metadata"`
|
||||||
}
|
}
|
16
utils/s3url_to_s3id/s3url_to_s3id.go
Normal file
16
utils/s3url_to_s3id/s3url_to_s3id.go
Normal 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]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user