new
This commit is contained in:
76
app/main/api/internal/logic/product/getproductbyenlogic.go
Normal file
76
app/main/api/internal/logic/product/getproductbyenlogic.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tyc-server/app/main/model"
|
||||
"tyc-server/common/xerr"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/mr"
|
||||
|
||||
"tyc-server/app/main/api/internal/svc"
|
||||
"tyc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductByEnLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductByEnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByEnLogic {
|
||||
return &GetProductByEnLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByEnLogic) GetProductByEn(req *types.GetProductByEnRequest) (resp *types.ProductResponse, err error) {
|
||||
productModel, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, req.ProductEn)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "产品查询, 查找产品错误: %+v", err)
|
||||
}
|
||||
|
||||
build := l.svcCtx.ProductFeatureModel.SelectBuilder().Where(squirrel.Eq{
|
||||
"product_id": productModel.Id,
|
||||
})
|
||||
productFeatureAll, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, build, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "产品查询, 查找产品关联错误: %+v", err)
|
||||
}
|
||||
var product types.Product
|
||||
err = copier.Copy(&product, productModel)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, 用户信息结构体复制失败, %+v", err)
|
||||
}
|
||||
|
||||
mr.MapReduceVoid(func(source chan<- interface{}) {
|
||||
for _, productFeature := range productFeatureAll {
|
||||
source <- productFeature.FeatureId
|
||||
}
|
||||
}, func(item interface{}, writer mr.Writer[*model.Feature], cancel func(error)) {
|
||||
id := item.(int64)
|
||||
|
||||
feature, findFeatureErr := l.svcCtx.FeatureModel.FindOne(l.ctx, id)
|
||||
if findFeatureErr != nil {
|
||||
logx.WithContext(l.ctx).Errorf("产品查询, 查找关联feature错误: %d, err:%v", id, findFeatureErr)
|
||||
return
|
||||
}
|
||||
if feature != nil && feature.Id > 0 {
|
||||
writer.Write(feature)
|
||||
}
|
||||
}, func(pipe <-chan *model.Feature, cancel func(error)) {
|
||||
for item := range pipe {
|
||||
var feature types.Feature
|
||||
_ = copier.Copy(&feature, item)
|
||||
product.Features = append(product.Features, feature)
|
||||
}
|
||||
})
|
||||
|
||||
return &types.ProductResponse{Product: product}, nil
|
||||
}
|
||||
30
app/main/api/internal/logic/product/getproductbyidlogic.go
Normal file
30
app/main/api/internal/logic/product/getproductbyidlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyc-server/app/main/api/internal/svc"
|
||||
"tyc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductByIDLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductByIDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByIDLogic {
|
||||
return &GetProductByIDLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByIDLogic) GetProductByID(req *types.GetProductByIDRequest) (resp *types.ProductResponse, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tyc-server/app/main/api/internal/svc"
|
||||
"tyc-server/app/main/api/internal/types"
|
||||
"tyc-server/app/main/model"
|
||||
"tyc-server/common/xerr"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/mr"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductRenderListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductRenderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductRenderListLogic {
|
||||
return &GetProductRenderListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductRenderListLogic) GetProductRenderList(req *types.GetProductRenderListRequest) (resp *types.GetProductRenderListResponse, err error) {
|
||||
platform, platformOk := l.ctx.Value("platform").(string)
|
||||
if !platformOk || platform == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取渲染列表失败,没有相关平台信息")
|
||||
}
|
||||
// 从上下文中获取品牌信息
|
||||
brand, brandOk := l.ctx.Value("brand").(string)
|
||||
if !brandOk || brand == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取渲染列表失败,没有相关品牌信息")
|
||||
}
|
||||
|
||||
var platformKey = brand + "_" + platform
|
||||
builder := l.svcCtx.ProductRenderModel.SelectBuilder().Where(squirrel.Eq{
|
||||
"platform": platformKey,
|
||||
"module": req.Module,
|
||||
})
|
||||
productRenderModelList, err := l.svcCtx.ProductRenderModel.FindAll(l.ctx, builder, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取渲染列表失败,获取渲染列表失败%s", err.Error())
|
||||
}
|
||||
var productList []types.Product
|
||||
mr.MapReduceVoid(func(source chan<- interface{}) {
|
||||
for _, productRender := range productRenderModelList {
|
||||
if productRender.IsRendered == 1 {
|
||||
source <- productRender.ProductId
|
||||
}
|
||||
}
|
||||
}, func(item interface{}, writer mr.Writer[*model.Product], cancel func(error)) {
|
||||
id := item.(int64)
|
||||
product, findProductErr := l.svcCtx.ProductModel.FindOne(l.ctx, id)
|
||||
if findProductErr != nil {
|
||||
logx.WithContext(l.ctx).Errorf("获取渲染列表失败, 查找关联product错误: %d, err:%v", id, findProductErr)
|
||||
return
|
||||
}
|
||||
if product != nil && product.Id > 0 {
|
||||
product.Description = ""
|
||||
product.SellPrice = 0
|
||||
writer.Write(product)
|
||||
}
|
||||
}, func(pipe <-chan *model.Product, cancel func(error)) {
|
||||
for item := range pipe {
|
||||
var product types.Product
|
||||
_ = copier.Copy(&product, item)
|
||||
productList = append(productList, product)
|
||||
}
|
||||
})
|
||||
return &types.GetProductRenderListResponse{
|
||||
Product: productList,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user