<?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="cn.superdesk.uniorder.dao.mapper.invoice.customer.InvoiceApplyXGoodsMapperEx">


    <select id="proveFieldGoodsIdIsAccountingUnifiedCustomerOrderGoodsId">
        SELECT
            COUNT(1)
		FROM
		    invoice_apply_x_goods invo
			LEFT JOIN accounting_unified_customer_order_goods aucuog ON invo.unified_order_goods_id = aucuog.id AND invo.unified_order_id = aucuog.dz_order_id
		<where>
            <if test="invoiceOrderIds !=null and invoiceOrderIds.size >0 ">
                and id in
                <foreach collection="invoiceOrderIds" index="index" item="invoiceOrderId" open="(" close=")" separator=",">
                    #{invoiceOrderId}
                </foreach>
            </if>
		    aucuog.id is NOT NULL
        </where>
    </select>

    <!-- cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApplyXGoods -->
    <insert id="insertBatch" parameterType="java.util.List">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into invoice_apply_x_goods (
        invoice_apply_id,
        invoice_apply_sn,
        accounting_order_id,
        accounting_order_sn,
        accounting_order_type,
        dim_create_by,
        unified_order_id,
        order_sn,
        unified_order_goods_id,
        goods_id_source_from,
        goods_id_root_from,
        unified_order_credit_id,
        back_status,
        bank_id, back_time
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
        (
        #{item.invoiceApplyId,jdbcType=BIGINT},
        #{item.invoiceApplySn,jdbcType=VARCHAR},
        #{item.accountingOrderId,jdbcType=BIGINT},
        #{item.accountingOrderSn,jdbcType=VARCHAR},
        #{item.accountingOrderType,jdbcType=TINYINT},
        #{item.dimCreateBy,jdbcType=TINYINT},
        #{item.unifiedOrderId,jdbcType=BIGINT},
        #{item.orderSn,jdbcType=VARCHAR},
        #{item.unifiedOrderGoodsId,jdbcType=BIGINT},
        #{item.goodsIdSourceFrom,jdbcType=VARCHAR},
        #{item.goodsIdRootFrom,jdbcType=VARCHAR},
        #{item.unifiedOrderCreditId,jdbcType=BIGINT},
        #{item.backStatus,jdbcType=TINYINT},
        #{item.bankId,jdbcType=BIGINT},
        #{item.backTime,jdbcType=TIMESTAMP}
        )
        </foreach>
    </insert>

</mapper>
