<?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.BdAreaCurrencyDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdAreaCurrencyDetail">
        <id column="PK_ID" property="pkId" />
        <result column="PK_AREA_CURRENCY" property="pkAreaCurrency" />
        <result column="PK_ACCOUNT" property="pkAccount" />
        <result column="DEDUCT_SORT" property="deductSort" />
        <result column="DEDUCT_RATIO" property="deductRatio" />
        <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="IS_DEDUCTION" property="isDeduction" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PK_ID, PK_AREA_CURRENCY, PK_ACCOUNT, DEDUCT_SORT, DEDUCT_RATIO, DEL_FLAG, PK_COUNTRY, PK_CREATOR, CREATION_TIME, PK_MODIFIED, MODIFIED_TIME
    </sql>


<!--    获取可使用最扣除大比例-->
    <select id="getSumDeductRatio" parameterType="com.hzs.common.domain.system.config.BdAreaCurrencyDetail"
            resultType="com.hzs.common.domain.system.config.BdAreaCurrencyDetail">
        select sum(DEDUCT_RATIO) as deductRatio from BD_AREA_CURRENCY_DETAIL
        where  DEL_FLAG = 0
        <if test="pkAreaCurrency != null">
            AND  PK_AREA_CURRENCY= #{pkAreaCurrency}
        </if>
        <if test="pkCountry != null">
            AND  PK_COUNTRY= #{pkCountry}
        </if>

    </select>

<!--    校验扣款顺序是否唯一-->
    <select id="checkDeductSort" parameterType="com.hzs.common.domain.system.config.BdAreaCurrencyDetail"
            resultType="com.hzs.common.domain.system.config.BdAreaCurrencyDetail">
        select PK_ID,DEDUCT_SORT from BD_AREA_CURRENCY_DETAIL
        where and DEL_FLAG = 0
        <if test="pkId != null">
            AND  PK_ID!= #{pkId}
        </if>
        <if test="deductSort != null">
            AND  DEDUCT_SORT= #{deductSort}
        </if>

    </select>

    <select id="getAreaCurrencyDetailList"
            parameterType="com.hzs.common.domain.system.config.ext.BdAreaCurrencyDetailExt"
            resultType="com.hzs.common.domain.system.config.ext.BdAreaCurrencyDetailExt">
        SELECT
        a.PK_ID,
        a.PK_AREA_CURRENCY,
        a.PK_ACCOUNT,
        a.DEDUCT_SORT,
        a.DEDUCT_RATIO,
        a.DEL_FLAG as delAreaCurrency,
        a.PK_COUNTRY,
        a.PK_CREATOR,
        a.CREATION_TIME,
        a.PK_MODIFIED,
        a.MODIFIED_TIME,
        b.ACCOUNT_NAME as accountName
        FROM
        BD_AREA_CURRENCY_DETAIL a
        INNER JOIN BD_ACCOUNT b ON a.PK_ACCOUNT = b.PK_ID
        WHERE
        a.DEL_FLAG = 0 and b.DEL_FLAG = 0
        <if test="pkAreaCurrency != null">
            AND  a.PK_AREA_CURRENCY = #{pkAreaCurrency}
        </if>
        <if test="pkAccount != null">
            AND  a.PK_ACCOUNT= #{pkAccount}
        </if>
        order by a.DEDUCT_SORT asc

    </select>



</mapper>
