<?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.rj.mapper.LbOrderRowMapper">

    <!-- 外部订单 id 为全局主键，按 id upsert，不受多租户拦截器影响 -->
    <insert id="upsertBatch">
        INSERT INTO lb_order_row (
            id, old_id, tenant_id, data_type,
            seller_id, seller_name, seller_phone,
            buyer_id, order_sn, total_money,
            pay_time, pay_img, status, is_resell, is_show,
            consignee, phone, province, city, area, address,
            merchandise_id, confirm_time, buy_time, created_at, updated_at,
            today_total_money_sum, today_unresell_count, today_order_count
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
                #{item.id}, #{item.oldId}, #{item.tenantId}, #{item.dataType},
                #{item.sellerId}, #{item.sellerName}, #{item.sellerPhone},
                #{item.buyerId}, #{item.orderSn}, #{item.totalMoney},
                #{item.payTime}, #{item.payImg}, #{item.status}, #{item.isResell}, #{item.isShow},
                #{item.consignee}, #{item.phone}, #{item.province}, #{item.city}, #{item.area}, #{item.address},
                #{item.merchandiseId}, #{item.confirmTime}, #{item.buyTime}, #{item.createdAt}, #{item.updatedAt},
                #{item.todayTotalMoneySum}, #{item.todayUnresellCount}, #{item.todayOrderCount}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
            old_id = VALUES(old_id),
            tenant_id = VALUES(tenant_id),
            data_type = VALUES(data_type),
            seller_id = VALUES(seller_id),
            seller_name = VALUES(seller_name),
            seller_phone = VALUES(seller_phone),
            buyer_id = VALUES(buyer_id),
            order_sn = VALUES(order_sn),
            total_money = VALUES(total_money),
            pay_time = VALUES(pay_time),
            pay_img = VALUES(pay_img),
            status = VALUES(status),
            is_resell = VALUES(is_resell),
            is_show = VALUES(is_show),
            consignee = VALUES(consignee),
            phone = VALUES(phone),
            province = VALUES(province),
            city = VALUES(city),
            area = VALUES(area),
            address = VALUES(address),
            merchandise_id = VALUES(merchandise_id),
            confirm_time = VALUES(confirm_time),
            buy_time = VALUES(buy_time),
            created_at = VALUES(created_at),
            updated_at = VALUES(updated_at),
            today_total_money_sum = VALUES(today_total_money_sum),
            today_unresell_count = VALUES(today_unresell_count),
            today_order_count = VALUES(today_order_count)
    </insert>

</mapper>
