43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package productlogic
|
|
|
|
import (
|
|
"context"
|
|
"tianyuan-api/pkg/sqlutil"
|
|
|
|
"tianyuan-api/apps/sentinel/internal/svc"
|
|
"tianyuan-api/apps/sentinel/sentinel"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetProductByCodeLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetProductByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByCodeLogic {
|
|
return &GetProductByCodeLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetProductByCodeLogic) GetProductByCode(in *sentinel.GetRecordByCodeRequest) (*sentinel.Product, error) {
|
|
product, err := l.svcCtx.ProductsModel.FindOneByProductCode(l.ctx, in.Code)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &sentinel.Product{
|
|
Id: product.Id,
|
|
ProductName: product.ProductName,
|
|
ProductCode: product.ProductCode,
|
|
ProductPrice: product.ProductPrice,
|
|
ProductDescription: sqlutil.NullStringToString(product.ProductDescription),
|
|
ProductContent: sqlutil.NullStringToString(product.ProductContent),
|
|
ProductGroup: product.ProductGroup,
|
|
}, nil
|
|
}
|