package stats import ( "context" "muyu-apiserver/gateway/internal/svc" "muyu-apiserver/gateway/internal/types" "muyu-apiserver/rpc/purchase/purchaseservice" "github.com/zeromicro/go-zero/core/logx" ) type GetPurchaseStatsBySupplierLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetPurchaseStatsBySupplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPurchaseStatsBySupplierLogic { return &GetPurchaseStatsBySupplierLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *GetPurchaseStatsBySupplierLogic) GetPurchaseStatsBySupplier(req *types.PurchaseStatsSummaryReq) (*types.PurchaseStatsBySupplierResp, error) { resp, err := l.svcCtx.PurchaseRpc.GetPurchaseStatsBySupplier(l.ctx, &purchaseservice.PurchaseStatsSummaryReq{ StartDate: req.StartDate, EndDate: req.EndDate, }) if err != nil { return nil, err } list := make([]types.PurchaseStatsBySupplierItem, 0, len(resp.List)) for _, s := range resp.List { list = append(list, types.PurchaseStatsBySupplierItem{ SupplierId: s.SupplierId, SupplierName: s.SupplierName, OrderCount: s.OrderCount, TotalAmount: s.PurchaseAmount, PaidAmount: s.PaidAmount, }) } return &types.PurchaseStatsBySupplierResp{List: list}, nil }