<?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.jianshui.invoice.mapper.InvoiceFileMapper">
    
    <resultMap type="InvoiceFile" id="InvoiceFileResult">
        <result property="id"    column="id"    />
        <result property="fileId"    column="file_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileContent"    column="file_content"    />
        <result property="createTime"    column="create_time"    />
        <result property="identity"    column="identity"    />
        <result property="tax"    column="tax"    />
        <result property="fphm"    column="fphm"    />
    </resultMap>

    <sql id="selectInvoiceFileVo">
        select id, file_id, file_name, file_content, create_time, identity, tax,fphm from invoice_file
    </sql>

    <select id="selectInvoiceFileList" parameterType="InvoiceFile" resultMap="InvoiceFileResult">
        <include refid="selectInvoiceFileVo"/>
        <where>  
            <if test="fileId != null  and fileId != ''"> and file_id = #{fileId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name = #{fileName}</if>
            <if test="fileContent != null  and fileContent != ''"> and file_content = #{fileContent}</if>
            <if test="identity != null  and identity != ''"> and identity = #{identity}</if>
            <if test="tax != null  and tax != ''"> and tax = #{tax}</if>
            <if test="fphm != null  and fphm != ''"> and fphm = #{fphm}</if>
        </where>
    </select>
    
    <select id="selectInvoiceFileById" parameterType="String" resultMap="InvoiceFileResult">
        <include refid="selectInvoiceFileVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertInvoiceFile" parameterType="InvoiceFile">
        insert into invoice_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="fileId != null">file_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileContent != null">file_content,</if>
            <if test="createTime != null">create_time,</if>
            <if test="identity != null">identity,</if>
            <if test="tax != null">tax,</if>
            <if test="fphm != null">fphm,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="fileId != null">#{fileId},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileContent != null">#{fileContent},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="identity != null">#{identity},</if>
            <if test="tax != null">#{tax},</if>
            <if test="fphm != null">#{fphm},</if>
         </trim>
    </insert>

    <update id="updateInvoiceFile" parameterType="InvoiceFile">
        update invoice_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileId != null">file_id = #{fileId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileContent != null">file_content = #{fileContent},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="identity != null">identity = #{identity},</if>
            <if test="tax != null">tax = #{tax},</if>
            <if test="fphm != null">fphm = #{fphm},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInvoiceFileById" parameterType="String">
        delete from invoice_file where id = #{id}
    </delete>

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