<?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.tmerclub.cloud.platform.mapper.PublicBankMapper">

    <select id="listPublicBank" resultType="com.tmerclub.cloud.platform.vo.PublicBankVO">
        SELECT
            *
        FROM
            `public_bank`
        <where>
            <if test="publicBankDTO.bankName != null and publicBankDTO.bankName != ''">
                bank_name LIKE CONCAT( '%', #{publicBankDTO.bankName}, '%' )
            </if>
            <if test="publicBankDTO.bankCode != null and publicBankDTO.bankCode != ''">
                AND bank_code LIKE CONCAT( #{publicBankDTO.bankCode}, '%')
            </if>
        </where>
        ORDER BY
            bank_id DESC
    </select>

    <insert id="save">
        INSERT INTO
            `public_bank` (`bank_name`, `bank_code`, `create_time`, `update_time`)
        VALUES
            (#{publicBankDTO.bankName}, #{publicBankDTO.bankCode}, NOW(), NOW())
    </insert>

    <update id="update">
        UPDATE
            `public_bank`
        SET
            <if test="publicBankDTO.bankName != null">
                bank_name = #{publicBankDTO.bankName},
            </if>
            <if test="publicBankDTO.bankCode != null">
                bank_code = #{publicBankDTO.bankCode},
            </if>
            update_time = NOW()
        WHERE
            bank_id = #{publicBankDTO.bankId}
    </update>

    <delete id="deleteByIds">
        DELETE FROM
            `public_bank`
        WHERE
            bank_id IN
            <foreach collection="bankIds" item="bankId" open="(" separator="," close=")">
                #{bankId}
            </foreach>
    </delete>


</mapper>