package cn.iocoder.yudao.module.flow.dal.mysql.outbound;

import java.math.BigDecimal;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.flow.dal.dataobject.outbound.OutboundDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.flow.controller.admin.outbound.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 出库单 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface OutboundMapper extends BaseMapperX<OutboundDO> {

    default PageResult<OutboundDO> selectPage(OutboundPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OutboundDO>()
                .eqIfPresent(OutboundDO::getVendorId, reqVO.getVendorId())
                .likeIfPresent(OutboundDO::getVendorName, reqVO.getVendorName())
                .eqIfPresent(OutboundDO::getOutBoundId, reqVO.getOutBoundId())
                .betweenIfPresent(OutboundDO::getOutBoundTime, reqVO.getOutBoundTime())
                .eqIfPresent(OutboundDO::getCarrierVehicles, reqVO.getCarrierVehicles())
                .eqIfPresent(OutboundDO::getCarrier, reqVO.getCarrier())
                .eqIfPresent(OutboundDO::getCarrierContact, reqVO.getCarrierContact())
                .eqIfPresent(OutboundDO::getBlockState, reqVO.getBlockState())
                .eqIfPresent(OutboundDO::getBlockChainId, reqVO.getBlockChainId())
                .eqIfPresent(OutboundDO::getBlockChainBlockIdentity, reqVO.getBlockChainBlockIdentity())
                .eqIfPresent(OutboundDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .likeIfPresent(OutboundDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .betweenIfPresent(OutboundDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OutboundDO::getId));
    }

    default List<OutboundDO> selectList(OutboundExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<OutboundDO>()
                .eqIfPresent(OutboundDO::getVendorId, reqVO.getVendorId())
                .likeIfPresent(OutboundDO::getVendorName, reqVO.getVendorName())
                .eqIfPresent(OutboundDO::getOutBoundId, reqVO.getOutBoundId())
                .betweenIfPresent(OutboundDO::getOutBoundTime, reqVO.getOutBoundTime())
                .eqIfPresent(OutboundDO::getCarrierVehicles, reqVO.getCarrierVehicles())
                .eqIfPresent(OutboundDO::getCarrier, reqVO.getCarrier())
                .eqIfPresent(OutboundDO::getCarrierContact, reqVO.getCarrierContact())
                .eqIfPresent(OutboundDO::getBlockState, reqVO.getBlockState())
                .eqIfPresent(OutboundDO::getBlockChainId, reqVO.getBlockChainId())
                .eqIfPresent(OutboundDO::getBlockChainBlockIdentity, reqVO.getBlockChainBlockIdentity())
                .eqIfPresent(OutboundDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .likeIfPresent(OutboundDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .betweenIfPresent(OutboundDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OutboundDO::getId));
    }

    /**
     * 获得月统计的出库每个商品总重量数据
     */
    List<OutboundStatisticsDataRespVO> getDatasGroupByGoodsId(@Param("type") String type);

    /**
     * 获取最新7天每天总数量除去当天
     * @return
     */
    List<OutboundStatisticsDataRespVO> getSixDatasByGoodsId();

    BigDecimal getTodayOutboundCount();
}
