<?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.core.dao.InvoiceDownDao">

    <select id="getNoParse" resultType="java.lang.String">
        select taxno
        from t_dx_http_log_invoice_down
        where status = '0'
          and type = '1'
        group by taxno
    </select>

    <select id="getNotParseHttpLogs" resultType="com.dxhy.core.job.entity.TDxHttpLogInvoiceDown">
        select *
        from t_dx_http_log_invoice_down
        where status = '0'
          and type = '1'
          and taxno = #{taxno}
    </select>

    <update id="updateNotParseHttpLogsStatus">
        update t_dx_http_log_invoice_down set status='3'
        where log_id in
        <foreach collection="logs" index="index" item="item" open="(" separator="," close=")">
            #{item.logId}
        </foreach>
    </update>

    <update id="updateHttoLogById" parameterType="com.dxhy.core.job.entity.TDxHttpLogInvoiceDown">
        update t_dx_http_log_invoice_down
        set status = #{status},
            total  =#{total}
        where log_id = #{logId}
    </update>

    <delete id="delDetailIncome" parameterType="java.lang.String">
        delete
        from t_dx_record_invoice_detail
        where uuid = #{uuid}
    </delete>


    <insert id="insertDetailIncome" parameterType="com.dxhy.core.job.pojo.down.RecordInvoiceDetailModel">
        insert into t_dx_record_invoice_detail (invoice_code,
                                                invoice_no,
                                                goods_name,
                                                model,
                                                unit,
                                                num,
                                                unit_price,
                                                detail_amount,
                                                tax_rate,
                                                tax_amount,
                                                goods_num,
                                                uuid)
        values (#{entity.invoiceCode},
                #{entity.invoiceNo},
                #{entity.goodsName},
                #{entity.model},
                #{entity.unit},
                #{entity.num},
                #{entity.unitPrice},
                #{entity.detailAmount},
                #{entity.taxRate},
                #{entity.taxAmount},
                #{entity.goodsNum},
                #{entity.uuid})
    </insert>


    <delete id="delDetailSales" parameterType="java.lang.String">
        delete
        from t_dx_record_invoice_detail_sales
        where uuid = #{uuid}
    </delete>


    <insert id="insertDetailSales" parameterType="com.dxhy.core.job.pojo.down.RecordInvoiceDetailModel">
        insert into t_dx_record_invoice_detail_sales (invoice_code,
                                                      invoice_no,
                                                      goods_name,
                                                      model,
                                                      unit,
                                                      num,
                                                      unit_price,
                                                      detail_amount,
                                                      tax_rate,
                                                      tax_amount,
                                                      goods_num,
                                                      uuid)
        values (#{entity.invoiceCode},
                #{entity.invoiceNo},
                #{entity.goodsName},
                #{entity.model},
                #{entity.unit},
                #{entity.num},
                #{entity.unitPrice},
                #{entity.detailAmount},
                #{entity.taxRate},
                #{entity.taxAmount},
                #{entity.goodsNum},
                #{entity.uuid})
    </insert>


    <select id="getDetailCount" resultType="int">
        select count(1)
        from ${detail}
        where uuid = #{uuid}
    </select>


    <update id="updateRecordInvoice" parameterType="com.dxhy.core.job.pojo.down.RecordInvoiceDownModel">
        update t_dx_record_invoice
        <set>
            <if test="invoiceCode != null and invoiceCode != ''">invoice_code=#{invoiceCode},</if>
            <if test="invoiceNo != null and invoiceNo != ''">invoice_no=#{invoiceNo},</if>
            <if test="invoiceType != null and invoiceType != ''">invoice_type=#{invoiceType},</if>
            <if test="buyerName != null and buyerName != ''">gf_name=#{buyerName},</if>
            <if test="buyerTaxNo != null and buyerTaxNo != ''">gf_tax_no=#{buyerTaxNo},</if>
            <if test="buyerAddressPhone != null and buyerAddressPhone != ''">
                gf_address_and_phone=#{buyerAddressPhone},
            </if>
            <if test="buyerAcount != null and buyerAcount != ''">gf_bank_and_no=#{buyerAcount},</if>
            <if test="salerName != null and salerName != ''">xf_name=#{salerName},</if>
            <if test="salerTaxNo != null and salerTaxNo != ''">xf_tax_no=#{salerTaxNo},</if>
            <if test="salerAddressPhone != null and salerAddressPhone != ''">
                xf_address_and_phone=#{salerAddressPhone},
            </if>
            <if test="salerAcount != null and salerAcount != ''">xf_bank_and_no=#{salerAcount},</if>
            <if test="invoiceDate != null">invoice_date=#{invoiceDate,jdbcType=TIMESTAMP},</if>
            <if test="invoiceAmount != null and invoiceAmount != ''">invoice_amount=#{invoiceAmount},</if>
            <if test="taxAmount != null and taxAmount != ''">tax_amount=#{taxAmount},</if>
            <if test="totalAmount != null and totalAmount != ''">total_amount=#{totalAmount},</if>
            <if test="remark != null and remark != ''">remark=#{remark},</if>
            <if test="invoiceStatus != null and invoiceStatus != ''">invoice_status=#{invoiceStatus},</if>
            <if test="checkCode != null and checkCode != ''">check_code=#{checkCode},</if>
            <!--            <if test="authStatus != null and authStatus != ''" >auth_status=#{authStatus},</if>
                        <if test="bdkStatus != null and bdkStatus != ''" >bdk_status=#{bdkStatus},</if>
                        <if test="bdkDate != null" >bdk_date=#{bdkDate,jdbcType=TIMESTAMP},</if>
                        <if test="bdkCurrentPeriod != null" >bdk_current_period=#{bdkCurrentPeriod,jdbcType=TIMESTAMP},</if>  -->
            <if test="uuid != null and uuid != ''">uuid=#{uuid},</if>
            <if test="statusUpdateDate != null">status_update_date=#{statusUpdateDate},</if>
            <if test="detailYesorno != null and detailYesorno != ''">detail_yesorno=#{detailYesorno},</if>
            <!--            <if test="statusUpdateDate != null" >status_update_date=#{statusUpdateDate,jdbcType=TIMESTAMP},</if>  -->
            <if test="collectStatus !=null and collectStatus!=''">
                collect_status=#{collectStatus},
                collect_from=#{collectFrom},
                collect_date=#{collectDate},
                pool_status=#{poolStatus},
                in_pool_reason=#{inPoolReason},
            </if>
        </set>
        where invoice_code = #{invoiceCode} and invoice_no = #{invoiceNo}
    </update>


    <update id="updateSaleRecordInvoice" parameterType="com.dxhy.core.job.pojo.down.RecordInvoiceDownModel">
        update t_dx_sale_record_invoice
        <set>
            <if test="invoiceCode != null and invoiceCode != ''">invoice_code=#{invoiceCode},</if>
            <if test="invoiceNo != null and invoiceNo != ''">invoice_no=#{invoiceNo},</if>
            <if test="invoiceType != null and invoiceType != ''">invoice_type=#{invoiceType},</if>
            <if test="buyerName != null and buyerName != ''">gf_name=#{buyerName},</if>
            <if test="buyerTaxNo != null and buyerTaxNo != ''">gf_tax_no=#{buyerTaxNo},</if>
            <if test="buyerAddressPhone != null and buyerAddressPhone != ''">
                gf_address_and_phone=#{buyerAddressPhone},
            </if>
            <if test="buyerAcount != null and buyerAcount != ''">gf_bank_and_no=#{buyerAcount},</if>
            <if test="salerName != null and salerName != ''">xf_name=#{salerName},</if>
            <if test="salerTaxNo != null and salerTaxNo != ''">xf_tax_no=#{salerTaxNo},</if>
            <if test="salerAddressPhone != null and salerAddressPhone != ''">
                xf_address_and_phone=#{salerAddressPhone},
            </if>
            <if test="salerAcount != null and salerAcount != ''">xf_bank_and_no=#{salerAcount},</if>
            <if test="invoiceDate != null">invoice_date=#{invoiceDate,jdbcType=TIMESTAMP},</if>
            <if test="invoiceAmount != null and invoiceAmount != ''">invoice_amount=#{invoiceAmount},</if>
            <if test="taxAmount != null and taxAmount != ''">tax_amount=#{taxAmount},</if>
            <if test="totalAmount != null and totalAmount != ''">total_amount=#{totalAmount},</if>
            <if test="remark != null and remark != ''">remark=#{remark},</if>
            <if test="invoiceStatus != null and invoiceStatus != ''">invoice_status=#{invoiceStatus},</if>
            <if test="checkCode != null and checkCode != ''">check_code=#{checkCode},</if>
            <!--            <if test="authStatus != null and authStatus != ''" >auth_status=#{authStatus},</if>
                        <if test="bdkStatus != null and bdkStatus != ''" >bdk_status=#{bdkStatus},</if>
                        <if test="bdkDate != null" >bdk_date=#{bdkDate,jdbcType=TIMESTAMP},</if>
                        <if test="bdkCurrentPeriod != null" >bdk_current_period=#{bdkCurrentPeriod,jdbcType=TIMESTAMP},</if>  -->
            <if test="uuid != null and uuid != ''">uuid=#{uuid},</if>
            <if test="statusUpdateDate != null ">status_update_date=#{statusUpdateDate},</if>
            <if test="detailYesorno != null and detailYesorno != ''">detail_yesorno=#{detailYesorno},</if>
            <!--            <if test="statusUpdateDate != null" >status_update_date=#{statusUpdateDate,jdbcType=TIMESTAMP},</if>  -->
            <if test="collectStatus !=null and collectStatus!=''">
                collect_status=#{collectStatus},
                collect_from=#{collectFrom},
                collect_date=#{collectDate},
                pool_status=#{poolStatus},
                in_pool_reason=#{inPoolReason},
            </if>
        </set>
        where invoice_code = #{invoiceCode} and invoice_no = #{invoiceNo}
    </update>


    <update id="updateHttpLogById" parameterType="com.dxhy.core.job.entity.TDxHttpLogInvoiceDown">
        update t_dx_http_log_invoice_down
        set status = #{status},
            total  =#{total}
        where log_id = #{logId}
    </update>


    <select id="findCustoms" resultType="int">
        select count(1)
        from t_dx_customs_sale
        where customs_code = #{customsCode}
          and fill_in_date = #{fillDate}
    </select>
</mapper>
