<?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.core.job.dao.CheckOneDao">
    <select id="getRecordList" resultType="com.dxhy.api.model.invoice.TDxRecordInvoice" databaseId="mysql">
		SELECT
			invoice_code,
			invoice_no,
			invoice_date,
			gf_tax_no,
			invoice_amount,
			check_code,
			invoice_status,
			invoice_type,
			total_amount as totalAmount
		FROM
			t_dx_record_invoice
		WHERE
			invoice_type IN ( '10','04','15' )
			AND check_sign = '0'
			and gf_tax_no = #{taxNo}
		ORDER BY
			create_date ASC
		limit #{rows}
	</select>

    <select id="getRecordList" resultType="com.dxhy.api.model.invoice.TDxRecordInvoice" databaseId="oracle">
	    SELECT * from (
	           SELECT ROWNUM AS rowno, r.*  FROM (
                      SELECT	invoice_code,
		                     	invoice_no,
			                    invoice_date,
		                    	gf_tax_no,
		                    	invoice_amount,
		                    	check_code,
		                    	invoice_status,
		                    	invoice_type,
			                    total_amount as totalAmount
			         FROM  t_dx_record_invoice
	                 WHERE invoice_type IN ( '10','04','15' ) AND check_sign = '0' and gf_tax_no = #{taxNo}
        	         ORDER BY create_date ASC
        	    ) r <![CDATA[ where ROWNUM <= #{rows} ]]>
        	)  table_alias
	</select>

    <update id="updateStatus" databaseId="mysql">
        update t_dx_record_invoice set
        check_sign = #{checkSign},
        <if test="invoiceStatus != null and invoiceStatus != ''">
            invoice_status = #{invoiceStatus},
        </if>
        status_update_date = now(),
		last_update_date = now()
        where uuid = #{uuid}
    </update>

    <update id="updateStatus" databaseId="oracle">
        update t_dx_record_invoice set
        check_sign = #{checkSign},
        <if test="invoiceStatus != null and invoiceStatus != ''">
            invoice_status = #{invoiceStatus},
        </if>
        status_update_date = SYSDATE,
		last_update_date = SYSDATE
        where uuid = #{uuid}
    </update>

    <update id="updateFailStatus" databaseId="mysql">
        update t_dx_record_invoice set
        check_sign = '0',
		last_update_date = now()
        where check_sign = '2'
        <if test="taxNo!=null and taxNo!=''">
            and gf_tax_no= #{taxNo}
        </if>
    </update>

    <update id="updateFailStatus" databaseId="oracle">
        update t_dx_record_invoice set
        check_sign = '0',
		last_update_date = SYSDATE
        where check_sign = '2'
        <if test="taxNo!=null and taxNo!=''">
            and gf_tax_no= #{taxNo}
        </if>
    </update>

    <select id="getRecordListThreeMonth" resultType="com.dxhy.api.model.invoice.TDxRecordInvoice" databaseId="mysql">
		SELECT
			invoice_code,
			invoice_no,
			invoice_date,
			gf_tax_no,
			invoice_amount,
			check_code,
			invoice_status,
			invoice_type,
			total_amount as totalAmount
		FROM
			t_dx_record_invoice
		WHERE
			invoice_type IN ( '10','04' ,'15')
			AND gf_tax_no = #{taxNo}
			AND check_sign = '0'
			AND <![CDATA[create_date >= #{monthBegin}]]>
		ORDER BY
			create_date ASC
		limit #{rows}
	</select>

    <select id="getRecordListThreeMonth" resultType="com.dxhy.api.model.invoice.TDxRecordInvoice" databaseId="oracle">
		SELECT * FROM (
		     SELECT ROWNUM AS rowno, r.*  FROM (
		      SELECT invoice_code,
		             invoice_no,
			         invoice_date,
			         gf_tax_no,
			         invoice_amount,
			         check_code,
			         invoice_status,
			         invoice_type,
			         total_amount as totalAmount
		       FROM t_dx_record_invoice
		       WHERE invoice_type IN ( '10','04' ,'15') AND gf_tax_no = #{taxNo} AND check_sign = '0' AND <![CDATA[create_date >= #{monthBegin}]]>
		        ORDER BY  create_date ASC
		     )r <![CDATA[ where ROWNUM <= #{rows} ]]>
		) table_alias
	</select>

    <select id="getTaxNo" resultType="com.dxhy.core.job.entity.TAcOrg">
		  SELECT
		  DISTINCT qy.nsrsbh taxno,
		  qy.nsrmc taxname,
		  config.db_name dbName,
		  qy.company,
		  config.ace_id aceId,
		  config.ace_key aceKey,
          config.data_ace_id dataAceId,
          config.data_ace_key dataAceKey
    		FROM
		sys_group_config config
		JOIN sys_enterprise_config qy ON config.company = qy.company
		where qy.check_flag = '1'
	</select>
</mapper>