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

    <resultMap id="BbycfpcxhjResultMap"
               type="com.dxhy.core.model.BbrzrbcxRespVO">
        <result column="hjsl" property="hjsl"/>
        <result column="hjje" property="hjje"/>
        <result column="hjse" property="hjse"/>
        <result column="rzrq" property="rzrq"/>
        <result column="dkse" property="dkse"/>
        <result column="rzDate" property="rzDate"/>
    </resultMap>

    <resultMap id="hjxxMap"
               type="com.dxhy.core.model.BbrzrbcxRespVO">
        <result column="gfsh" property="gfsh"/>
        <result column="gfmc" property="gfmc"/>
        <result column="hjsl" property="hjsl"/>
        <result column="hjje" property="hjje"/>
        <result column="hjse" property="hjse"/>
    </resultMap>

    <select id="selectBbycfpbbHj" parameterType="java.util.Map"
            resultMap="BbycfpcxhjResultMap" databaseId="mysql">
        select count(1) hjsl, DATE_FORMAT(t.rzh_date,'%Y-%m-%d') rzrq ,DATE_FORMAT(t.rzh_date,'%d') rzDate
        ,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse , sum(t.dk_tax_amount) dkse
        from t_dx_record_invoice t
        where t.auth_status = '4' <!--and rzh_yesorno='1'-->
        and t.invoice_type in ('01','03','08','14','31')
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="company !=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="dklx !=null and dklx !='' and dklx!='null'">
            and t.rzh_yesorno =#{dklx}
        </if>
        GROUP BY DATE_FORMAT(rzh_date,'%Y-%m-%d'),gf_tax_no
        order by rzrq desc
    </select>
    <select id="selectBbycfpbbHj" parameterType="java.util.Map"
            resultMap="BbycfpcxhjResultMap" databaseId="oracle">
        select to_char(t.rzh_date,'yyyy-mm-dd') rzrq , to_char(t.rzh_date,'dd') rzDate ,count(1)
        hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse, sum(t.dk_tax_amount) dkse
        from t_dx_record_invoice t
        where t.auth_status = '4' <!--and rzh_yesorno='1'-->
        and t.invoice_type in ('01','03','08','14','31')
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="company !=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="dklx !=null and dklx !='' and dklx!='null'">
            and t.rzh_yesorno =#{dklx}
        </if>
        GROUP BY
        to_char( rzh_date, 'yyyy-mm-dd' ),
        gf_tax_no ,to_char( t.rzh_date, 'dd' )
        ORDER BY
        to_char( t.rzh_date, 'yyyy-mm-dd' ) DESC
    </select>

    <select id="selectHjxx" parameterType="java.util.Map"
            resultMap="hjxxMap">

        select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_record_invoice t
        where t.auth_status = '4'
        and rzh_yesorno='1'
        and t.invoice_type in ('01','03','14')
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>

    </select>

</mapper>
