<?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.third.pay.mapper.TOnlineCardMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.third.pay.TOnlineCard">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="CODE" property="code"/>
        <result column="NAME" property="name"/>
        <result column="ID_CARD" property="idCard"/>
        <result column="BANK_NO" property="bankNo"/>
        <result column="PHONE" property="phone"/>
        <result column="BANK_CODE" property="bankCode"/>
        <result column="BIND_ID" property="bindId"/>
        <result column="BIND_STATUS" property="bindStatus"/>
        <result column="CUSTOMER_NUM" property="customerNum"/>
        <result column="BANK_NAME" property="bankName"/>
        <result column="THIRD_INFO" property="thirdInfo"/>
        <result column="BIND_TYPE" property="bindType"/>
        <result column="VALIDDATE" property="validdate"/>
        <result column="CVV2" property="cvv2"/>
    </resultMap>

    <!-- 查询绑卡列表 -->
    <select id="queryBankList" resultMap="BaseResultMap">
        select code, bank_no, bank_code, bank_name
        from T_ONLINE_CARD
        where del_flag = '0'
          and PK_CREATOR = #{pkMember}
          and CUSTOMER_NUM = #{customerNum}
          and PK_COUNTRY = #{pkCountry}
          and BIND_STATUS = 1
        order by CREATION_TIME desc
    </select>

    <!-- 校验用户银行卡是否存在 -->
    <select id="checkUserBankExist" resultMap="BaseResultMap">
        select *
        from T_ONLINE_CARD
        where del_flag = '0'
          and BIND_STATUS = 1
          and PK_CREATOR = #{pkMember}
          and BANK_NO = #{bankNo}
          and CUSTOMER_NUM = #{customerNum}
          and PK_COUNTRY = #{pkCountry}
    </select>

    <!-- 根据编号查询银行卡 -->
    <select id="queryCardByCode" resultMap="BaseResultMap">
        select *
        from T_ONLINE_CARD
        where del_flag = '0'
        and CODE = #{code}
        and CUSTOMER_NUM = #{customerNum}
        <if test="pkMember != null and pkMember != ''">
            and PK_CREATOR = #{pkMember}
        </if>
        <if test="pkCountry != null">
            and PK_COUNTRY = #{pkCountry}
        </if>
    </select>

    <!-- 更新银行卡信息 -->
    <update id="updateBankInfo" parameterType="com.hzs.common.domain.third.pay.TOnlineCard">
        update T_ONLINE_CARD
        set
        <if test="bindId != null and bindId != '' ">
            BIND_ID = #{bindId},
        </if>
        <if test="bankCode != null and bankCode != '' ">
            BANK_CODE = #{bankCode},
        </if>
        <if test="bankName != null and bankName != '' ">
            BANK_NAME = #{bankName},
        </if>
        <if test="thirdInfo != null and thirdInfo != ''">
            THIRD_INFO = #{thirdInfo},
        </if>
        BIND_STATUS = #{bindStatus},
        PK_MODIFIED = #{pkModified},
        MODIFIED_TIME = #{modifiedTime}
        where CODE = #{code}
    </update>

    <!-- 解绑银行卡信息 -->
    <update id="unBindBank">
        update T_ONLINE_CARD
        set DEL_FLAG      = 1,
            PK_MODIFIED   = #{pkMember},
            MODIFIED_TIME = sysdate
        where CODE = #{code}
          and CUSTOMER_NUM = #{customerNum}
    </update>

</mapper>
