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

    <resultMap id="FprzybResultMap" type="com.dxhy.core.model.FprzybRespVO">
        <result column="skssq" property="skssq"/>
        <result column="fpsl" property="fpsl"/>
        <result column="hjje" property="hjje"/>
        <result column="hjse" property="hjse"/>
        <result column="dkse" property="dkse"/>
    </resultMap>
    <select id="selectByGfshAndRznf" parameterType="java.util.Map"
            resultMap="FprzybResultMap" databaseId="mysql">
        select
        right (t.rzh_belong_date,2) rzDate,
        t.rzh_belong_date skssq,
        COUNT(t.id ) as fpsl,
        ifnull(sum(invoice_amount),0) as hjje,
        ifnull(sum(tax_amount),0) as hjse ,
        ifnull(sum(dk_tax_amount),0) as dkse
        from t_dx_record_invoice t
        where
        (t.invoice_type in (${krzpz}) or (t.invoice_type = '32' and t.lq_tdyslxDm = '08'))
        and t.auth_status = '4' <!--and rzh_yesorno='1'-->
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>

        <if test="rznf != null and rznf != '' and rznf != 'null' and rznf != '99' ">
            and LEFT(rzh_belong_date,4) = #{rznf}
        </if>
        <if test="company!=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="dklx!=null and dklx!=''">
            and t.rzh_yesorno=#{dklx}
        </if>
        GROUP BY t.rzh_belong_date ORDER by t.rzh_belong_date
    </select>

    <select id="selectRzfphzByRznf" parameterType="java.util.Map"
            resultMap="FprzybResultMap" databaseId="mysql">
        select
        right (t.rzh_belong_date,2) rzDate,
        t.rzh_belong_date skssq,
        COUNT(t.id ) as fpsl,
        sum(invoice_amount) as hjje,
        sum(tax_amount) as hjse ,
        sum(dk_tax_amount) as dkse
        from t_dx_record_invoice t
        where
        t.auth_status = '4' and
        <!--t.rzh_yesorno = '1'and-->
        (t.invoice_type in (${krzpz}) or (t.invoice_type = '32' and t.lq_tdyslxDm = '08'))
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="rznf != null and rznf != '' and rznf != 'null' and rznf != '99' ">
            and LEFT(rzh_belong_date,4) = #{rznf}
        </if>
        <if test="company !=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="dklx!=null and dklx!=''">
            and t.rzh_yesorno =#{dklx}
        </if>
        GROUP BY t.rzh_belong_date ORDER by t.rzh_belong_date
    </select>

    <select id="selectByGfshAndRznf" parameterType="java.util.Map"
            resultMap="FprzybResultMap" databaseId="oracle">
        select
        SUBSTR (t.rzh_belong_date,5) rzDate,
        t.rzh_belong_date skssq,
        COUNT(t.id ) as fpsl,
        COALESCE(sum(invoice_amount),0) as hjje,
        COALESCE(sum(tax_amount),0) as hjse ,
        COALESCE(sum(dk_tax_amount),0) as dkse
        from t_dx_record_invoice t
        where
        (t.invoice_type in (${krzpz}) or (t.invoice_type = '32' and t.lq_tdyslxDm = '08'))
        and t.auth_status = '4' <!--and rzh_yesorno='1'-->
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>

        <if test="rznf != null and rznf != '' and rznf != 'null' and rznf != '99' ">
            and SUBSTR (t.rzh_belong_date,0,LENGTH(t.rzh_belong_date) - 2) = #{rznf}
        </if>
        <if test="company!=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="dklx!=null and dklx!=''">
            and t.rzh_yesorno=#{dklx}
        </if>
        GROUP BY t.rzh_belong_date,SUBSTR (t.rzh_belong_date,5) ORDER by t.rzh_belong_date
    </select>

    <select id="selectRzfphzByRznf" parameterType="java.util.Map"
            resultMap="FprzybResultMap" databaseId="oracle">
        select
        SUBSTR (t.rzh_belong_date,5) rzDate,
        t.rzh_belong_date skssq,
        COUNT(t.id ) as fpsl,
        sum(invoice_amount) as hjje,
        sum(tax_amount) as hjse ,
        sum(dk_tax_amount) as dkse
        from t_dx_record_invoice t
        where
        <!--t.rzh_yesorno = '1' and-->
        t.auth_status = '4' and
        (t.invoice_type in (${krzpz}) or (t.invoice_type = '32' and t.lq_tdyslxDm = '08'))
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="rznf != null and rznf != '' and rznf != 'null' and rznf != '99' ">
            and SUBSTR (t.rzh_belong_date,0,LENGTH(t.rzh_belong_date) - 2) = #{rznf}
        </if>
        <if test="company !=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="dklx!=null and dklx!=''">
            and t.rzh_yesorno =#{dklx}
        </if>
        GROUP BY t.rzh_belong_date,SUBSTR (t.rzh_belong_date,5) ORDER by t.rzh_belong_date
    </select>

    <select id="selectTaxList" resultType="com.dxhy.api.model.db.TDxTaxCurrentEntity">
        select * from t_dx_tax_current where taxno in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>