package com.sckw.payment.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sckw.payment.model.KwpLedgerTrade;
import com.sckw.payment.model.dto.LedgerPurchaseDto;
import com.sckw.payment.model.dto.LedgerSellDto;
import com.sckw.payment.model.dto.LedgerSize;
import com.sckw.payment.model.dto.LedgerTradeDto;
import com.sckw.payment.model.vo.LedgerSell;
import com.sckw.payment.model.vo.req.TradeReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * @author xucaiqin
 * @date 2023-07-17 15:34:43
 */

@Mapper
public interface KwpLedgerTradeMapper extends BaseMapper<KwpLedgerTrade> {

    List<LedgerSellDto> sellList(@Param("tradeReq") TradeReq tradeReq, @Param("authList") List<Long> authList);

    /**
     * 运营端 对账列表数据
     *
     * @param tradeReq
     * @return
     */
    List<LedgerSell> list(@Param("tradeReq") TradeReq tradeReq, @Param("authEntIdList") List<Long> authEntIdList);

    /**
     * 采购方数据需要过滤已保存、已撤回状态的数据
     *
     * @param tradeReq
     * @return
     */

    List<LedgerPurchaseDto> purchaseList(@Param("tradeReq") TradeReq tradeReq, @Param("authList") List<Long> authList);

    /**
     * 统计对账单数量
     *
     * @param tradeReq
     * @return
     */
    Map<String, Long> countOrder(@Param("tradeReq") TradeReq tradeReq);

    Map<String, Long> countSellOrder(@Param("tradeReq") TradeReq tradeReq, @Param("authList") List<Long> authList);

    Map<String, Long> countPurchaseOrder(@Param("tradeReq") TradeReq tradeReq, @Param("authList") List<Long> authList);

    /**
     * 运营端统计对账单数量
     *
     * @param tradeReq
     * @return
     */
    Map<String, Long> countOrder2(@Param("tradeReq") TradeReq tradeReq, @Param("authEntIdList") List<Long> authEntIdList);

    LedgerTradeDto selectId(@Param("id") Long id, @Param("unitType") Integer unitType);

    List<LedgerSellDto> selectSellIds(@Param("ids") List<Long> ids);

    List<LedgerPurchaseDto> selectPurchaseIds(@Param("ids") List<Long> ids);

    /**
     * app端对账统计
     *
     * @param tradeReq
     * @param status
     * @return
     */
    Long countSum(@Param("tradeReq") TradeReq tradeReq, @Param("status") List<Integer> status);

    /**
     * app端对账统计
     *
     * @param tradeReq
     * @param status
     * @return
     */
    BigDecimal countSumMoney(@Param("tradeReq") TradeReq tradeReq, @Param("status") List<Integer> status);

    void updatePrice(@Param("id") Long id, @Param("totalPrice") BigDecimal totalPrice);

    /**
     * @param entId     采购单位
     * @param entTarget 销售单位
     * @return
     */
    List<String> selectJoin(@Param("entId") Long entId, @Param("entTarget") Long entTarget);

    LedgerSize countSize(@Param("entId") Long entId, @Param("enterpriseIds") List<Long> enterpriseIds);

    /**
     * 运营端通过ids查询，导出数据
     *
     * @param ids
     * @return
     */
    List<LedgerSell> selectIds(@Param("ids") List<Long> ids);

    List<LedgerTradeDto> exportList(@Param("tradeReq") TradeReq tradeReq, @Param("idList") List<Long> idList, @Param("authList") List<Long> authList);
}