Pull latest changes from upstream/main (GitHub) including: - Purchase RPC service (proto, server, logic, models) - Gateway route updates for purchase endpoints - SQL migration and config updates Excludes deploy/bin/ pre-compiled arm64 binaries (builds use multi-stage Dockerfiles targeting amd64).
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
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
|
|
}
|