package com.zfire.mall.manager.commonmapper.wallet;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.bean.wallet.*;
import com.zfire.mall.manager.plus.entity.CustomerWallet;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

public interface WalletCommonMapper {


    @Select("select * from customer_wallet where customer_wallet_id=#{customerWalletId} for update")
    public CustomerWallet getCustomerWalletByIdForUpdate(@Param("customerWalletId") String customerWalletId);

    /**
     * 查询经销商的所有钱包
     */
    @SqlParser(filter = true)
    public IPage<CustomerWalletBean> queryWalletByCustomerId(
            IPage page,
            @Param("customerId") String customerId,
            @Param("type") String type,
            @Param("hasRecord") Boolean hasRecord,
            @Param("minFreeAmount") BigDecimal minFreeAmount,
            @Param("maxFreeAmount") BigDecimal maxFreeAmount
    );


    /**
     * 查询经销商的钱包详情
     */
    @SqlParser(filter = true)
    public CustomerWalletBean queryWalletDetailByCustomerId(
            @Param("customerWalletId") String customerWalletId
    );

    /**
     * 重载可用的信用额度
     */
    @SqlParser(filter = true)
    public void reloadCustomerWalletCert(@Param("customerId") String customerId);

    /**
     * 财务汇总
     */
    @SqlParser(filter = true)
    public List<Map<String,Object>> queryTotalAmount(
            @Param("adminWebsitIds") List<String> adminWebsitIds,
            @Param("type") String type
    );

    /**
     * 经销商的余额汇总
     */
    @SqlParser(filter = true)
    public IPage<Map<String,Object>> queryCustomerTotalAmount(
            IPage page,
            @Param("customerNumber") String customerNumber,
            @Param("customerName") String customerName,
            @Param("adminWebsitIds") List<String> adminWebsitIds,
            @Param("walletId") String walletId
    );

    //经销商的余额汇总导出数据
    @SqlParser(filter = true)
    public List<CustomerTotalAmountExportBean> queryCustomerTotalAmountExport(@Param("customerNumber") String customerNumber,
                                                                              @Param("customerName") String customerName,
                                                                              @Param("adminWebsitIds") List<String> adminWebsitIds,
                                                                              @Param("walletId") String walletId,
                                                                              @Param("byCustomer") Boolean byCustomer);



    @SqlParser(filter = true)
    public IPage<RebateWalletSaleBean> queryRebateWalletSaleTypeList(IPage page,
                                                                     @Param("name") String name,
                                                                     @Param("saleTypeCode") String saleTypeCode,
                                                                     @Param("saleTypeName") String saleTypeName,
                                                                     @Param("status") Boolean status);


    /**
     * 初始化现金钱包
     */
    @SqlParser(filter = true)
    public void initCustomerWallet(@Param("customerId") String customerId);

    /**
     * 初始化返利钱包
     */
    @SqlParser(filter = true)
    public void initCustomerWallet2();


    /**
     * 查询金额
     */
    @SqlParser(filter = true)
    public AmountCountBean amountCount(@Param("customerId") String customerId,
                                       @Param("customerNumber") String customerNumber,
                                       @Param("customerName")  String customerName,
                                       @Param("type") String type,
                                       @Param("customerWalletId") String customerWalletId,
                                       @Param("walletRebateId") String walletRebateId,
                                       @Param("billNo") String billNo,
                                       @Param("startTime") String startTime,
                                       @Param("endTime") String endTime,
                                       @Param("isReconciliation") Boolean isReconciliation,
                                       @Param("isCustomer") Boolean isCustomer,
                                       @Param("billType") String billType
                                       );


    @SqlParser(filter = true)
    List<WalletCountBean> queryWalletByCustomerIdRange(
            @Param("startCustomerId") String startCustomerId,
            @Param("endCustomerId") String endCustomerId
    );

    @SqlParser(filter = true)
    List<WalletCountBean>  queryWalletByCustomerIdRangeCount(
            @Param("startCustomerId") String startCustomerId,
            @Param("endCustomerId") String endCustomerId
    );

    @SqlParser(filter = true)
    List<CustomerCountMonthBean>  queryCommonlyMonthCount(
            @Param("month") String month
    );

    @SqlParser(filter = true)
    List<CustomerCountMonthBean>  queryrebateMonthCount(
            @Param("month") String month
    );

}
