<?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.dxhy.extend.dao.ExtDefinitiveStrideYearCopDao">
    <resultMap id="reportStatisticsMap" type="com.dxhy.extend.entity.ExtReportStatisticsEntity">
        <result column="totalCount" property="totalCount"/>
        <result column="totalAmount" property="totalAmount"/>
        <result column="totalTax" property="totalTax"/>
    </resultMap>
    <!-- 自定义底账表结果集映射-->
    <resultMap id="RecordInvoiceMap" type="com.dxhy.extend.entity.ExtRecordInvoiceEntity">
        <id property="id" column="id"></id>
        <result property="uuid" column="uuid"/>
        <result property="qsDate" column="qs_date"/>
        <result property="invoiceType" column="invoice_type"/>
        <result property="invoiceCode" column="invoice_code"/>
        <result property="invoiceNo" column="invoice_no"/>
        <result property="invoiceDate" column="invoice_date"/>
        <result property="invoiceStatus" column="invoice_status"/>
        <result property="gfName" column="gf_name"/>
        <result property="xfName" column="xf_name"/>
        <result property="taxAmount" column="taxAmount"/>
        <result property="invoiceAmount" column="invoiceamount"/>
    </resultMap>
    <!--多条件查询普票跨年度预警-->
    <select id="queryDefinitiveList" resultMap="RecordInvoiceMap" databaseId="mysql">
        SELECT
        t.id,
        t.uuid,
        t.invoice_type,
        date_format(t.qs_date,'%Y-%m-%d') qs_date,
        t.invoice_code,
        t.invoice_no,
        date_format(t.invoice_date,'%Y-%m-%d') invoice_date,
        t.gf_name,
        t.xf_name,
        t.invoice_amount AS invoiceamount,
        t.tax_amount AS taxAmount,
        (case when t.qs_status = '0' then '未签收' else '已签收' end ) qs_status,
        t.qs_name userName

        from t_dx_record_invoice t
        WHERE t.qs_status = '1' and t.invoice_type IN('04','10','11')
        <if test="gfTaxNo =='' or gfTaxNo ==null">
            and t.gf_tax_no in
            <foreach item="item" index="index" collection="taxno" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="billingDate1 != null">
            AND date_format(t.invoice_date,'%Y') = date_format(#{billingDate1},'%Y')
        </if>
        and date_format(qs_date,'%Y-%m') >= date_format(now(),'%Y-%m')
        order by t.qs_date desc
    </select>


    <select id="queryDefinitiveList" resultMap="RecordInvoiceMap" databaseId="oracle">
        SELECT
        t.id,
        t.uuid,
        t.invoice_type,
        to_char(t.qs_date,'yyyy-MM-dd') qs_date,
        t.invoice_code,
        t.invoice_no,
        to_char(t.invoice_date,'yyyy-MM-dd') invoice_date,
        t.gf_name,
        t.xf_name,
        t.invoice_amount AS invoiceamount,
        t.tax_amount AS taxAmount,
        decode(t.qs_status, '0', '未签收', '1', '已签收') qs_status,
        t.qs_name userName

        from t_dx_record_invoice t

        WHERE t.qs_status = '1' and t.invoice_type IN('04','10','11')
        <if test="gfTaxNo =='' or gfTaxNo ==null">
            and t.gf_tax_no in
            <foreach item="item" index="index" collection="taxno" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="billingDate1 != null">
            AND to_char(t.invoice_date,'yyyy') = SUBSTR(#{billingDate1}, 0,LENGTH(#{billingDate1}) - 6)
        </if>
        and to_char(qs_date,'yyyy-MM') >= to_char(sysdate,'yyyy-MM')
        order by t.qs_date desc
    </select>

</mapper>

