Align origin/main with upstream/main (GitHub). The two branches diverged due to pre-rebase vs post-rebase merge commits for the k8s-amd64-dockerfiles feature. Includes: multi-stage Go compilation Dockerfiles, pan-bolt inventory features, CRM relations, Excel import tooling, proto/gRPC updates, migration scripts, and tools/ directory. Excludes deploy/bin/ pre-compiled binaries (arm64, not needed for amd64 K3s cluster; builds use multi-stage Dockerfiles now).
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
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{
|
|
ProductName: req.ProductName,
|
|
ImageUrl: req.ImageUrl,
|
|
Spec: req.Spec,
|
|
Color: req.Color,
|
|
SalesPrice: req.SalesPrice,
|
|
Remark: req.Remark,
|
|
Pans: panInputsToPb(req.Pans),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.IdResp{Id: rpcResp.Id}, nil
|
|
}
|
|
|
|
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,
|
|
})
|
|
}
|
|
return out
|
|
}
|