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

    <select id="selectByDkCount" parameterType="java.util.Map"
            resultType="com.dxhy.base.model.BaseTDxDkCountRespVO" databaseId="mysql">
        select t.id,t.taxno,t.taxname,t.skssq,date_format(t.create_date ,'%Y-%m-%d') createDate,t.tj_status
        tjStatus,t.qs_status qsStatus,t.sfdqskssq,
        d.dk_tax_amount_count dksehj,t.cxtj_status cxtjStatus,t.tj_date tjDate,t.cxqs_status cxqsStatus,t.apply_msg,
        t.tj_user,t.qr_user,date_format(t.qr_date,'%Y-%m-%d %H:%i:%s')qrDate,d.dk_invoice_count invoiceNum
        from t_dx_dk_count t left join t_dx_dk_count_detail d
        on t.taxno=d.taxno and t.skssq=d.tj_month
        where (d.invoice_type='99' or d.invoice_type is null)  and (tjjglx='1' or tjjglx is null) and
        t.taxno in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.skssq = #{skssq}
        </if>
        <if test='tjzt != null and tjzt != "" and tjzt != "null" and tjzt != "6"'>
            and t.tj_status = #{tjzt}
        </if>
        <if test='tjzt=="0"'>
            and sfdqskssq = '1'
            <![CDATA[ and date_add(str_to_date(concat(t.skssq,01),'%Y%m%d'), interval 1 month)< now() ]]>
        </if>
        <if test='tjzt == "6" or qrtjzt == "6"'>
            and sfdqskssq = '1'
            <![CDATA[ and date_add(str_to_date(concat(t.skssq,01),'%Y%m%d'), interval 1 month)> str_to_date(date_format(now(),'%Y%m%d'),'%Y%m%d') ]]>
        </if>
        <if test='qrtjzt != null and qrtjzt != "" and qrtjzt != "null" and qrtjzt !="6"'>
            and t.qs_status = #{qrtjzt}
        </if>

        order by t.skssq desc,t.taxno
    </select>

    <select id="selectByDkCount" parameterType="java.util.Map"
            resultType="com.dxhy.base.model.BaseTDxDkCountRespVO" databaseId="oracle">
        select t.id,t.taxno,t.taxname,t.skssq,t.create_date createDate,t.tj_status tjStatus,t.qs_status
        qsStatus,t.sfdqskssq,
        d.dk_tax_amount_count dksehj,t.cxtj_status cxtjStatus,t.tj_date tjDate,t.cxqs_status cxqsStatus,t.apply_msg,
        t.tj_user,t.qr_user,to_char(t.qr_date,'yyyy-MM-dd HH:mm:ss') qrDate,d.dk_invoice_count invoiceNum
        from t_dx_dk_count t left join t_dx_dk_count_detail d
        on t.taxno=d.taxno and t.skssq=d.tj_month
        where
        (d.invoice_type='99' or d.invoice_type is null) and
        t.taxno in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.skssq = #{skssq}
        </if>
        <if test='tjzt != null and tjzt != "" and tjzt != "null" and tjzt != "6"'>
            and t.tj_status = #{tjzt}
        </if>
        <if test='tjzt == "0"'>
            and sfdqskssq = '1'
            <![CDATA[ and add_months(to_date(concat(t.skssq,'01'),'yyyyMMdd'),1) < sysdate ]]>
        </if>
        <if test='tjzt == "6" or qrtjzt == "6"'>
            and sfdqskssq = '1'
            <![CDATA[ and add_months(to_date(concat(t.skssq,'01'),'yyyyMMdd'),1) > to_date(to_char(sysdate,'yyyyMMdd'),'yyyyMMdd') ]]>
        </if>
        <if test='qrtjzt != null and qrtjzt != "" and qrtjzt != "null" and qrtjzt !="6"'>
            and t.qs_status = #{qrtjzt}
        </if>
        order by t.skssq desc,t.taxno
    </select>

    <select id="getPassword" resultType="com.dxhy.common.vo.TaxOrgCode">
        select *
        from sys_dept
        where taxno = #{taxno}
          and org_type = '5'
          and del_flag = '0'
    </select>
</mapper>
