<?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="cn.ezhizao.project.business.invoice.mapper.BizInvoiceMapper">

    <resultMap type="cn.ezhizao.project.business.invoice.domain.BizInvoice" id="BizInvoiceResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizInvoice" resultMap="BizInvoiceResult">
        SELECT t1.*,t2.contract_no ,t3.nick_name as applierName,t4.nick_name as invoiceName

        FROM biz_invoice t1
        left join biz_archive_input t2 on t1.contract_id = t2.id
        left join sys_user t3 on t1.applier_id = t3.user_id
        left join sys_user t4 on t1.invoice_id = t4.user_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="invoiceType != null ">AND invoice_type = #{invoiceType}</if>
            <if test="invoiceMy != null  and invoiceMy != ''">
                AND t1.invoice_my like concat('%',#{invoiceMy}, '%')
            </if>
            <if test="invoiceOther != null  and invoiceOther != ''">
                AND t1.invoice_other like concat('%',#{invoiceOther}, '%')
            </if>
            <if test="contractNo != null  and contractNo != ''">
                AND t2.contract_no like concat('%',#{contractNo}, '%')
            </if>
            <if test="applierName != null  and applierName != ''">
                AND t3.user_name like concat('%',#{applierName}, '%')
            </if>
            <if test="invoiceName != null  and invoiceName != ''">
                AND t4.user_name like concat('%',#{invoiceName}, '%')
            </if>
            <if test="status != null ">AND t1.status = #{status}</if>
        <if test="tenantId != null">
            AND t1.tenant_id = #{tenantId}
        </if>
            <if test="dateFilter!= null and dateFilter.size() ">
                AND (
                DATE_FORMAT(t1.applier_time,'%Y-%m-%d') &gt;= #{dateFilter[0]}
                AND
                DATE_FORMAT(t1.applier_time,'%Y-%m-%d') &lt;= #{dateFilter[1]}
                )
            </if>
            <if test="invoiceDateFilter!= null and invoiceDateFilter.size() ">
                AND(
                DATE_FORMAT(t1.invoice_time,'%Y-%m-%d') &gt;= #{invoiceDateFilter[0]}
                AND
                DATE_FORMAT(t1.invoice_time,'%Y-%m-%d') &lt;= #{invoiceDateFilter[1]}
                )
            </if>
        </trim>
        order by t1.create_time DESC
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_invoice
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
            <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
