package cn.pluss.platform.mapper;

import cn.pluss.platform.dto.MerchantFeeDTO;
import cn.pluss.platform.entity.MerchantProfit;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
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 MerchantProfitMapper extends BaseMapper<MerchantProfit> {

    List<MerchantProfit> selectGroupMercProfit(@Param("userIdList") List<Long> userIdList);

    @Select("SELECT SUM(`price`) FROM tb_pluss_merchant_profit WHERE `status` = '1' AND userId = #{userId}")
    BigDecimal selectSumValidProfit(@Param("userId") String userId);

    MerchantProfit queryMerchantProfit(MerchantProfit merchantProfit);

    List<MerchantProfit> queryMerchantProfitList(MerchantProfit merchantProfit);

    List<MerchantProfit> queryMerchantProfitPage(Map map);

    Integer queryMerchantProfitPageCount(Map map);

    void saveMerchantProfitBatch(List<MerchantProfit> merchantProfitList);
    
    Double queryMerchantProfitSumConsumeFee(Map map);
    
    Double queryMerchantProfitSumPrice(Map map);
    
    Integer queryMerchantProfitPageCountGroupByOrderNumber(Map map);

    /**
     * 查询流水以及分润
     * @param userId            上级id, 也可能是上上级
     * @param merchantCodeList  店铺code列表
     * @param startTime         开始时间
     * @param endTime           截止时间
     * @return
     */
    List<MerchantFeeDTO> queryMerchantBillWithProfit(@Param("userId") String userId, @Param("merchantCodeList") List<String> merchantCodeList, @Param("startTime") Date startTime, @Param("endTime") Date endTime);


    void updateMerchantProfit(MerchantProfit p);

    /**
     * 批量更新 指定字段
     * @param listp
     */
    void updateBatch(List<MerchantProfit> listp);


    Map<String, Object> getProfitCount(Map<String, Object> map);

    /**
     * 通过分润数据查询对应的费率信息
     * @param merchantProfitList
     * @return
     */
    List<Map<String, Object>> queryMerchantProfitRate(@Param("merchantProfitList") List<MerchantProfit> merchantProfitList, @Param("userId") String userId);


    Map<String, BigDecimal> getProfitAmtCount(MerchantProfit condition);
}

