<?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.dao.SgqsDao">
    <resultMap id="BaseResultMap" type="com.dxhy.core.entity.TDxInvoice">
        <id column="id" property="id"/>
        <result column="invoice_code" property="invoiceCode"/>
        <result column="invoice_no" property="invoiceNo"/>
        <result column="ele_invoice_no" property="eleInvoiceNo"/>
        <result column="invoice_type" property="invoiceType"/>
        <result column="invoice_amount" property="invoiceAmount"/>
        <result column="tax_amount" property="taxAmount"/>
        <result column="invoice_date" property="invoiceDate"/>
        <result column="user_name" property="userName"/>
        <result column="qs_type" property="qsType"/>
        <result column="qs_status" property="qsStatus"/>
        <result column="uuid" property="uuid"/>
        <result column="qs_date" property="qsDate"/>
        <result column="notes" property="notes"/>
        <result column="dept_id" property="deptId"/>
        <result column="scan_id" property="scanId"/>
    </resultMap>

    <select id="selectSgqs" parameterType="java.util.Map"
            resultMap="BaseResultMap" databaseId="mysql">
        select
        qs_status,invoice_code,invoice_no,ele_invoice_no,invoice_date,invoice_type,gf_name,xf_name,gf_tax_no,xf_tax_no,invoice_amount,tax_amount,dept_name
        ,sn_voucher_number,posting_time,image_id,account_period,bzdh,bzr,inaccount_status,comp_code
        from t_dx_record_invoice t
        where
        qs_status = '0' and source_system='0'
        and t.gf_tax_no = #{gfsh}
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and businessCode != '99' ">
            and comp_code = #{companyCode}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and invoice_no = #{invoiceNo}
        </if>
        <if test="businessCode != null and businessCode != '' and businessCode != 'null' and businessCode != '99' ">
            and dept_id = #{businessCode}
        </if>
        and invoice_date between #{kprqq} and #{kprqz}
        <if test="company !=null and company!=''">
            and company = #{company}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
        order by invoice_date desc
    </select>

    <select id="selectSgqs" parameterType="java.util.Map"
            resultMap="BaseResultMap" databaseId="oracle">
        select
        qs_status,invoice_code,invoice_no,ele_invoice_no,invoice_date,invoice_type,gf_name,xf_name,gf_tax_no,xf_tax_no,invoice_amount,tax_amount,dept_name
        from t_dx_record_invoice t
        where qs_status = '0' and source_system='0' and
        t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and invoice_no = #{invoiceNo}
        </if>
        <if test="businessCode != null and businessCode != '' and businessCode != 'null' and businessCode != '99' ">
            and dept_id = #{businessCode}
        </if>
        AND invoice_date between to_date(#{kprqq},'yyyy-mm-dd hh24:mi:ss') and to_date(#{kprqz},'yyyy-mm-dd hh24:mi:ss')
        <if test="company !=null and company!=''">
            and company = #{company}
        </if>
        order by invoice_date desc
    </select>

</mapper>