package logic import ( "context" "muyu-apiserver/pkg/tenantctx" "muyu-apiserver/rpc/inventory/internal/svc" "muyu-apiserver/rpc/inventory/pb" "github.com/zeromicro/go-zero/core/logx" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) type UpdateProductBatchLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewUpdateProductBatchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductBatchLogic { return &UpdateProductBatchLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)} } func (l *UpdateProductBatchLogic) UpdateProductBatch(in *pb.UpdateProductBatchReq) (*pb.Empty, error) { tenantId := tenantctx.ExtractTenantId(l.ctx) batch, err := l.svcCtx.ProductBatchModel.FindOneByProductAndBatchId(l.ctx, tenantId, in.ProductId, in.BatchId) if err != nil { return nil, status.Error(codes.NotFound, "批次不存在") } if err := batchInputToModelFields(in.Batch, batch); err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } if in.Status == 0 { batch.Status = 0 } else { batch.Status = 1 } if err := l.svcCtx.ProductBatchModel.Update(l.ctx, batch); err != nil { return nil, status.Error(codes.Internal, err.Error()) } return &pb.Empty{}, nil }