package com.hfkj.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * mapper扩展类
 */
public interface BsRebateRewardMapperExt {

    @Select("select case when sum(trade_amount) is null then 0 else sum(trade_amount) end trade_amount from bs_trade_order " +
            "where pay_time BETWEEN #{timeS} and  #{timeE} and `status` = 3 and refund_type is null")
    BigDecimal queryTradeAmount(@Param("timeS") String timeS,@Param("timeE") String timeE);

    @Select(" select a.mer_id merId,TRUNCATE((a.trade_amount / b.total_trade_amount) * 100, 2) as ratio " +
            " from (select mer_id,sum(trade_amount) trade_amount from bs_trade_order " +
            " where pay_time BETWEEN #{timeS} and #{timeE} and mer_id in (${merIds})" +
            " and `status` = 3 and refund_type is null  GROUP BY mer_id ORDER BY trade_amount desc) a" +
            " " +
            " LEFT JOIN (select sum(trade_amount) total_trade_amount from bs_trade_order " +
            " where pay_time BETWEEN #{timeS} and #{timeE} and mer_id in (${merIds}) " +
            " and `status` = 3 and refund_type is null) b on 1 = 1")
    List<Map<String,Object>> queryTradeRatio(@Param("timeS") String timeS,@Param("timeE") String timeE, @Param("merIds") String merIds);

}
