muyu-apiserver/gateway/internal/logic/purchase/stats/getpurchasestatsbyproductlogic.go

50 lines
1.3 KiB
Go
Raw Normal View History

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 GetPurchaseStatsByProductLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetPurchaseStatsByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPurchaseStatsByProductLogic {
return &GetPurchaseStatsByProductLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetPurchaseStatsByProductLogic) GetPurchaseStatsByProduct(req *types.PurchaseStatsSummaryReq) (*types.PurchaseStatsByProductResp, error) {
resp, err := l.svcCtx.PurchaseRpc.GetPurchaseStatsByProduct(l.ctx, &purchaseservice.PurchaseStatsSummaryReq{
StartDate: req.StartDate,
EndDate: req.EndDate,
})
if err != nil {
return nil, err
}
list := make([]types.PurchaseStatsByProductItem, 0, len(resp.List))
for _, p := range resp.List {
list = append(list, types.PurchaseStatsByProductItem{
ProductId: p.ProductId,
ProductName: p.ProductName,
Spec: p.Spec,
Color: p.Color,
TotalQty: p.TotalQty,
AvgUnitPrice: p.AvgUnitPrice,
TotalAmount: p.TotalAmount,
})
}
return &types.PurchaseStatsByProductResp{List: list}, nil
}