<?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.ruoyi.system.mapper.BankCardMapper">

    <resultMap type="BankCard" id="BankCardResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="number"    column="number"    />
        <result property="bankName"    column="bank_name"    />
        <result property="accountName"    column="account_name"    />
        <result property="type"    column="type"    />
        <result property="img"    column="img"    />
    </resultMap>

    <sql id="selectBankCardVo">
        select id, user_id, number, bank_name, account_name, type, img from bank_card
    </sql>

    <select id="selectBankCardList" parameterType="BankCard" resultMap="BankCardResult">
        <include refid="selectBankCardVo"/>
        <where>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="number != null  and number != ''"> and BINARY number like concat('%', #{number}, '%')</if>
            <if test="bankName != null  and bankName != ''"> and BINARY bank_name like concat('%', #{bankName}, '%')</if>
            <if test="accountName != null  and accountName != ''"> and BINARY account_name like concat('%', #{accountName}, '%')</if>
        </where>
    </select>

    <select id="selectBankCardById" parameterType="Long" resultMap="BankCardResult">
        <include refid="selectBankCardVo"/>
        where id = #{id}
    </select>

    <insert id="insertBankCard" parameterType="BankCard" useGeneratedKeys="true" keyProperty="id">
        insert into bank_card
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="number != null">number,</if>
            <if test="bankName != null">bank_name,</if>
            <if test="accountName != null">account_name,</if>
            <if test="type != null">type,</if>
            <if test="img != null">img,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="number != null">#{number},</if>
            <if test="bankName != null">#{bankName},</if>
            <if test="accountName != null">#{accountName},</if>
            <if test="type != null">#{type},</if>
            <if test="img != null">#{img},</if>
         </trim>
    </insert>

    <update id="updateBankCard" parameterType="BankCard">
        update bank_card
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="number != null">number = #{number},</if>
            <if test="bankName != null">bank_name = #{bankName},</if>
            <if test="accountName != null">account_name = #{accountName},</if>
            <if test="type != null">type = #{type},</if>
            <if test="img != null">img = #{img},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBankCardById" parameterType="Long">
        delete from bank_card where id = #{id}
    </delete>

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