2026-02-28 15:29:16 +08:00
|
|
|
package stock
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"muyu-apiserver/gateway/internal/svc"
|
|
|
|
|
"muyu-apiserver/gateway/internal/types"
|
|
|
|
|
"muyu-apiserver/rpc/inventory/pb"
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ListStockLogic struct {
|
|
|
|
|
logx.Logger
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewListStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListStockLogic {
|
|
|
|
|
return &ListStockLogic{
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ListStockLogic) ListStock(req *types.ListProductReq) (resp *types.ListProductResp, err error) {
|
|
|
|
|
rpcResp, err := l.svcCtx.InventoryRpc.ListProduct(l.ctx, &pb.ListProductReq{
|
|
|
|
|
Page: req.Page,
|
|
|
|
|
PageSize: req.PageSize,
|
|
|
|
|
ProductName: req.ProductName,
|
|
|
|
|
Spec: req.Spec,
|
|
|
|
|
Color: req.Color,
|
|
|
|
|
Status: req.Status,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list := make([]types.ProductInfo, 0, len(rpcResp.List))
|
|
|
|
|
for _, p := range rpcResp.List {
|
|
|
|
|
list = append(list, types.ProductInfo{
|
2026-06-14 15:24:02 +08:00
|
|
|
ProductId: p.ProductId,
|
|
|
|
|
ProductName: p.ProductName,
|
|
|
|
|
ImageUrl: p.ImageUrl,
|
|
|
|
|
Spec: p.Spec,
|
|
|
|
|
Color: p.Color,
|
|
|
|
|
SalesPrice: p.SalesPrice,
|
|
|
|
|
Remark: p.Remark,
|
|
|
|
|
Status: p.Status,
|
|
|
|
|
CreatedAt: p.CreatedAt,
|
|
|
|
|
UpdatedAt: p.UpdatedAt,
|
2026-02-28 15:29:16 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &types.ListProductResp{
|
|
|
|
|
Total: rpcResp.Total,
|
|
|
|
|
List: list,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|