69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
|
|
package plan
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/pkg/ctxdata"
|
||
|
|
"muyu-apiserver/rpc/production/productionservice"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CreateProductionPlanLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCreateProductionPlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductionPlanLogic {
|
||
|
|
return &CreateProductionPlanLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CreateProductionPlanLogic) CreateProductionPlan(req *types.CreateProductionPlanReq) (*types.IdResp, error) {
|
||
|
|
yarnRatios := make([]*productionservice.YarnRatioReq, 0, len(req.YarnRatios))
|
||
|
|
for _, yr := range req.YarnRatios {
|
||
|
|
yarnRatios = append(yarnRatios, &productionservice.YarnRatioReq{
|
||
|
|
YarnName: yr.YarnName,
|
||
|
|
Ratio: yr.Ratio,
|
||
|
|
AmountPerMeter: yr.AmountPerMeter,
|
||
|
|
TotalAmount: yr.TotalAmount,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
processSteps := make([]*productionservice.ProcessStepReq, 0, len(req.ProcessSteps))
|
||
|
|
for _, ps := range req.ProcessSteps {
|
||
|
|
processSteps = append(processSteps, &productionservice.ProcessStepReq{
|
||
|
|
StepType: ps.StepType,
|
||
|
|
StepOrder: ps.StepOrder,
|
||
|
|
Remark: ps.Remark,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
resp, err := l.svcCtx.ProductionRpc.CreateProductionPlan(l.ctx, &productionservice.CreateProductionPlanReq{
|
||
|
|
ProductId: req.ProductId,
|
||
|
|
ProductName: req.ProductName,
|
||
|
|
Color: req.Color,
|
||
|
|
FabricCode: req.FabricCode,
|
||
|
|
ColorCode: req.ColorCode,
|
||
|
|
TargetQuantity: req.TargetQuantity,
|
||
|
|
YarnUsagePerMeter: req.YarnUsagePerMeter,
|
||
|
|
ProductionPrice: req.ProductionPrice,
|
||
|
|
SupplierId: req.SupplierId,
|
||
|
|
Remark: req.Remark,
|
||
|
|
StartTime: req.StartTime,
|
||
|
|
Creator: ctxdata.GetUserId(l.ctx),
|
||
|
|
YarnRatios: yarnRatios,
|
||
|
|
ProcessSteps: processSteps,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return &types.IdResp{Id: resp.Id}, nil
|
||
|
|
}
|