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

    <!-- 通用查询映射结果 -->
    <resultMap id="AreaCurrentExt" type="com.hzs.common.domain.system.ext.AreaCurrencyExt">
        <id column="PK_ID" property="pkId" />
        <result column="ACCOUNT_NAME" property="accountName" />
        <result column="PK_TRANSACTION_KEY" property="pkTransactionKey" />
        <result column="SORT" property="sort" />
        <result column="FIELD_VALUE" property="fieldValue" />
        <result column="ENABLE_STATE" property="enableState" />
        <result column="IS_TRANSFER" property="isTransfer" />
        <result column="IS_WITHDRAWAL" property="isWithdrawal" />
        <result column="IS_REGULAR" property="isRegular" />
        <result column="IS_POSTAGE" property="isPostage" />
        <result column="EFFECTIVE_DATE" property="effectiveDate" />
        <result column="BACKGROUND_IMG" property="backgroundImg" />
        <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="DEDUCT_SORT" property="deductSort" />
        <result column="DEDUCT_RATIO" property="deductRatio" />
        <result column="PK_ACCOUNT" property="pkAccount" />
        <result column="ON_LINE_RECHARGE" property="onLineRecharge" />
        <result column="SHOW_STATUS" property="showStatus" />
        <result column="SPECIAL_AREA" property="specialArea" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PK_ID, ACCOUNT_NAME, TRANSACTION_KEY, SORT, FIELD_VALUE, ENABLE_STATE, IS_TRANSFER, IS_WITHDRAWAL, IS_ITFIXED, EFFECTIVE_DATE, BACKGROUND_IMG, DEL_FLAG, PK_COUNTRY, PK_CREATOR, CREATION_TIME, PK_MODIFIED, MODIFIED_TIME
    </sql>

    <select id="queryAreaCurrencyByCondition" resultMap="AreaCurrentExt">
        select ba.*,bc.special_area,bd.deduct_sort,bd.deduct_ratio,bd.pk_account,bd.is_deduction from
        (
        select  pk_id,pk_country,special_area from bd_area_currency where del_flag=0
        <if test="specialArea != null">
            and special_area = #{specialArea}
        </if>
        <if test="pkCountry != null">
            and pk_country= #{pkCountry}
        </if>
        and EFFECTIVE_DATE=(select max(EFFECTIVE_DATE) EFFECTIVE_DATE from bd_area_currency
        where del_flag=0
        <if test="specialArea != null">
            and special_area = #{specialArea}
        </if>
        <if test="pkCountry != null">
            and pk_country= #{pkCountry}
        </if>
        and effective_date &lt;=sysdate )
        and effective_date &lt;=sysdate
        group by pk_country,special_area,pk_id
        ) bc
        inner join bd_area_currency_detail bd
        on bc.pk_id = bd.pk_area_currency
        inner join bd_account ba
        on bd.pk_account =ba.pk_id
        where bd.del_flag=0
        and ba.del_flag=0
        <if test="pkCountry != null">
            and bd.pk_country=#{pkCountry}
        </if>
         and ba.enable_state=0
         and ba.effective_date &lt;= sysdate
        order by bd.deduct_sort,bd.deduct_ratio
    </select>

<!--查询币种配置列表-->
    <select id="selectBdAccountList" parameterType="com.hzs.common.domain.system.config.ext.BdAccountExt"
            resultType="com.hzs.common.domain.system.config.ext.BdAccountExt">
        select
        a.PK_ID,
        a.ACCOUNT_NAME,
        a.PK_TRANSACTION_KEY,
        a.SORT,
        a.FIELD_VALUE,
        a.ENABLE_STATE,
        a.IS_TRANSFER,
        a.IS_WITHDRAWAL,
        a.EFFECTIVE_DATE,
        a.BACKGROUND_IMG,
        a.DEL_FLAG,
        a.PK_COUNTRY,
        a.CREATION_TIME,
        a.MODIFIED_TIME,
        a.IS_RECHARGE,
        a.IS_REGULAR,
        a.IS_POSTAGE,
        a.PK_CREATOR,
        a.PK_MODIFIED,
        a.PK_BD_ACCOUNT,
        a.SHOW_STATUS,
        a.ON_LINE_RECHARGE onLineRecharge,
        b.ACCOUNT_NAME as accountFame,
        c.NAME as name,
        c.NATIONAL_FLAG2 as nationalFlag2
        from BD_ACCOUNT a
        LEFT JOIN  BD_ACCOUNT b on a.PK_BD_ACCOUNT=b.PK_ID
        LEFT JOIN BD_COUNTRY c on a.PK_COUNTRY=c.PK_ID
        where a.DEL_FLAG = 0 and c.DEL_FLAG = 0
        <if test="accountName != null and accountName != ''">
            AND a.ACCOUNT_NAME like '%' || #{accountName} || '%'
        </if>
        <if test="pkCountry != null and pkCountry != 0">
            AND a.PK_COUNTRY = #{pkCountry}
        </if>

        order by a.SORT ASC
    </select>

     <!--校验会员账户表是否有数据-->
    <select id="selectMemberAccountCount" parameterType="com.hzs.common.domain.system.config.ext.BdAccountExt"
            resultType="java.lang.Integer">
        select count(1) from cu_member_account
        where DEL_FLAG = 0
        <if test="account1 != null and account1 != 0">
            AND ACCOUNT1 !=0
        </if>
        <if test="account2 != null and account2 != 0">
            AND ACCOUNT2 !=0
        </if>
        <if test="account3 != null and account3 != 0">
            AND ACCOUNT3 !=0
        </if>
        <if test="account4 != null and account4 != 0">
            AND ACCOUNT4 !=0
        </if>
        <if test="account5 != null and account5 != 0">
            AND ACCOUNT5 !=0
        </if>
        <if test="account6 != null and account6 != 0">
            AND ACCOUNT6 !=0
        </if>
        <if test="account7 != null and account7 != 0">
            AND ACCOUNT7 !=0
        </if>
        <if test="account8 != null and account8 != 0">
            AND ACCOUNT8 !=0
        </if>
        <if test="account9 != null and account9 != 0">
            AND ACCOUNT9 !=0
        </if>
        <if test="account10 != null and account10 != 0">
            AND ACCOUNT10 !=0
        </if>

    </select>





</mapper>
