49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"muyu-apiserver/pkg/tenantctx"
|
||
|
|
"muyu-apiserver/rpc/purchase/internal/svc"
|
||
|
|
"muyu-apiserver/rpc/purchase/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListInventoryLogLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListInventoryLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListInventoryLogLogic {
|
||
|
|
return &ListInventoryLogLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListInventoryLogLogic) ListInventoryLog(in *pb.ListInventoryLogReq) (*pb.ListInventoryLogResp, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
list, total, err := l.svcCtx.InventoryLogModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.ProductId, in.RefType, in.ChangeType, in.StartDate, in.EndDate)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items := make([]*pb.InventoryLogInfo, 0, len(list))
|
||
|
|
for _, lg := range list {
|
||
|
|
items = append(items, &pb.InventoryLogInfo{
|
||
|
|
LogId: lg.LogId,
|
||
|
|
ProductId: lg.ProductId,
|
||
|
|
ChangeQty: fmt.Sprintf("%.2f", lg.ChangeQty),
|
||
|
|
BalanceAfter: fmt.Sprintf("%.2f", lg.BalanceAfter),
|
||
|
|
ChangeType: lg.ChangeType,
|
||
|
|
RefType: lg.RefType,
|
||
|
|
RefId: lg.RefId,
|
||
|
|
ContactId: lg.ContactId,
|
||
|
|
LogDate: lg.LogDate.Format("2006-01-02"),
|
||
|
|
Operator: lg.Operator,
|
||
|
|
Remark: lg.Remark.String,
|
||
|
|
CreatedAt: lg.CreatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return &pb.ListInventoryLogResp{Total: total, List: items}, nil
|
||
|
|
}
|