package com.hfkj.dao;

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

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

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

    @Select("<script>" +
            " SELECT" +
            " b.chain_brand_id chainBrandId," +
            " b.chain_brand_name chainBrandName," +
            " b.province_name provinceName," +
            " b.city_name cityName," +
            " b.area_name areaName," +
            " b.mer_no merNo," +
            " b.mer_name merName," +
            " b.address," +
            " case when chain_brand_id is not null" +
            " then " +
            " (case b.chain_brand_settle_type" +
            " when 1 then (select amount from bs_merchant_chain_brand_account where mer_chain_brand_id = b.chain_brand_id and `status` = 1 LIMIT 1)" +
            " when 2 then a.amount end)" +
            " else a.amount end amount" +
            " FROM" +
            " bs_merchant_account a" +
            " LEFT JOIN bs_merchant b ON a.mer_no = b.mer_no" +
            " where 1 = 1" +
            " <if test='param.chainBrandIdIsNull != null'> and b.chain_brand_id is null </if>" +
            " <if test='param.provinceCode != null'> and b.province_code = #{param.provinceCode} </if>" +
            " <if test='param.cityCode != null'> and b.city_code = #{param.cityCode} </if>" +
            " <if test='param.areaCode != null'> and b.area_code = #{param.areaCode} </if>" +
            " <if test='param.merNo != null'> and b.mer_no like concat('%',#{param.merNo},'%') </if>" +
            " <if test='param.merName != null'> and b.mer_name like concat('%',#{param.merName},'%') </if>" +
            " ORDER BY a.amount asc" +
            "</script>")
    List<TreeMap<String,Object>> selectMerList(@Param("param") Map<String,Object> param);
}
