<?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.erp.dao.TdxInvoiceDao">
    <select id="selectAllCount" resultType="Integer" databaseId="mysql">
        select
        count(1)
        from t_dx_invoice t
        where 1=1
        and date_format(t.qs_date,'%Y%m%d%H%i%s') between #{pramsMap.qsDateBegin} and
        #{pramsMap.qsDateEnd}
        <if test="pramsMap.buyerTaxNo !=null and pramsMap.buyerTaxNo != ''">
            and t.gf_tax_no = #{pramsMap.buyerTaxNo}
        </if>
        <if test="pramsMap.qsStatus != null and pramsMap.qsStatus != ''">
            and t.qs_status = #{pramsMap.qsStatus}
        </if>
        <if test="pramsMap.qsUser != null and pramsMap.qsUser != ''">
            and t.user_name = #{pramsMap.qsUser}
        </if>

    </select>


    <select id="selectAllCount" resultType="Integer" databaseId="oracle">
        select
        count(1)
        from t_dx_invoice t
        where 1=1
        and to_char(t.qs_date,'YYYYMMDDHH24MISS') between #{pramsMap.qsDateBegin} and
        #{pramsMap.qsDateEnd}
        <if test="pramsMap.buyerTaxNo !=null and pramsMap.buyerTaxNo != ''">
            and t.gf_tax_no = #{pramsMap.buyerTaxNo}
        </if>
        <if test="pramsMap.qsStatus != null and pramsMap.qsStatus != ''">
            and t.qs_status = #{pramsMap.qsStatus}
        </if>
        <if test="pramsMap.qsUser != null and pramsMap.qsUser != ''">
            and t.user_name = #{pramsMap.qsUser}
        </if>

    </select>


    <select id="selectByParam" resultType="com.dxhy.erp.entity.InvoiceElectron" databaseId="mysql">
        select
        *
        from t_dx_invoice t
        where date_format(t.qs_date,'%Y%m%d%H%i%s') between #{pramsMap.qsDateBegin} and
        #{pramsMap.qsDateEnd}
        <if test="pramsMap.buyerTaxNo !=null and pramsMap.buyerTaxNo != ''">
            and t.gf_tax_no = #{pramsMap.buyerTaxNo}
        </if>
        <if test="pramsMap.qsStatus != null and pramsMap.qsStatus != ''">
            and t.qs_status = #{pramsMap.qsStatus}
        </if>
        <if test="pramsMap.qsUser != null and pramsMap.qsUser != ''">
            and t.user_name = #{pramsMap.qsUser}
        </if>

        order by t.qs_date limit #{pramsMap.start},#{pramsMap.num}
    </select>


    <select id="selectByParam" resultType="com.dxhy.erp.entity.InvoiceElectron" databaseId="oracle">
        select * from (
        select
        t.*, rownum as num
        from t_dx_invoice t
        where 1=1
        and to_char(t.qs_date,'YYYYMMDDHH24MISS') between #{pramsMap.qsDateBegin} and
        #{pramsMap.qsDateEnd}
        <if test="pramsMap.buyerTaxNo !=null and pramsMap.buyerTaxNo != ''">
            and t.gf_tax_no = #{pramsMap.buyerTaxNo}
        </if>
        <if test="pramsMap.qsStatus != null and pramsMap.qsStatus != ''">
            and t.qs_status = #{pramsMap.qsStatus}
        </if>
        <if test="pramsMap.qsUser != null and pramsMap.qsUser != ''">
            and t.user_name = #{pramsMap.qsUser}
        </if>

        order by t.qs_date
        ) where  <![CDATA[  num> #{pramsMap.start}  and num<=#{pramsMap.num}+ #{pramsMap.start}  ]]>
    </select>


    <select id="getTaxs" resultType="com.dxhy.common.vo.Tax">
        select taxno, taxname
        from sys_user_org
        where userid = #{userId}
    </select>

    <!-- 58接口  获取符合条件的数据总数 -->
    <select id="selectSignResultCount" resultType="java.lang.Integer">
        select count(1) from t_dx_invoice where gf_tax_no in
        <foreach collection="enterpriseCode" item="enterprise" open="(" close=")" separator=",">
            #{enterprise}
        </foreach>
        AND  <![CDATA[qs_date >=#{start}]]>
        AND  <![CDATA[qs_date <#{end}]]>
    </select>
    <!-- 58接口   -->
    <select id="selectSignResul" resultType="com.dxhy.erp.model.SignInvoiceInfos">
        select
        t.invoice_code invoiceCode,
        t.invoice_no invoiceNo,
        t.invoice_date invoiceDate,
        t.gf_tax_no gfTaxNo,
        t.gf_name gfName,
        t.total_amount totalAmount,
        t.xf_name xfName,
        t2.remark,
        t.qs_status qsStatus,
        t.notes notes
        from t_dx_invoice t left join t_dx_record_invoice t2 on t.uuid = t2.uuid
        where t.gf_tax_no in
        <foreach collection="enterpriseCode" item="enterprise" open="(" close=")" separator=",">
            #{enterprise}
        </foreach>
        AND  <![CDATA[t.qs_date >=#{start}]]>
        AND  <![CDATA[t.qs_date <#{end}]]>
        LIMIT #{startNum},#{num}
    </select>
    <!-- 58接口   -->
    <select id="findDetailByUUid" resultType="java.lang.String">
        select goods_name
        from t_dx_record_invoice_detail
        where uuid = #{uuid} limit 1
    </select>
</mapper>
