<?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.GxfpqrDao">

    <resultMap id="RzcxhjResultMap"
               type="com.dxhy.core.model.FpRzRespVO">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="invoiceAmount"/>
        <result column="hjse" property="taxAmount"/>
    </resultMap>

    <select id="selectByPramsMap" parameterType="java.util.Map"
            resultType="com.dxhy.core.model.FpRzRespVO" databaseId="mysql">
        select t.id id,t.uuid uuid, t.invoice_amount je, t.tax_amount se,
        DATE_FORMAT(t.invoice_date,'%Y-%m-%d') kprq,t.gf_name gfmc,t.gf_tax_no gfsh,
        t.xf_name xfmc,date_format(t.qs_date,'%Y-%m-%d') qsrq,t.qs_status qszt,t.qs_name qsr,t.qs_type
        qsfs,t.invoice_code
        fpdm,t.invoice_no fphm,t.dept_id deptId,t.dept_name businessName,t.invoice_type
        invoiceType,t.gx_user_name,
        date_format(t.gx_date,'%Y-%m-%d') gxrq,t.dk_tax_amount yxdkse,c.current_tax_period
        dqskssq,t.payment_status,date_format(t.payment_date,'%Y-%m-%d')payment_date,t.voucher_number,t.ele_invoice_no
        from t_dx_record_invoice t,t_dx_tax_current c
        WHERE t.gf_tax_no = c.taxno
        and date_format(t.gx_date,'%Y-%m-%d') between #{gxksrq} and #{gxjsrq}
        and t.auth_status = '1'
        and t.rzh_yesorno = '0'
        and t.sfygx = '1'
        and (t.invoice_type in('01','03','08','14','31','283','161','183','185') or (t.invoice_type ='32' and t.lq_tdyslxDm='08'))
        and t.export_mark = '0'
        and t.bdk_status = '1'
        and t.company = #{company}
        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 t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceSource != null and invoiceSource != '' and invoiceSource != '99'">
            and t.invoice_source = #{invoiceSource}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like concat(#{xfmc},'%')
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' ">
            and t.qs_status = #{qszt}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            and t.qs_name = #{qsr}
        </if>
        <if test="voucherNumber != null and voucherNumber != ''">
            and t.voucher_number like concat('%',concat(#{voucherNumber},'%'))
        </if>
        <if test="gxUser != null and gxUser != '' and gxUser != 'null' and gxUser != '99'">
            and t.gx_user_account = #{gxUser}
        </if>
        <if test="paymentDateStart != null and paymentDateStart != '' and paymentDateStart != 'null' ">
            <![CDATA[ AND date_format(t.payment_date,'%Y-%m-%d') >= #{paymentDateStart} ]]>
        </if>
        <if test="paymentDateEnd != null and paymentDateEnd != '' and paymentDateEnd != 'null' ">
            <![CDATA[ AND date_format(t.payment_date,'%Y-%m-%d')  <= #{paymentDateEnd} ]]>
        </if>
        <if test="paymentStatus != null and paymentStatus != '' and paymentStatus != '99'">
            and t.payment_status = #{paymentStatus}
        </if>
        <if
                test="businessCode != '99' and businessCode != null and businessCode != '' and businessCode != 'null' ">
            and t.dept_id = #{businessCode}
        </if>
        <if test="businessCode==''">
            and (t.dept_id is null or t.dept_id='' or t.dept_id='99')
        </if>
        <if test='businessCode == "99" and business!=null and business.size()>0'>
            and (t.dept_id in
            <foreach collection="business" index="index" item="item" open="(" separator="," close="">
                #{item.businessCode}
            </foreach>
            ) or (t.dept_id is null or t.dept_id='' or t.dept_id='99'))
        </if>
        <if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
            and ele_invoice_no = #{eleInvoiceNo}
        </if>
        order by t.gx_date desc,kprq desc
    </select>
    <select id="selectByPramsMap" parameterType="java.util.Map"
            resultType="com.dxhy.core.model.FpRzRespVO" databaseId="oracle">
        select t.id id,t.uuid uuid, t.invoice_amount je, t.tax_amount se,
        to_char(t.invoice_date,'yyyy-mm-dd')kprq,t.gf_name gfmc,t.gf_tax_no gfsh,
        t.xf_name xfmc,to_char(t.qs_date,'yyyy-mm-dd') qsrq,t.qs_status qszt,t.qs_name qsr,t.qs_type
        qsfs,t.invoice_code
        fpdm,t.invoice_no fphm,t.dept_id deptId,t.dept_name businessName,t.invoice_type
        invoiceType,t.gx_user_name,
        to_char(t.gx_date,'yyyy-mm-dd') gxrq,t.dk_tax_amount yxdkse,c.current_tax_period
        dqskssq,t.payment_status,to_char(t.payment_date,'yyyy-mm-dd')payment_date,t.ele_invoice_no
        from t_dx_record_invoice t,t_dx_tax_current c
        WHERE t.gf_tax_no = c.taxno
        and to_char(t.invoice_date,'yyyy-mm-dd') between #{gxksrq} and #{gxjsrq}
        and t.auth_status = '1'
        and t.rzh_yesorno = '0'
        and t.sfygx = '1'
        and (t.invoice_type in('01','03','08','14','31','283','161','183','185') or (t.invoice_type ='32' and t.lq_tdyslxDm='08'))
        and t.export_mark = '0'
        and t.bdk_status = '1'
        and t.company = #{company}
        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 t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceSource != null and invoiceSource != '' and invoiceSource != '99'">
            and t.invoice_source = #{invoiceSource}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like concat(#{xfmc},'%')
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' ">
            and t.qs_status = #{qszt}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            and t.qs_name = #{qsr}
        </if>
        <if test="voucherNumber != null and voucherNumber != ''">
            and t.voucher_number like concat('%',concat(#{voucherNumber},'%'))
        </if>
        <if test="gxUser != null and gxUser != '' and gxUser != 'null' and gxUser != '99'">
            and t.gx_user_account = #{gxUser}
        </if>
        <if test="paymentDateStart != null and paymentDateStart != '' and paymentDateStart != 'null' ">
            <![CDATA[ AND to_char(t.payment_date,'%Y-%m-%d') >= #{paymentDateStart} ]]>
        </if>
        <if test="paymentDateEnd != null and paymentDateEnd != '' and paymentDateEnd != 'null' ">
            <![CDATA[ AND to_char(t.payment_date,'%Y-%m-%d')  <= #{paymentDateEnd} ]]>
        </if>
        <if test="paymentStatus != null and paymentStatus != '' and paymentStatus != '99'">
            and t.payment_status = #{paymentStatus}
        </if>
        <if
                test="businessCode != '99' and businessCode != null and businessCode != '' and businessCode != 'null' ">
            and t.dept_id = #{businessCode}
        </if>
        <if test="businessCode==''">
            and (t.dept_id is null or t.dept_id='' or t.dept_id='99')
        </if>
        <if test='businessCode == "99" and business!=null and business.size()>0'>
            and (t.dept_id in
            <foreach collection="business" index="index" item="item" open="(" separator="," close="">
                #{item.businessCode}
            </foreach>
            ) or (t.dept_id is null or t.dept_id='' or t.dept_id='99'))
        </if>
        <if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
            and ele_invoice_no = #{eleInvoiceNo}
        </if>
        order by t.gx_date desc,kprq desc
    </select>

</mapper>
