<?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.tmerclub.cloud.order.mapper.AllotOrderItemMapper">

    <insert id="addBatchAllotOrderItem">
        INSERT INTO `allot_order_item`(`allot_order_item_id`, `allot_order_id`, `spu_id`, `sku_id`, `allot_count`, `allot_in_count`, `create_time`,
            `update_time`)
        VALUES
            <foreach collection="allotOrderItems" item="allotOrderItem" separator=",">
                (#{allotOrderItem.allotOrderItemId}, #{allotOrderItem.allotOrderId}, #{allotOrderItem.spuId}, #{allotOrderItem.skuId},
                #{allotOrderItem.allotCount}, #{allotOrderItem.allotInCount}, #{allotOrderItem.createTime}, #{allotOrderItem.updateTime})
            </foreach>
    </insert>

    <update id="updateBatchAllotOrderItem">
        <foreach collection="allotOrderItems" item="allotOrderItem">
            UPDATE
                allot_order_item
            <set>
                <if test="allotOrderItem.allotInCount != null">
                    allot_in_count = #{allotOrderItem.allotInCount},
                </if>
                <if test="allotOrderItem.updateTime != null">
                    update_time = #{allotOrderItem.updateTime}
                </if>
            </set>
            WHERE
                allot_order_id = #{allotOrderItem.allotOrderId}
                AND allot_order_item_id = #{allotOrderItem.allotOrderItemId};
        </foreach>
    </update>

    <update id="updateAllotOrderItem">
        UPDATE
            allot_order_item
        <set>
            <if test="allotOrderItem.allotInCount != null">
                allot_in_count = #{allotOrderItem.allotInCount},
            </if>
            <if test="allotOrderItem.updateTime != null">
                update_time = #{allotOrderItem.updateTime}
            </if>
        </set>
        WHERE
            allot_order_id = #{allotOrderItem.allotOrderId}
            AND allot_order_item_id = #{allotOrderItem.allotOrderItemId}
    </update>
</mapper>