<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzs.system.config.mapper.BdRangeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdRange">
        <id column="PK_ID" property="pkId" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="RANGE_NAME" property="rangeName" />
        <result column="PK_TRANSACTION" property="pkTransaction" />
        <result column="MONEY_RATIO" property="moneyRatio" />
        <result column="ACHIEVE_RATIO" property="achieveRatio" />
    </resultMap>

    <select id="queryRangeDto" resultType="com.hzs.system.config.dto.RangeDTO">
        select br.range_name,br.range_value,bd.pk_range,bd.range_type,bd.pk_level,br.pk_country,(100-br.achieve_ratio) achieve_ratio from bd_range br
        inner join bd_range_details bd
        on br.pk_id=bd.pk_range
        where br.del_flag=0 and bd.del_flag=0
        <if test="pkCountry != null">
            and br.pk_country=#{pkCountry}
        </if>
        <if test="rangeType != null">
            and bd.range_type=#{rangeType}
        </if>
        <if test="pkLevel != null">
            and bd.pk_level=#{pkLevel}
        </if>
        order by br.pk_country,pk_range,range_type,pk_level
    </select>

</mapper>
