<?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.extend.dao.ExtRzjgqdDao">

    <resultMap id="RzjgqdResultMap" type="com.dxhy.extend.model.ExtRzjgqdRespVO">
        <result column="id" property="id"/>
        <result column="uuid" property="uuid"/>
        <result column="fpdm" property="fpdm"/>
        <result column="fphm" property="fphm"/>
        <result column="fplx" property="fplx"/>
        <result column="kprq" property="kprq"/>
        <result column="xfsh" property="xfsh"/>
        <result column="xfmc" property="xfmc"/>
        <result column="je" property="je"/>
        <result column="se" property="se"/>
        <result column="dkse" property="dkse"/>
        <result column="rzrq" property="rzrq"/>
    </resultMap>

    <resultMap id="HjxxMap" type="com.dxhy.extend.model.ExtTjbbHjxxVO">
        <result column="hjsl" property="hjsl"/>
        <result column="hjje" property="hjje"/>
        <result column="hjse" property="hjse"/>
    </resultMap>

    <select id="rzjgByGfshAndSkssq" parameterType="java.util.Map"
            resultMap="RzjgqdResultMap" databaseId="mysql">
        select t.id id,t.uuid uuid,t.invoice_code fpdm,t.invoice_no fphm,t.invoice_type fplx,
        date_format(t.invoice_date,'%Y-%m-%d') kprq,
        t.xf_tax_no xfsh,t.xf_name xfmc,t.invoice_amount je,t.tax_amount se,t.dk_tax_amount
        dkse,date_format(t.rzh_date,'%Y-%m-%d') rzrq,
        t.invoice_type,
        t.rzh_yesorno dklx
        from t_dx_record_invoice t
        where t.invoice_type in ('01','03','08','14','31') and t.auth_status = '4' <!--and rzh_yesorno='1'-->
        and t.company = #{company}
        and t.gf_tax_no = #{gfsh}
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="dklx!=null and dklx!=''">
            <choose>
                <when test='dklx=="99"'>
                    and t.rzh_yesorno in ('1','2')
                </when>
                <otherwise>
                    and t.rzh_yesorno = #{dklx}
                </otherwise>
            </choose>
        </if>
    </select>

    <select id="rzjgByGfshAndSkssq" parameterType="java.util.Map"
            resultMap="RzjgqdResultMap" databaseId="oracle">
        select t.id id,t.uuid uuid,t.invoice_code fpdm,t.invoice_no fphm,t.invoice_type fplx,
        to_char(t.invoice_date,'yyyy-MM-dd') kprq,
        t.xf_tax_no xfsh,t.xf_name xfmc,t.invoice_amount je,t.tax_amount se,t.dk_tax_amount
        dkse,to_char(t.rzh_date,'yyyy-MM-dd') rzrq,
        t.invoice_type,
        t.rzh_yesorno dklx
        from t_dx_record_invoice t
        where t.invoice_type in ('01','03','08','14','31') and t.auth_status = '4' <!--and rzh_yesorno='1'-->
        and t.company = #{company}
        and t.gf_tax_no = #{gfsh}
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="dklx!=null and dklx!=''">
            <choose>
                <when test='dklx=="99"'>
                    and t.rzh_yesorno in ('1','2')
                </when>
                <otherwise>
                    and t.rzh_yesorno = #{dklx}
                </otherwise>
            </choose>
        </if>
    </select>

    <select id="rzjghjxxByGfshAndSkssq" parameterType="java.util.Map"
            resultMap="HjxxMap">
        select COUNT(1)hjsl, SUM(t.invoice_amount)hjje, SUM(t.tax_amount)hjse,SUM(t.dk_tax_amount) hjdkse
        from t_dx_record_invoice t
        where t.invoice_type in ('01','03','08','14','31') and t.auth_status = '4' <!-- and rzh_yesorno='1'-->
        and t.company = #{company}
        and t.gf_tax_no = #{gfsh}
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="dklx!=null and dklx!=''">
            <choose>
                <when test='dklx=="99"'>
                    and t.rzh_yesorno in ('1','2')
                </when>
                <otherwise>
                    and t.rzh_yesorno = #{dklx}
                </otherwise>
            </choose>
        </if>
    </select>


</mapper>
