<?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.usky.iot.mapper.CrmInvoiceInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.iot.domain.CrmInvoiceInfo">
        <id column="id" property="id" />
        <result column="custom_id" property="customId" />
        <result column="invoice_title" property="invoiceTitle" />
        <result column="duty_id" property="dutyId" />
        <result column="email" property="email" />
        <result column="applicant" property="applicant" />
        <result column="phone" property="phone" />
        <result column="amount" property="amount" />
        <result column="invoice_type" property="invoiceType" />
        <result column="invoice_attribute" property="invoiceAttribute" />
        <result column="send_address" property="sendAddress" />
        <result column="payment_receipt" property="paymentReceipt" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="dept_id" property="deptId" />
        <result column="tenant_id" property="tenantId" />
    </resultMap>

    <select id="page" resultType="com.usky.iot.domain.CrmInvoiceInfo">
        select
        ci.*,
        cc.project_id as projectId
        from crm_invoice_info ci
        left join crm_custom_info cc
        on ci.custom_id = cc.id
        <where>
            <if test="gr.projectId != null">
                and cc.project_id like CONCAT('%',#{gr.projectId},'%')
            </if>
            <if test="gr.invoiceTitle != null">
                and ci.invoice_title like CONCAT('%',#{gr.invoiceTitle},'%')
            </if>
            <if test="gr.invoiceStatus != null">
                and ci.invoice_status = #{gr.invoiceStatus}
            </if>
            <if test="gr.startTime != null and gr.startTime != '' and gr.endTime != null and gr.endTime != ''">
                and  ci.create_time BETWEEN  #{gr.startTime} AND  #{gr.endTime}
            </if>
        </where>
        order by ci.id desc
    </select>
    <select id="export" resultType="com.usky.iot.domain.CrmInvoiceInfo">
        select
        ci.*,
        cc.project_id as projectId
        from crm_invoice_info ci
        left join crm_custom_info cc
        on ci.custom_id = cc.id
        <where>
            <if test="gr.projectId != null">
                and cc.project_id like CONCAT('%',#{gr.projectId},'%')
            </if>
            <if test="gr.invoiceTitle != null">
                and ci.invoice_title like CONCAT('%',#{gr.invoiceTitle},'%')
            </if>
            <if test="gr.invoiceStatus != null">
                and ci.invoice_status = #{gr.invoiceStatus}
            </if>
            <if test="gr.startTime != null and gr.startTime != '' and gr.endTime != null and gr.endTime != ''">
                and  ci.create_time BETWEEN  #{gr.startTime} AND  #{gr.endTime}
            </if>
        </where>
        order by ci.id desc
    </select>
</mapper>
