<?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.younike.system.mapper.MerchantBankMapper">
    
    <resultMap type="MerchantBank" id="MerchantBankResult">
        <result property="merchantId"    column="merchant_id"    />
        <result property="userName"    column="user_name"    />
        <result property="bankBranchName"    column="bank_branch_name"    />
        <result property="bankBranchCode"    column="bank_branch_code"    />
        <result property="bankImg"    column="bank_img"    />
        <result property="bankAccount"    column="bank_account"    />
        <result property="bankType"    column="bank_type"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <sql id="selectMerchantBankVo">
        select merchant_id, user_name, bank_branch_name, bank_branch_code, bank_img, bank_account, bank_type, del_flag, create_by, create_time, update_by, update_time, column1, column2, column3 from merchant_bank
    </sql>

    <select id="selectMerchantBankList" parameterType="MerchantBank" resultMap="MerchantBankResult">
        <include refid="selectMerchantBankVo"/>
        <where>  
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="bankBranchName != null  and bankBranchName != ''"> and bank_branch_name like concat('%', #{bankBranchName}, '%')</if>
            <if test="bankBranchCode != null  and bankBranchCode != ''"> and bank_branch_code = #{bankBranchCode}</if>
            <if test="bankImg != null  and bankImg != ''"> and bank_img = #{bankImg}</if>
            <if test="bankAccount != null  and bankAccount != ''"> and bank_account = #{bankAccount}</if>
            <if test="bankType != null "> and bank_type = #{bankType}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
        </where>
    </select>
    
    <select id="selectMerchantBankByMerchantId" parameterType="Long" resultMap="MerchantBankResult">
        <include refid="selectMerchantBankVo"/>
        where merchant_id = #{merchantId}
    </select>
        
    <insert id="insertMerchantBank" parameterType="MerchantBank">
        insert into merchant_bank
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="merchantId != null">merchant_id,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="bankBranchName != null">bank_branch_name,</if>
            <if test="bankBranchCode != null">bank_branch_code,</if>
            <if test="bankImg != null">bank_img,</if>
            <if test="bankAccount != null">bank_account,</if>
            <if test="bankType != null">bank_type,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="merchantId != null">#{merchantId},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="bankBranchName != null">#{bankBranchName},</if>
            <if test="bankBranchCode != null">#{bankBranchCode},</if>
            <if test="bankImg != null">#{bankImg},</if>
            <if test="bankAccount != null">#{bankAccount},</if>
            <if test="bankType != null">#{bankType},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <update id="updateMerchantBank" parameterType="MerchantBank">
        update merchant_bank
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="bankBranchName != null">bank_branch_name = #{bankBranchName},</if>
            <if test="bankBranchCode != null">bank_branch_code = #{bankBranchCode},</if>
            <if test="bankImg != null">bank_img = #{bankImg},</if>
            <if test="bankAccount != null">bank_account = #{bankAccount},</if>
            <if test="bankType != null">bank_type = #{bankType},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where merchant_id = #{merchantId}
    </update>

    <delete id="deleteMerchantBankByMerchantId" parameterType="Long">
        delete from merchant_bank where merchant_id = #{merchantId}
    </delete>

    <delete id="deleteMerchantBankByMerchantIds" parameterType="String">
        delete from merchant_bank where merchant_id in 
        <foreach item="merchantId" collection="array" open="(" separator="," close=")">
            #{merchantId}
        </foreach>
    </delete>
</mapper>