<?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.jsowell.pile.mapper.MemberInvoiceTitleMapper">

    <resultMap type="com.jsowell.pile.domain.MemberInvoiceTitle" id="MemberInvoiceTitleResult">
        <result property="id"    column="id"    />
        <result property="memberId"    column="member_id"    />
        <result property="titleType"    column="title_type"    />
        <result property="name"    column="name"    />
        <result property="taxId"    column="tax_id"    />
        <result property="unitAddress"    column="unit_address"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="bankName"    column="bank_name"    />
        <result property="bankAccountNumber"    column="bank_account_number"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="Base_Column_List">
        id, member_id, title_type, name, tax_id, unit_address, phone_number, bank_name, bank_account_number,
        create_time, create_by, update_time, update_by, del_flag
    </sql>

    <sql id="selectMemberInvoiceTitleVo">
        select
             <include refid="Base_Column_List"/>
        from member_invoice_title
    </sql>

    <select id="selectMemberInvoiceTitleList" parameterType="com.jsowell.pile.domain.MemberInvoiceTitle" resultMap="MemberInvoiceTitleResult">
        <include refid="selectMemberInvoiceTitleVo"/>
        <where>
            <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
            <if test="titleType != null  and titleType != ''"> and title_type = #{titleType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="taxId != null  and taxId != ''"> and tax_id = #{taxId}</if>
            <if test="unitAddress != null  and unitAddress != ''"> and unit_address = #{unitAddress}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="bankName != null  and bankName != ''"> and bank_name like concat('%', #{bankName}, '%')</if>
            <if test="bankAccountNumber != null  and bankAccountNumber != ''"> and bank_account_number = #{bankAccountNumber}</if>
        </where>
    </select>

    <select id="selectMemberInvoiceTitleById" parameterType="Long" resultMap="MemberInvoiceTitleResult">
        <include refid="selectMemberInvoiceTitleVo"/>
        where id = #{id}
    </select>

    <insert id="insertMemberInvoiceTitle" parameterType="com.jsowell.pile.domain.MemberInvoiceTitle" useGeneratedKeys="true" keyProperty="id">
        insert into member_invoice_title
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null">member_id,</if>
            <if test="titleType != null">title_type,</if>
            <if test="name != null">name,</if>
            <if test="taxId != null">tax_id,</if>
            <if test="unitAddress != null">unit_address,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="bankName != null">bank_name,</if>
            <if test="bankAccountNumber != null">bank_account_number,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null">#{memberId},</if>
            <if test="titleType != null">#{titleType},</if>
            <if test="name != null">#{name},</if>
            <if test="taxId != null">#{taxId},</if>
            <if test="unitAddress != null">#{unitAddress},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="bankName != null">#{bankName},</if>
            <if test="bankAccountNumber != null">#{bankAccountNumber},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateMemberInvoiceTitle" parameterType="com.jsowell.pile.domain.MemberInvoiceTitle">
        update member_invoice_title
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="titleType != null">title_type = #{titleType},</if>
            <if test="name != null">name = #{name},</if>
            <if test="taxId != null">tax_id = #{taxId},</if>
            <if test="unitAddress != null">unit_address = #{unitAddress},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="bankName != null">bank_name = #{bankName},</if>
            <if test="bankAccountNumber != null">bank_account_number = #{bankAccountNumber},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMemberInvoiceTitleById" parameterType="Long">
        delete from member_invoice_title where id = #{id}
    </delete>

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