74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"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 GetStockAdjustLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewGetStockAdjustLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockAdjustLogic {
|
||
|
|
return &GetStockAdjustLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *GetStockAdjustLogic) GetStockAdjust(in *pb.GetStockAdjustReq) (*pb.StockAdjustInfo, error) {
|
||
|
|
adjust, err := l.svcCtx.StockAdjustModel.FindOneByAdjustId(l.ctx, in.AdjustId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.NotFound, "stock adjust not found")
|
||
|
|
}
|
||
|
|
|
||
|
|
details, err := l.svcCtx.AdjustDetailModel.FindByAdjustId(l.ctx, in.AdjustId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
pbDetails := make([]*pb.StockAdjustDetailInfo, 0, len(details))
|
||
|
|
for _, d := range details {
|
||
|
|
productName := ""
|
||
|
|
product, err := l.svcCtx.ProductModel.FindOneByProductId(l.ctx, d.ProductId)
|
||
|
|
if err == nil {
|
||
|
|
productName = product.ProductName
|
||
|
|
}
|
||
|
|
|
||
|
|
pbDetails = append(pbDetails, &pb.StockAdjustDetailInfo{
|
||
|
|
DetailId: d.DetailId,
|
||
|
|
AdjustId: d.AdjustId,
|
||
|
|
ProductId: d.ProductId,
|
||
|
|
ProductName: productName,
|
||
|
|
BeforeQuantity: fmt.Sprintf("%.2f", d.BeforeQuantity),
|
||
|
|
AdjustQuantity: fmt.Sprintf("%.2f", d.AdjustQuantity),
|
||
|
|
AfterQuantity: fmt.Sprintf("%.2f", d.AfterQuantity),
|
||
|
|
Remark: d.Remark.String,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.StockAdjustInfo{
|
||
|
|
AdjustId: adjust.AdjustId,
|
||
|
|
AdjustNo: adjust.AdjustNo,
|
||
|
|
AdjustDate: adjust.AdjustDate.Format("2006-01-02"),
|
||
|
|
AdjustReason: adjust.AdjustReason,
|
||
|
|
Operator: adjust.Operator,
|
||
|
|
Approver: adjust.Approver,
|
||
|
|
Status: adjust.Status,
|
||
|
|
Remark: adjust.Remark.String,
|
||
|
|
CreatedAt: adjust.CreatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
UpdatedAt: adjust.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
Details: pbDetails,
|
||
|
|
}, nil
|
||
|
|
}
|