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

    <resultMap id="CjmxResultMap" type="com.dxhy.base.entity.BaseTDxRecordInvoice">
        <result column="invoice_code" property="invoiceCode"/>
        <result column="invoice_no" property="invoiceNo"/>
        <result column="invoice_type" property="invoiceType"/>
        <result column="gf_name" property="gfName"/>
        <result column="xf_name" property="xfName"/>
        <result column="invoice_date" property="invoiceDate"/>
        <result column="invoice_amount" property="invoiceAmount"/>
        <result column="tax_amount" property="taxAmount"/>
        <result column="invoice_status" property="invoiceStatus"/>
        <result column="status_update_date" property="statusUpdateDate"/>
        <result column="ele_invoice_no" property="eleInvoiceNo"/>
    </resultMap>

    <resultMap id="WbmxResultMap" type="com.dxhy.base.entity.BaseTDxRecordInvoice">
        <result column="invoice_code" property="invoiceCode"/>
        <result column="invoice_no" property="invoiceNo"/>
        <result column="gf_name" property="gfName"/>
        <result column="xf_name" property="xfName"/>
        <result column="invoice_date" property="invoiceDate"/>
        <result column="invoice_amount" property="invoiceAmount"/>
        <result column="tax_amount" property="taxAmount"/>
        <result column="invoice_status" property="invoiceStatus"/>
        <result column="create_date" property="createDate"/>
        <result column="total_amount" property="totalAmount"/>
        <result column="invoice_source" property="invoiceSource"/>
        <result column="ele_invoice_no" property="eleInvoiceNo"/>
    </resultMap>

    <resultMap id="WbmxhjResultMap" type="com.dxhy.base.entity.BaseTDxRecordInvoice">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="invoiceAmount"/>
        <result column="hjse" property="taxAmount"/>
    </resultMap>
    <update id="updatePassword">
        update sys_dept
        set password=#{password}
        where taxno = #{taxno}
          and org_type = '5'
    </update>
    <update id="updatePwd">
       update t_dx_tax_current
        set new_bussi_pwd=#{password}
        where taxno = #{taxno}
    </update>
    <select id="selectCjmxByGfshAndCjrq" parameterType="java.util.Map"
            resultMap="CjmxResultMap" databaseId="mysql">
        select t.invoice_code,t.invoice_no,t.gf_name,t.xf_name, DATE_FORMAT(t.invoice_date,'%Y-%m-%d')
        invoice_date,t.invoice_amount,t.tax_amount,t.invoice_status,DATE_FORMAT(t.status_update_date,'%Y-%m-%d')
        status_update_date,t.invoice_Type,t.ele_invoice_no
        from t_dx_record_invoice t
        where t.gf_tax_no = #{gfsh}
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        and DATE_FORMAT(t.create_date,'%Y-%m-%d') = #{cjrq}
        <if test="ycpbz != null and ycpbz != '' and ycpbz != 'null' ">
            and t.invoice_status !='0'
        </if>
        and t.source_system = '0'
        order by  t.ele_invoice_no DESC,t.invoice_code,t.invoice_no,t.create_date desc
    </select>

    <select id="selectCjmxByGfshAndCjrq" parameterType="java.util.Map"
            resultMap="CjmxResultMap" databaseId="oracle">
        select t.invoice_code,t.invoice_no,t.gf_name,t.xf_name,
        t.invoice_date,t.invoice_amount,t.tax_amount,t.invoice_status,t.status_update_date
        status_update_date,t.invoice_Type,t.ele_invoice_no
        from t_dx_record_invoice t
        where t.gf_tax_no = #{gfsh}
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        and to_char(t.create_date,'yyyy-mm-dd') between #{cjrq} and #{cjrq}
        <if test="ycpbz != null and ycpbz != '' and ycpbz != 'null' ">
            and t.invoice_status !='0'
        </if>
        and t.source_system = '0'
        order by  t.ele_invoice_no DESC,t.invoice_code,t.invoice_no,t.create_date desc
    </select>

    <select id="selectWbfpmx" parameterType="java.util.Map"
            resultMap="WbmxResultMap" databaseId="mysql">
        select
        t.invoice_type,t.invoice_code,t.invoice_no,invoice_date,t.invoice_amount,t.tax_amount,t.gf_name,t.xf_name,t.check_code,create_date,invoice_source
        ,t.total_amount,t.ele_invoice_no
        from t_dx_record_invoice t
        where t.create_date between #{cjksrq} and #{cjjsrq}
        and t.company = #{company}
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource!='99'">
            and invoice_source = #{invoiceSource}
        </if>
        <if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
            and ele_invoice_no = #{eleInvoiceNo}
        </if>
        and t.source_system = '0'
        and t.detail_yesorno = '0'
        order by t.create_date desc,t.invoice_date desc
    </select>

    <select id="selectWbfpmx" parameterType="java.util.Map"
            resultMap="WbmxResultMap" databaseId="oracle">
        select
        t.invoice_type,t.invoice_code,t.invoice_no,invoice_date,t.invoice_amount,t.tax_amount,t.gf_name,t.xf_name,t.check_code,create_date,invoice_source,
        t.total_amount,t.ele_invoice_no
        from t_dx_record_invoice t
        where t.company = #{company}
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource!='99'">
            and invoice_source = #{invoiceSource}
        </if>
        <if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
            and ele_invoice_no = #{eleInvoiceNo}
        </if>
        and t.source_system = '0'
        and t.detail_yesorno = '0'
        and t.create_date between #{cjksrq} and #{cjjsrq}
        order by t.create_date desc,t.invoice_date desc
    </select>

    <select id="selectWbfpmxHj" parameterType="java.util.Map"
            resultMap="WbmxhjResultMap" databaseId="mysql">
        select
        count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_record_invoice t
        where t.create_date between #{cjksrq} and #{cjjsrq}
        and t.company = #{company}
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource!='99'">
            and invoice_source = #{invoiceSource}
        </if>
        <if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
            and ele_invoice_no = #{eleInvoiceNo}
        </if>
        and t.source_system = '0'
        and t.detail_yesorno = '0'
    </select>

    <select id="selectWbfpmxHj" parameterType="java.util.Map"
            resultMap="WbmxhjResultMap" databaseId="oracle">
        select
        count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_record_invoice t
        where t.company = #{company}
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        and t.gf_tax_no in
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='null' and invoiceSource!='99'">
            and invoice_source = #{invoiceSource}
        </if>
        <if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
            and ele_invoice_no = #{eleInvoiceNo}
        </if>
        and t.source_system = '0'
        and t.detail_yesorno = '0'
        and to_char(t.create_date,'yyyy-mm-dd') between #{cjksrq} and #{cjjsrq}
    </select>

    <update id="updateDetailYesornoByUuid">
        update t_dx_record_invoice t
        set t.detail_yesorno = '1'
        where t.uuid = #{uuid}
    </update>

</mapper>
