<?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.playlet.system.mapper.PlayletUserInvoiceMapper">

    <resultMap type="PlayletUserInvoice" id="PlayletUserInvoiceResult">
        <result property="id"    column="id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="companyName"    column="company_name"    />
        <result property="taxpayerNumber"    column="taxpayer_number"    />
        <result property="companyPhone"    column="company_phone"    />
        <result property="companySite"    column="company_site"    />
        <result property="bankAccountNumber"    column="bank_account_number"    />
        <result property="bankAccountName"    column="bank_account_name"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectPlayletUserInvoiceVo">
        select id, create_time, update_time, create_by, update_by, remark, company_name, taxpayer_number, company_phone, company_site, bank_account_number, bank_account_name, user_id from playlet_user_invoice
    </sql>

    <select id="selectPlayletUserInvoiceList" parameterType="PlayletUserInvoice" resultMap="PlayletUserInvoiceResult">
        <include refid="selectPlayletUserInvoiceVo"/>
        <where>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="taxpayerNumber != null  and taxpayerNumber != ''"> and taxpayer_number = #{taxpayerNumber}</if>
            <if test="companyPhone != null  and companyPhone != ''"> and company_phone = #{companyPhone}</if>
            <if test="companySite != null  and companySite != ''"> and company_site = #{companySite}</if>
            <if test="bankAccountNumber != null  and bankAccountNumber != ''"> and bank_account_number = #{bankAccountNumber}</if>
            <if test="bankAccountName != null  and bankAccountName != ''"> and bank_account_name like concat('%', #{bankAccountName}, '%')</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectPlayletUserInvoiceById" parameterType="Long" resultMap="PlayletUserInvoiceResult">
        <include refid="selectPlayletUserInvoiceVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlayletUserInvoice" parameterType="PlayletUserInvoice" useGeneratedKeys="true" keyProperty="id">
        insert into playlet_user_invoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="companyName != null and companyName != ''">company_name,</if>
            <if test="taxpayerNumber != null and taxpayerNumber != ''">taxpayer_number,</if>
            <if test="companyPhone != null and companyPhone != ''">company_phone,</if>
            <if test="companySite != null and companySite != ''">company_site,</if>
            <if test="bankAccountNumber != null and bankAccountNumber != ''">bank_account_number,</if>
            <if test="bankAccountName != null and bankAccountName != ''">bank_account_name,</if>
            <if test="userId != null and userId != ''">user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyName != null and companyName != ''">#{companyName},</if>
            <if test="taxpayerNumber != null and taxpayerNumber != ''">#{taxpayerNumber},</if>
            <if test="companyPhone != null and companyPhone != ''">#{companyPhone},</if>
            <if test="companySite != null and companySite != ''">#{companySite},</if>
            <if test="bankAccountNumber != null and bankAccountNumber != ''">#{bankAccountNumber},</if>
            <if test="bankAccountName != null and bankAccountName != ''">#{bankAccountName},</if>
            <if test="userId != null and userId != ''">#{userId},</if>
        </trim>
    </insert>

    <update id="updatePlayletUserInvoice" parameterType="PlayletUserInvoice">
        update playlet_user_invoice
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyName != null and companyName != ''">company_name = #{companyName},</if>
            <if test="taxpayerNumber != null and taxpayerNumber != ''">taxpayer_number = #{taxpayerNumber},</if>
            <if test="companyPhone != null and companyPhone != ''">company_phone = #{companyPhone},</if>
            <if test="companySite != null and companySite != ''">company_site = #{companySite},</if>
            <if test="bankAccountNumber != null and bankAccountNumber != ''">bank_account_number = #{bankAccountNumber},</if>
            <if test="bankAccountName != null and bankAccountName != ''">bank_account_name = #{bankAccountName},</if>
            <if test="userId != null and userId != ''">user_id = #{userId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlayletUserInvoiceById" parameterType="Long">
        delete from playlet_user_invoice where id = #{id}
    </delete>

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

</mapper>