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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdWithdrawal">
        <id column="PK_ID" property="pkId" />
        <result column="MIN_AMOUNT" property="minAmount" />
        <result column="MAX_AMOUNT" property="maxAmount" />
        <result column="IS_ROUNDING" property="isRounding" />
        <result column="IS_AUTO" property="isAuto" />
        <result column="SERVICE_RATIO" property="serviceRatio" />
        <result column="IS_INCOME_TAX" property="isIncomeTax" />
        <result column="EFFECTIVE_DATE" property="effectiveDate" />
        <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="PK_ACCOUNT" property="pkAccount" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PK_ID, MIN_AMOUNT, MAX_AMOUNT, IS_ROUNDING, IS_AUTO, SERVICE_RATIO, IS_INCOME_TAX, EFFECTIVE_DATE, DEL_FLAG, PK_COUNTRY, PK_CREATOR, CREATION_TIME, PK_MODIFIED, MODIFIED_TIME
    </sql>


<!--    查询自动提现明细配置列表-->
    <select id="getWithdrawalAutoList" parameterType="com.hzs.common.domain.system.config.ext.BdWithdrawalAutoExt"
            resultType="com.hzs.common.domain.system.config.ext.BdWithdrawalAutoExt">
        select a.PK_ID,
        a.PK_WITHDRAWAL,
        a.DEL_FLAG,
        a.PK_COUNTRY,
        a.CREATION_TIME,
        a.MODIFIED_TIME,
        a.PK_CREATOR,
        a.PK_MODIFIED,
        a.WITHDRAWAL_CYCLE
        from BD_WITHDRAWAL_AUTO a  INNER JOIN  BD_WITHDRAWAL b on a.PK_WITHDRAWAL=b.PK_ID
        where a.DEL_FLAG=0 and b.DEL_FLAG=0
        <if test="pkWithdrawal != null">
            AND  a.PK_WITHDRAWAL= #{pkWithdrawal}
        </if>
        order by CREATION_TIME Desc

    </select>

<!--    查询会员提价表是否有数据-->
    <select id="checkWithdraw" parameterType="com.hzs.common.domain.system.config.ext.BdWithdrawalAutoExt"
            resultType="java.lang.Integer">
        select  count(1)  from cu_member_withdraw
        where DEL_FLAG=0
        <if test="pkCountry != null ">
            AND PK_COUNTRY = #{pkCountry}
        </if>

    </select>


    <!--    根据国家查询提现配置列表-->
    <select id="queryWithdrawal" resultType="com.hzs.common.domain.system.config.BdWithdrawal">
        select *  from(
        SELECT  PK_ID,MIN_AMOUNT,MAX_AMOUNT,LOWER_BOUND,UPPER_BOUND,
        IS_ROUNDING,IS_AUTO,WITHDRAWAL_NUMBER,SERVICE_RATIO,IS_INCOME_TAX,
        EFFECTIVE_DATE,PK_CREATOR,CREATION_TIME,PK_MODIFIED,
        MODIFIED_TIME,DEL_FLAG,PK_COUNTRY,PK_ACCOUNT
        FROM BD_WITHDRAWAL
        WHERE  DEL_FLAG=0
        and EFFECTIVE_DATE &lt;=sysdate
        <if test="pkCountry != null ">
            AND PK_COUNTRY = #{pkCountry}
        </if>
        <if test="pkAccount != null ">
            AND pk_Account = #{pkAccount}
        </if>
        ORDER BY EFFECTIVE_DATE DESC
        ) where ROWNUM &lt;= 1

    </select>

<!--     查询提现配置列表-->
    <select id="listExt"
            resultType="com.hzs.common.domain.system.config.ext.BdWithdrawalExt">
SELECT
	bw.*,
	ba.ACCOUNT_NAME accountName
FROM
	BD_WITHDRAWAL bw
	LEFT JOIN BD_ACCOUNT ba ON bw.PK_ACCOUNT = ba.PK_ID and ba.DEL_FLAG=0
	where bw.DEL_FLAG=0
        <if test="pkCountry != null ">
            AND bw.PK_COUNTRY = #{pkCountry}
        </if>

    </select>


</mapper>
