<?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.ExtAbnormalInvoiceCopDao">
    <!-- 自定义底账表结果集映射-->
    <resultMap id="RecordInvoiceMap" type="com.dxhy.extend.entity.ExtRecordInvoiceEntity">
        <id property="id" column="id"></id>
        <result property="uuid" column="uuid"/>
        <result property="statusUpdateDate" column="status_update_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"/>
        <result property="dkse" column="dk_tax_amount"/>
    </resultMap>
    <!--多条件查询异常发票 -->
    <select id="queryAbnormalInvoice" resultMap="RecordInvoiceMap" databaseId="mysql">
        SELECT id,uuid,invoice_type,date_format(status_update_date,'%Y-%m-%d')
        status_update_date,invoice_code,invoice_no,date_format(invoice_date,'%Y-%m-%d') invoice_date,
        invoice_status,gf_name,xf_name,invoice_amount AS invoiceamount,tax_amount AS taxAmount
        ,dk_tax_amount
        dk_tax_amount,invoice_status invoiceStatus
        from t_dx_record_invoice t
        WHERE invoice_status !=0
        <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>
        AND date_format(status_update_date,'%Y-%m') >= date_format(now(),'%Y-%m')
        order by status_update_date desc ,invoice_date desc
    </select>


    <select id="queryAbnormalInvoice" resultMap="RecordInvoiceMap" databaseId="oracle">
        SELECT id,uuid,invoice_type,to_char(status_update_date,'yyyy-MM-dd')
        status_update_date,invoice_code,invoice_no,to_char(invoice_date,'yyyy-MM-dd') invoice_date,
        invoice_status,gf_name,xf_name,invoice_amount AS invoiceamount,tax_amount AS
        taxAmount,dk_tax_amount
        dk_tax_amount
        from t_dx_record_invoice t
        WHERE invoice_status !=0
        AND invoice_type IN ('01','03','14')
        <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>
        AND to_char(status_update_date,'yyyy-MM') >= to_char(sysdate,'yyyy-MM')

        order by status_update_date desc ,invoice_date desc
    </select>

</mapper>

