package cn.iocoder.yudao.module.product.dal.mysql.harvestinfo;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.harvestinfo.vo.HarvestInfoExportReqVO;
import cn.iocoder.yudao.module.product.controller.admin.harvestinfo.vo.HarvestInfoPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.statistics.vo.GoodsStatisticsDataRespVO;
import cn.iocoder.yudao.module.product.controller.admin.statistics.vo.MonthYOYRespVO;
import cn.iocoder.yudao.module.product.controller.admin.statistics.vo.WeekYOYRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.harvestinfo.HarvestInfoDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * 采收入库 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface HarvestInfoMapper extends BaseMapperX<HarvestInfoDO> {

    default PageResult<HarvestInfoDO> selectPage(HarvestInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<HarvestInfoDO>()
                .eqIfPresent(HarvestInfoDO::getHarverstId, reqVO.getHarverstId())
                .betweenIfPresent(HarvestInfoDO::getHarverstTime, reqVO.getHarverstTime())
                .betweenIfPresent(HarvestInfoDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(HarvestInfoDO::getBlockChainBlockIdentity, reqVO.getBlockChainBlockIdentity())
                .eqIfPresent(HarvestInfoDO::getBlockState, reqVO.getBlockState())
                .eqIfPresent(HarvestInfoDO::getBlockChainId, reqVO.getBlockChainId())
                .eqIfPresent(HarvestInfoDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .likeIfPresent(HarvestInfoDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .orderByDesc(HarvestInfoDO::getId));
    }

    default List<HarvestInfoDO> selectList(HarvestInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<HarvestInfoDO>()
                .eqIfPresent(HarvestInfoDO::getHarverstId, reqVO.getHarverstId())
                .betweenIfPresent(HarvestInfoDO::getHarverstTime, reqVO.getHarverstTime())
                .betweenIfPresent(HarvestInfoDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(HarvestInfoDO::getBlockChainBlockIdentity, reqVO.getBlockChainBlockIdentity())
                .eqIfPresent(HarvestInfoDO::getBlockState, reqVO.getBlockState())
                .eqIfPresent(HarvestInfoDO::getBlockChainId, reqVO.getBlockChainId())
                .orderByDesc(HarvestInfoDO::getId));
    }

    /**
     * 获得今年的采收数量
     */
    BigDecimal getNumStatisticsOfYear();

    /**
     * 获得月同比数据
     */
    List<MonthYOYRespVO> getMonthYOYDatas();

    /**
     * 获得周同比数据
     */
    List<WeekYOYRespVO> getWeekYOYDatas();

    /**
     * 获得月统计的商品采收数据
     */
    List<GoodsStatisticsDataRespVO> getDatasGroupByGoodsId(@Param("type") String type);

    /**
     * 获得今天的采收数量
     */
    BigDecimal getTodayHarvestCount();

}
