<?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.base.dao.BaseYqfpxxDao">

    <resultMap id="YqfpxxResultMap" type="com.dxhy.base.model.BaseYqrzRespVO">
        <result column="id" property="id"/>
        <result column="uuid" property="uuid"/>
        <result column="fpdm" property="fpdm"/>
        <result column="fphm" property="fphm"/>
        <result column="invoiceType" property="invoiceType"/>
        <result column="kprq" property="kprq"/>
        <result column="gfmc" property="gfmc"/>
        <result column="gfsh" property="gfsh"/>
        <result column="xfsh" property="xfsh"/>
        <result column="je" property="je"/>
        <result column="se" property="se"/>
        <result column="dkse" property="dkse"/>
        <result column="sfrz" property="sfrz"/>
        <result column="rzsj" property="rzsj"/>
        <result column="authStatus" property="authStatus"/>
    </resultMap>
    <select id="selectByYqcxtj" parameterType="java.util.Map"
            resultMap="YqfpxxResultMap" databaseId="mysql">
        select t.id id,t.uuid uuid,t.invoice_code fpdm,t.invoice_no fphm,invoice_type
        invoiceType,DATE_FORMAT(t.invoice_date,"%Y-%m-%d") kprq,t.gf_name gfmc,t.gf_tax_no gfsh,t.xf_tax_no
        xfsh,t.invoice_amount je,t.tax_amount se,
        t.dk_tax_amount dkse,t.rzh_yesorno sfrz,date_format(t.rzh_date,'%Y-%m-%d') rzsj,t.auth_status authStatus
        from t_dx_record_invoice t
        where t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and
        
        t.yqkgxbz='1' and
        t.rzh_yesorno = '0' and
        t.auth_status in ('0','1','5','6') and
        t.export_mark = '0' and
        date_format(t.invoice_date,'%Y-%m-%d') between #{kprqq} and #{kprqz}
        <if test="fphm != null and fphm != '' and fphm != 'null' ">
            and t.invoice_no = #{fphm}
        </if>

        <if test="fplx != null and fplx != '' and fplx != 'null' ">
            and t.invoice_type = #{fplx}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource=='99'">
            and t.invoice_type in ('01','03','08','14','31')
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="0"'>
            and t.invoice_type in ('01','03','08','14')
            and t.invoice_source = '0'
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="1"'>
            and t.invoice_type = '31'
            and t.invoice_source = '1'
        </if>

        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like concat(#{xfmc},'%')
        </if>

        <if test="sfrz != null and sfrz != '' and sfrz != 'null' ">
            and t.rzh_yesorno = #{sfrz}
        </if>

        order by t.invoice_date
    </select>


    <select id="selectByYqcxtj" parameterType="java.util.Map"
            resultMap="YqfpxxResultMap" databaseId="oracle">
        select t.id id,t.uuid uuid,t.invoice_code fpdm,t.invoice_no fphm,invoice_type
        invoiceType,to_char(t.invoice_date,'yyyy-mm-dd') kprq,t.gf_name gfmc,t.gf_tax_no gfsh,t.xf_tax_no
        xfsh,t.invoice_amount je,t.tax_amount se,
        t.dk_tax_amount dkse,t.rzh_yesorno sfrz,to_char(t.rzh_date,'yyyy-mm-dd') rzsj,t.auth_status authStatus
        from t_dx_record_invoice t
        where t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and
        
        t.yqkgxbz='1' and
        t.rzh_yesorno = '0' and
        t.auth_status in ('0','1','5','6') and
        t.bdk_status in ('0','5') and
        to_char(t.invoice_date,'yyyy-mm-dd') between #{kprqq} and #{kprqz}
        <if test="fphm != null and fphm != '' and fphm != 'null' ">
            and t.invoice_no = #{fphm}
        </if>

        <if test="fplx != null and fplx != '' and fplx != 'null' ">
            and t.invoice_type = #{fplx}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource=='99'">
            and t.invoice_type in ('01','03','14','31')
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="0"'>
            and t.invoice_type in ('01','03','14')
            and t.invoice_source = '0'
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="1"'>
            and t.invoice_type = '31'
            and t.invoice_source = '1'
        </if>

        <if test="xfsh != null and xfsh != '' and xfsh != 'null' ">
            and t.xf_tax_no = #{xfsh}
        </if>

        <if test="sfrz != null and sfrz != '' and sfrz != 'null' ">
            and t.rzh_yesorno = #{sfrz}
        </if>

        order by t.invoice_date
    </select>

    <select id="selectHjByYqcxtj" parameterType="java.util.Map"
            resultType="com.dxhy.base.model.BaseYqrzRespVO" databaseId="mysql">
        select count(1) xh,sum(t.invoice_amount) je,sum(t.tax_amount) se
        from t_dx_record_invoice t
        where t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and
        
        t.yqkgxbz='1' and
        t.rzh_yesorno = '0' and
        t.auth_status in ('0','1','5','6') and
        date_format(t.invoice_date,'%Y-%m-%d') between #{kprqq} and #{kprqz}
        <if test="fphm != null and fphm != '' and fphm != 'null' ">
            and t.invoice_no = #{fphm}
        </if>

        <if test="fplx != null and fplx != '' and fplx != 'null' ">
            and t.invoice_type = #{fplx}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource=='99'">
            and t.invoice_type in ('01','03','08','14','31')
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="0"'>
            and t.invoice_type in ('01','03','08','14')
            and t.invoice_source = '0'
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="1"'>
            and t.invoice_type = '31'
            and t.invoice_source = '1'
        </if>

        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like concat(#{xfmc},'%')
        </if>

        <if test="sfrz != null and sfrz != '' and sfrz != 'null' ">
            and t.rzh_yesorno = #{sfrz}
        </if>

    </select>


    <select id="selectHjByYqcxtj" parameterType="java.util.Map"
            resultType="com.dxhy.base.model.BaseYqrzRespVO" databaseId="oracle">
        select count(1) xh,sum(t.invoice_amount) je,sum(t.tax_amount) se
        from t_dx_record_invoice t
        where t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and
        
        t.yqkgxbz='1' and
        t.rzh_yesorno = '0' and
        t.auth_status in ('0','1','5','6') and
        t.bdk_status ='0' and
        to_char(t.invoice_date,'yyyy-mm-dd') between #{kprqq} and #{kprqz}
        <if test="fphm != null and fphm != '' and fphm != 'null' ">
            and t.invoice_no = #{fphm}
        </if>

        <if test="fplx != null and fplx != '' and fplx != 'null' ">
            and t.invoice_type = #{fplx}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource=='99'">
            and t.invoice_type in ('01','03','14','31')
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="0"'>
            and t.invoice_type in ('01','03','14')
            and t.invoice_source = '0'
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="1"'>
            and t.invoice_type = '31'
            and t.invoice_source = '1'
        </if>

        <if test="xfsh != null and xfsh != '' and xfsh != 'null' ">
            and t.xf_tax_no = #{xfsh}
        </if>

        <if test="sfrz != null and sfrz != '' and sfrz != 'null' ">
            and t.rzh_yesorno = #{sfrz}
        </if>
    </select>

</mapper>
