2026-02-28 15:29:16 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-06-14 15:24:02 +08:00
|
|
|
"muyu-apiserver/pkg/metrics"
|
|
|
|
|
"muyu-apiserver/pkg/tenantctx"
|
2026-02-28 15:29:16 +08:00
|
|
|
"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 ConfirmStockCheckLogic struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
logx.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewConfirmStockCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConfirmStockCheckLogic {
|
|
|
|
|
return &ConfirmStockCheckLogic{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ConfirmStockCheckLogic) ConfirmStockCheck(in *pb.ConfirmStockCheckReq) (*pb.Empty, error) {
|
|
|
|
|
check, err := l.svcCtx.StockCheckModel.FindOneByCheckId(l.ctx, in.CheckId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, status.Error(codes.NotFound, "stock check not found")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if check.Status != 0 && check.Status != 1 {
|
|
|
|
|
return nil, status.Error(codes.FailedPrecondition, "stock check cannot be confirmed in current status")
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 15:24:02 +08:00
|
|
|
// In the three-layer model, stock is held in bolt records.
|
|
|
|
|
// Confirming a stock check marks it as completed; bolt-level adjustments
|
|
|
|
|
// are handled separately via the SaveBolts/SavePans endpoints.
|
2026-02-28 15:29:16 +08:00
|
|
|
check.Status = 2
|
|
|
|
|
err = l.svcCtx.StockCheckModel.Update(l.ctx, check)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 15:24:02 +08:00
|
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
|
|
|
metrics.StockCheckConfirmedTotal.WithLabelValues(tenantId).Inc()
|
|
|
|
|
|
2026-02-28 15:29:16 +08:00
|
|
|
return &pb.Empty{}, nil
|
|
|
|
|
}
|