package com.yc.ship.module.trade.dal.mysql.invoice;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.trade.controller.admin.invoice.vo.InvoicePageReqVO;
import com.yc.ship.module.trade.controller.admin.invoice.vo.InvoiceRespVO;
import com.yc.ship.module.trade.dal.dataobject.invoice.InvoiceDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 电子发票 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface InvoiceMapper extends BaseMapperX<InvoiceDO> {

    default PageResult<InvoiceDO> selectPage(InvoicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InvoiceDO>()
                .eqIfPresent(InvoiceDO::getTransactionNo, reqVO.getTransactionNo())
                .eqIfPresent(InvoiceDO::getSource, reqVO.getSource())
                .eqIfPresent(InvoiceDO::getTitleType, reqVO.getTitleType())
                .eqIfPresent(InvoiceDO::getInvoiceType, reqVO.getInvoiceType())
                .eqIfPresent(InvoiceDO::getInvoiceStatus, reqVO.getInvoiceStatus())
                .likeIfPresent(InvoiceDO::getBuyerName, reqVO.getBuyerName())
                .eqIfPresent(InvoiceDO::getBuyerTaxCode, reqVO.getBuyerTaxCode())
                .eqIfPresent(InvoiceDO::getBuyerTel, reqVO.getBuyerTel())
                .eqIfPresent(InvoiceDO::getBuyerEmail, reqVO.getBuyerEmail())
                .eqIfPresent(InvoiceDO::getBuyerPhone, reqVO.getBuyerPhone())
                .likeIfPresent(InvoiceDO::getSalesName, reqVO.getSalesName())
                .eqIfPresent(InvoiceDO::getSalesAddress, reqVO.getSalesAddress())
                .eqIfPresent(InvoiceDO::getSalesTaxCode, reqVO.getSalesTaxCode())
                .eqIfPresent(InvoiceDO::getCFphm, reqVO.getCFphm())
                .eqIfPresent(InvoiceDO::getAgencyId, reqVO.getAgencyId())
                .eqIfPresent(InvoiceDO::getAccountId, reqVO.getAccountId())
                .eqIfPresent(InvoiceDO::getStoreId, reqVO.getStoreId())
                .orderByDesc(InvoiceDO::getId)
                .geIfPresent(InvoiceDO::getCKprq, reqVO.getBeginCKprq())
                .leIfPresent(InvoiceDO::getCKprq, reqVO.getEndCKprq()));
    }

    List<InvoiceDO> queryInvoiceOrder (@Param("orderNo") String orderNo);

    @TenantIgnore
    IPage<InvoiceRespVO> queryInvoicePage(IPage<InvoiceRespVO> iPage, @Param("param") InvoicePageReqVO pageReqVO);

}