fix
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/xerr"
|
||||
"sort"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
@@ -43,6 +44,13 @@ func (l *GetProductByEnLogic) GetProductByEn(req *types.GetProductByEnRequest) (
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "产品查询, 查找产品关联错误: %v", err)
|
||||
}
|
||||
|
||||
// 创建featureId到sort的映射,用于后续排序
|
||||
featureSortMap := make(map[int64]int64)
|
||||
for _, productFeature := range productFeatureAll {
|
||||
featureSortMap[productFeature.FeatureId] = productFeature.Sort
|
||||
}
|
||||
|
||||
var product types.Product
|
||||
err = copier.Copy(&product, productModel)
|
||||
if err != nil {
|
||||
@@ -71,5 +79,12 @@ func (l *GetProductByEnLogic) GetProductByEn(req *types.GetProductByEnRequest) (
|
||||
}
|
||||
})
|
||||
|
||||
// 按照productFeature.Sort字段对features进行排序
|
||||
sort.Slice(product.Features, func(i, j int) bool {
|
||||
sortI := featureSortMap[product.Features[i].ID]
|
||||
sortJ := featureSortMap[product.Features[j].ID]
|
||||
return sortI < sortJ
|
||||
})
|
||||
|
||||
return &types.ProductResponse{Product: product}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user