muyu-apiserver/rpc/inventory/internal/logic/approvestockadjustlogic.go
Chever John 379fb28d92 chore: sync codebase with upstream
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).
2026-06-14 15:24:02 +08:00

67 lines
1.7 KiB
Go

package logic
import (
"context"
"muyu-apiserver/pkg/metrics"
"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 ApproveStockAdjustLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewApproveStockAdjustLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApproveStockAdjustLogic {
return &ApproveStockAdjustLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApproveStockAdjustLogic) ApproveStockAdjust(in *pb.ApproveStockAdjustReq) (*pb.Empty, error) {
adjust, err := l.svcCtx.StockAdjustModel.FindOneByAdjustId(l.ctx, in.AdjustId)
if err != nil {
return nil, status.Error(codes.NotFound, "stock adjust not found")
}
if adjust.Status != 0 {
return nil, status.Error(codes.FailedPrecondition, "stock adjust is not in pending status")
}
adjust.Approver = in.Approver
switch in.Action {
case 1: // approve
// In the three-layer model, actual stock adjustments are done via
// SaveBolts/SavePans. Approving records the approval decision only.
adjust.Status = 1
case 2: // reject
adjust.Status = 2
default:
return nil, status.Errorf(codes.InvalidArgument, "unsupported action: %d", in.Action)
}
err = l.svcCtx.StockAdjustModel.Update(l.ctx, adjust)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
tenantId := tenantctx.ExtractTenantId(l.ctx)
actionLabel := "approve"
if in.Action == 2 {
actionLabel = "reject"
}
metrics.StockAdjustApprovedTotal.WithLabelValues(tenantId, actionLabel).Inc()
return &pb.Empty{}, nil
}