service.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package statisticsrv
  2. import (
  3. "Cold_Logistic/internal/server/infra/dao"
  4. "context"
  5. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  6. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  7. )
  8. type StatisticService struct {
  9. store *dao.DataStore
  10. }
  11. func NewStatisticService(store *dao.DataStore) *StatisticService {
  12. return &StatisticService{store: store}
  13. }
  14. // OrderNumTimeStat 订单数量统计-按时间
  15. func (srv *StatisticService) OrderNumTimeStat(ctx context.Context, req OrderNumTimeStatReqVO) (res []dao.StaticNumData, err error) {
  16. dto := dao.StaticOrderNumDTO{
  17. StatType: req.StatType,
  18. TimeStart: req.TimeStart,
  19. TimeEnd: req.TimeEnd,
  20. OrderStatus: req.OrderStatus,
  21. }
  22. res, err = srv.store.ExpressOrder().StaticNumByTime(ctx, dto)
  23. if err != nil {
  24. return res, errors.WithStackOnce(err)
  25. }
  26. return res, nil
  27. }
  28. // OrderNumUserStat 订单数量统计-按用户+时间
  29. func (srv *StatisticService) OrderNumUserStat(ctx context.Context, req OrderNumUserStatReqVO) (res core.PageListResponse, err error) {
  30. dto := dao.StaticOrderNumDTO{
  31. Page: req.Page,
  32. StatType: req.Search.StatType,
  33. TimeStart: req.Search.TimeStart,
  34. TimeEnd: req.Search.TimeEnd,
  35. OrderStatus: req.Search.OrderStatus,
  36. }
  37. list, total, err := srv.store.ExpressOrder().StaticNumByUser(ctx, dto)
  38. if err != nil {
  39. return res, errors.WithStackOnce(err)
  40. }
  41. res.Total = total
  42. res.TotalPage = total / int64(req.Page.Size)
  43. res.Count = len(list)
  44. res.List = list
  45. return res, nil
  46. }