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

    <resultMap id="BaseResultMap"
               type="com.dxhy.extend.model.ExtBbycfpcxRespVO">
        <result column="inaccount_status" property="inAccountStatus"/>
        <result column="bzdh" property="bzdh"/>
        <result column="bzr" property="bzr"/>
        <result column="sn_voucher_number" property="snVoucherNumber"/>
        <result column="account_period" property="accountPeriod"/>
        <result column="posting_time" property="postingTime"/>
        <result column="image_id" property="imageNumber"/>
        <result column="fpdm" property="fpdm"/>
        <result column="fphm" property="fphm"/>
        <result column="invoiceType" property="invoiceType"/>
        <result column="kprq" property="kprq"/>
        <result column="gfsh" property="gfsh"/>
        <result column="gfmc" property="gfmc"/>
        <result column="xfsh" property="xfsh"/>
        <result column="xfmc" property="xfmc"/>
        <result column="je" property="je"/>
        <result column="se" property="se"/>
        <result column="yczt" property="yczt"/>
        <result column="ycsj" property="ycsj"/>
        <result column="qszt" property="qszt"/>
        <result column="qsrq" property="qsrq"/>
        <result column="qsr" property="qsr"/>
        <result column="rzsj" property="rzsj"/>
        <result column="rzzt" property="rzzt"/>
        <result column="rzclzt" property="rzclzt"/>
        <result column="rzlx" property="rzlx"/>
        <result column="skssq" property="skssq"/>
        <result column="dept_name" property="businessName"/>
    </resultMap>

    <resultMap id="BbycfpcxhjResultMap"
               type="com.dxhy.extend.model.ExtBbycfpcxRespVO">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="je"/>
        <result column="hjse" property="se"/>
    </resultMap>

    <select id="selectByPramsMap" parameterType="java.util.Map"
            resultMap="BaseResultMap" databaseId="mysql">
        select
        t.invoice_code fpdm, t.invoice_no fphm ,DATE_FORMAT(t.invoice_date,'%Y-%m-%d')
        kprq,t.gf_tax_no gfsh,t.gf_name gfmc,t.invoice_type invoiceType,
        t.xf_tax_no xfsh,t.xf_name xfmc,t.tax_amount se,t.invoice_amount
        je,DATE_FORMAT(t.qs_date,'%Y-%m-%d') qsrq,t.inaccount_status,t.bzdh,t.bzr,
        t.qs_status qszt,t.qs_name qsr, t.invoice_status
        yczt,DATE_FORMAT(t.status_update_date,'%Y-%m-%d') ycsj,rzh_date
        rzsj,t.sn_voucher_number,t.account_period,t.posting_time,t.image_id,
        rzh_yesorno rzzt,auth_status rzclzt,bdk_status rzlx,rzh_belong_date skssq,dept_name
        from t_dx_record_invoice t
        WHERE t.invoice_status != '0'
        and t.invoice_type in ('01','03','08','14','31')
        and t.company = #{company}
        and t.invoice_date between #{kpksrq} and #{kpjsrq}
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null'">
            and t.bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and t.bzr like concat('%',#{bzr},'%')
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and t.inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (t.inaccount_status = '0' or t.inaccount_status = '' or t.inaccount_status is null)
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and t.sn_voucher_number = #{snVoucherNumber}
        </if>
        <if test="postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99' and postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99'">
            and t.posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>
        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and t.image_id = #{imageNumber}
        </if>
        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and t.account_period = #{accountPeriod}
        </if>
        <if
                test="yczt != null and yczt != '' and yczt != 'null' ">
            and t.invoice_status = #{yczt}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' ">
            and t.qs_status = #{qszt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null'  and rzzt != 3">
            and t.rzh_yesorno = #{rzzt}
        </if>
        <if test="rzzt != null and rzzt == 3">
            and (t.rzh_yesorno = '2' OR t.rzh_yesorno = '1')
        </if>
        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like CONCAT(#{xfmc},'%')
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </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>
    </select>
    <select id="selectByPramsMap" parameterType="java.util.Map"
            resultMap="BaseResultMap" databaseId="oracle">
        select
        t.invoice_code fpdm, t.invoice_no fphm ,to_char(t.invoice_date,'yyyy-mm-dd')
        kprq,t.gf_tax_no gfsh,t.gf_name gfmc,t.invoice_type invoiceType,
        t.xf_tax_no xfsh,t.xf_name xfmc,t.tax_amount se,t.invoice_amount
        je,to_char(t.qs_date,'yyyy-mm-dd') qsrq,
        t.qs_status qszt,t.qs_name qsr, t.invoice_status yczt,to_char(t.status_update_date,'yyyy-mm-dd')
        ycsj ,
        rzh_date rzsj,rzh_yesorno rzzt,auth_status rzclzt,bdk_status rzlx,rzh_belong_date
        skssq,dept_name
        from t_dx_record_invoice t
        WHERE t.invoice_status != '0'
        and t.invoice_type in ('01','03','08','14','31')
        and t.company = #{company}
        and t.invoice_date between to_date(#{kpksrq},'yyyy-mm-dd hh24:mi:ss') and
        to_date(#{kpjsrq},'yyyy-mm-dd
        hh24:mi:ss')
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if
                test="yczt != null and yczt != '' and yczt != 'null' ">
            and t.invoice_status = #{yczt}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' ">
            and t.qs_status = #{qszt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null' ">
            and t.rzh_yesorno = #{rzzt}
        </if>
        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like CONCAT(#{xfmc},'%')
        </if>
        <if
                test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </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>
    </select>

    <select id="selectBbfpzhHj" parameterType="java.util.Map"
            resultMap="BbycfpcxhjResultMap" databaseId="mysql">

        select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_record_invoice t
        where t.invoice_status != '0'
        and t.invoice_type in ('01','03','08','14','31')
        and t.company = #{company}
        and DATE_FORMAT(t.invoice_date,'%Y-%m-%d') between #{kpksrq} and #{kpjsrq}
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null'">
            and t.bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and t.bzr like concat('%',#{bzr},'%')
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and t.inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (t.inaccount_status = '0' or t.inaccount_status = '' or t.inaccount_status is null)
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and t.sn_voucher_number = #{snVoucherNumber}
        </if>
        <if test="postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99' and postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99'">
            and t.posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>
        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and t.image_id = #{imageNumber}
        </if>
        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and t.account_period = #{accountPeriod}
        </if>
        <if
                test="yczt != null and yczt != '' and yczt != 'null' ">
            and t.invoice_status = #{yczt}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' ">
            and t.qs_status = #{qszt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null'  and rzzt != '3'">
            and t.rzh_yesorno = #{rzzt}
        </if>
        <if test="rzzt != null and rzzt == '3'">
            and (t.rzh_yesorno = '2' OR t.rzh_yesorno = '1')
        </if>
        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like CONCAT(#{xfmc},'%')
        </if>
        <if
                test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </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>

    </select>
    <select id="selectBbfpzhHj" parameterType="java.util.Map"
            resultMap="BbycfpcxhjResultMap" databaseId="oracle">

        select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_record_invoice t
        where
        t.invoice_status != '0'
        and t.invoice_type in ('01','03','08','14','31')
        and t.company = #{company}
        and t.invoice_date between to_date(#{kpksrq},'yyyy-mm-dd hh24:mi:ss') and
        to_date(#{kpjsrq},'yyyy-mm-dd
        hh24:mi:ss')
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if
                test="yczt != null and yczt != '' and yczt != 'null' ">
            and t.invoice_status = #{yczt}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' ">
            and t.qs_status = #{qszt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null' ">
            and t.rzh_yesorno = #{rzzt}
        </if>
        <if test="xfmc != null and xfmc != '' and xfmc != 'null' ">
            and t.xf_name like CONCAT(#{xfmc},'%')
        </if>
        <if
                test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </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>

    </select>

</mapper>
