package com.czg.service.order.service.impl;

import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.SaleSummaryService;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.order.vo.SaleSummaryInfoVo;
import com.czg.service.order.mapper.ShopProdStatisticMapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 销量统计Service实现类
 *
 * @author tankaikai
 * @since 2025-03-07 15:32
 */
@Service
public class SaleSummaryServiceImpl implements SaleSummaryService {
    @Resource
    private ShopProdStatisticMapper shopProdStatisticMapper;

    @Override
    public SaleSummaryCountVo summaryCount(SaleSummaryCountParam param) {
        SaleSummaryCountVo saleSummaryCount = shopProdStatisticMapper.getSaleSummaryCount(param);
        if (saleSummaryCount == null) {
            saleSummaryCount = new SaleSummaryCountVo();
        }
        return saleSummaryCount;
    }

    @Override
    public Page<SaleSummaryInfoVo> summaryPage(SaleSummaryCountParam param) {
        PageHelper.startPage(PageUtil.buildPageHelp());
        PageInfo<SaleSummaryInfoVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findSaleSummaryList(param));
        return PageUtil.convert(pageInfo);
    }

    @Override
    public List<SaleSummaryInfoVo> summaryList(SaleSummaryCountParam param) {
        return shopProdStatisticMapper.findSaleSummaryList(param);
    }
}
