<?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.szxc.mapper.SzxcBankcardInfoMapper">
    
    <resultMap type="SzxcBankcardInfo" id="SzxcBankcardInfoResult">
        <result property="id"    column="id"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="cardId"    column="card_id"    />
        <result property="cardNum"    column="card_num"    />
        <result property="bankNum"    column="bank_num"    />
        <result property="bankName"    column="bank_name"    />
        <result property="bankAddress"    column="bank_address"    />
        <result property="defaultCard"    column="default_card"    />
        <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="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectSzxcBankcardInfoVo">
        select id, owner_id, owner_name, card_id, card_num, bank_num, bank_name, bank_address, default_card, create_by, create_time, update_by, update_time, dept_id, dept_name, user_id from szxc_bankcard_info
    </sql>

    <select id="selectSzxcBankcardInfoList" parameterType="SzxcBankcardInfo" resultMap="SzxcBankcardInfoResult">
        <include refid="selectSzxcBankcardInfoVo"/> as b
        <where>  
            <if test="ownerId != null "> and owner_id = #{ownerId}</if>
            <if test="ownerName != null  and ownerName != ''"> and owner_name like concat('%', #{ownerName}, '%')</if>
            <if test="cardId != null  and cardId != ''"> and card_id = #{cardId}</if>
            <if test="cardNum != null  and cardNum != ''"> and card_num = #{cardNum}</if>
            <if test="bankNum != null  and bankNum != ''"> and bank_num = #{bankNum}</if>
            <if test="bankName != null  and bankName != ''"> and bank_name like concat('%', #{bankName}, '%')</if>
            <if test="bankAddress != null  and bankAddress != ''"> and bank_address = #{bankAddress}</if>
            <if test="defaultCard != null  and defaultCard != ''"> and default_card = #{defaultCard}</if>
            <!--<if test="deptId != null "> and dept_id = #{deptId}</if>-->
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="params.dataScope != null and params.dataScope !=''">
                ${params.dataScope}
            </if>
        </where>
    </select>
    
    <select id="selectSzxcBankcardInfoById" parameterType="Long" resultMap="SzxcBankcardInfoResult">
        <include refid="selectSzxcBankcardInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSzxcBankcardInfo" parameterType="SzxcBankcardInfo" useGeneratedKeys="true" keyProperty="id">
        insert into szxc_bankcard_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ownerId != null">owner_id,</if>
            <if test="ownerName != null and ownerName != ''">owner_name,</if>
            <if test="cardId != null and cardId != ''">card_id,</if>
            <if test="cardNum != null and cardNum != ''">card_num,</if>
            <if test="bankNum != null">bank_num,</if>
            <if test="bankName != null and bankName != ''">bank_name,</if>
            <if test="bankAddress != null and bankAddress != ''">bank_address,</if>
            <if test="defaultCard != null and defaultCard != ''">default_card,</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="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ownerId != null">#{ownerId},</if>
            <if test="ownerName != null and ownerName != ''">#{ownerName},</if>
            <if test="cardId != null and cardId != ''">#{cardId},</if>
            <if test="cardNum != null and cardNum != ''">#{cardNum},</if>
            <if test="bankNum != null">#{bankNum},</if>
            <if test="bankName != null and bankName != ''">#{bankName},</if>
            <if test="bankAddress != null and bankAddress != ''">#{bankAddress},</if>
            <if test="defaultCard != null and defaultCard != ''">#{defaultCard},</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="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updateSzxcBankcardInfo" parameterType="SzxcBankcardInfo">
        update szxc_bankcard_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="ownerName != null and ownerName != ''">owner_name = #{ownerName},</if>
            <if test="cardId != null and cardId != ''">card_id = #{cardId},</if>
            <if test="cardNum != null and cardNum != ''">card_num = #{cardNum},</if>
            <if test="bankNum != null">bank_num = #{bankNum},</if>
            <if test="bankName != null and bankName != ''">bank_name = #{bankName},</if>
            <if test="bankAddress != null and bankAddress != ''">bank_address = #{bankAddress},</if>
            <if test="defaultCard != null and defaultCard != ''">default_card = #{defaultCard},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where id = #{id}
    </update>
    <!--修改默认银行卡专属方法-->
    <update id="updateSzxcBankcardInfo2" parameterType="SzxcBankcardInfo">
        update szxc_bankcard_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="defaultCard != null and defaultCard != ''">default_card = #{defaultCard},</if>
        </trim>
    </update>

    <delete id="deleteSzxcBankcardInfoById" parameterType="Long">
        delete from szxc_bankcard_info where id = #{id}
    </delete>

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