2026-02-28 15:29:16 +08:00
|
|
|
package product
|
|
|
|
|
|
|
|
|
|
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 CreateProductLogic struct {
|
|
|
|
|
logx.Logger
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
|
|
|
|
|
return &CreateProductLogic{
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *CreateProductLogic) CreateProduct(req *types.CreateProductReq) (resp *types.IdResp, err error) {
|
|
|
|
|
rpcResp, err := l.svcCtx.InventoryRpc.CreateProduct(l.ctx, &pb.CreateProductReq{
|
2026-07-05 08:06:28 +09:00
|
|
|
ProductName: req.ProductName,
|
|
|
|
|
ImageUrl: req.ImageUrl,
|
|
|
|
|
Spec: req.Spec,
|
|
|
|
|
Color: req.Color,
|
|
|
|
|
ColorNo: req.ColorNo,
|
|
|
|
|
ProductCode: req.ProductCode,
|
|
|
|
|
SalesPrice: req.SalesPrice,
|
|
|
|
|
Remark: req.Remark,
|
|
|
|
|
Pans: panInputsToPb(req.Pans),
|
|
|
|
|
InitialBatch: productBatchInputToPb(req.InitialBatch),
|
2026-02-28 15:29:16 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &types.IdResp{Id: rpcResp.Id}, nil
|
|
|
|
|
}
|
2026-06-14 15:24:02 +08:00
|
|
|
|
|
|
|
|
func panInputsToPb(pans []types.PanInput) []*pb.PanInput {
|
|
|
|
|
if len(pans) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
out := make([]*pb.PanInput, 0, len(pans))
|
|
|
|
|
for _, p := range pans {
|
|
|
|
|
out = append(out, &pb.PanInput{
|
|
|
|
|
Name: p.Name,
|
|
|
|
|
Position: p.Position,
|
|
|
|
|
BoltLengths: p.BoltLengths,
|
2026-07-05 08:06:28 +09:00
|
|
|
BatchId: p.BatchId,
|
2026-06-14 15:24:02 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
2026-07-05 08:06:28 +09:00
|
|
|
|
|
|
|
|
func productBatchInputToPb(input types.ProductBatchInput) *pb.ProductBatchInput {
|
|
|
|
|
if input == (types.ProductBatchInput{}) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return &pb.ProductBatchInput{
|
|
|
|
|
BatchNo: input.BatchNo,
|
|
|
|
|
YarnRatio: input.YarnRatio,
|
|
|
|
|
WarpWeightGM: input.WarpWeightGM,
|
|
|
|
|
WeftWeightGM: input.WeftWeightGM,
|
|
|
|
|
ProductionProcess: input.ProductionProcess,
|
|
|
|
|
Remark: input.Remark,
|
|
|
|
|
}
|
|
|
|
|
}
|