package com.jwipc.finance.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.finance.entity.AccountStatement;
import com.jwipc.finance.entity.AccountStatementDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jwipc.finance.model.po.FastStatementItemPO;
import com.jwipc.finance.model.po.InvoicedApplyItemPO;
import com.jwipc.finance.model.po.StatementInvoicedFlagPO;
import com.jwipc.finance.model.po.StatementItemPO;
import com.jwipc.finance.model.query.AccountStatementDetailQuery;
import com.jwipc.finance.model.query.CreateInvoicedApplyPageQuery;
import com.jwipc.finance.model.query.CreateInvoicedApplyQuery;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 对账模块-对账单明细表 Mapper 接口
 * </p>
 *
 * @author shenyang.ou
 * @since 2024-03-04
 */
public interface AccountStatementDetailMapper extends BaseMapper<AccountStatementDetail> {

    List<StatementItemPO> findByStatementId(@Param("asId") Long asId);


    List<StatementItemPO> findByStatementIdAndFactoryCode(@Param("asId") Long asId, @Param("factoryCode") String factoryCode);

    List<AccountStatementDetail> findByAsId(@Param("asIdList") List<Long> asIdList);

    List<AccountStatementDetail> selectDataByQuery(@Param("query") AccountStatementDetailQuery query);

    List<AccountStatementDetail> selectDataByQuery(Page<AccountStatementDetail> toPage,@Param("query") AccountStatementDetailQuery query);

    List<FastStatementItemPO> selectFastDataByQuery(@Param("query") AccountStatementDetailQuery query);

    List<FastStatementItemPO> selectFastDataByQuery(Page<AccountStatement> toPage, @Param("query") AccountStatementDetailQuery query);

    /**
     * 获取可以用于创建开票申请的对账单明细
     *
     * @param query 查询条件
     * @return 结果
     */
    List<AccountStatementDetail> findAllowUseAsd(@Param("query") CreateInvoicedApplyQuery query);

    /**
     * 提供创建开票申请时获取对账单明细数据
     *
     * @param allowUseAsdIdList 允许用于创建开票申请的对账单明细ID
     * @return 结果
     */
    List<InvoicedApplyItemPO> provideCreateInvoicedApply(@Param("allowUseAsdIdList") List<Long> allowUseAsdIdList);

    List<InvoicedApplyItemPO> provideCreateInvoicedApplyPage(@Param("query") CreateInvoicedApplyPageQuery query);

    List<InvoicedApplyItemPO> provideCreateInvoicedApplyPage(Page<AccountStatementDetail> dbPage, @Param("query") CreateInvoicedApplyPageQuery query);

    /**
     * 根据对账单ID获取对账单明细开票完成标识的情况
     *
     * @param asIdList 对账单ID集合
     * @return 结果
     */
    List<StatementInvoicedFlagPO> findStatementInvoicedFlag(@Param("asIdList") List<Long> asIdList);

}
