<?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.ruoyi.web.modules.order.mapper.BizOrderItemMapper">

    <resultMap id="BizOrderItemResult" type="com.ruoyi.web.modules.order.domain.BizOrderItem">
        <id property="itemId" column="item_id"/>
        <result property="orderId" column="order_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="goodsSpec" column="goods_spec"/>
        <result property="goodsImage" column="goods_image"/>
        <result property="unitPrice" column="unit_price"/>
        <result property="quantity" column="quantity"/>
        <result property="lineAmount" column="line_amount"/>
        <result property="sortNo" column="sort_no"/>
        <result property="buyerRemark" column="buyer_remark"/>
        <result property="serviceDesc" column="service_desc"/>
        <result property="cartItemId" column="cart_item_id"/>
        <result property="specKey" column="spec_key"/>
    </resultMap>

    <select id="selectByOrderId" resultMap="BizOrderItemResult">
        select item_id, order_id, goods_id, goods_name, goods_spec, goods_image,
               unit_price, quantity, line_amount, sort_no,
               buyer_remark, service_desc, cart_item_id, spec_key
        from biz_order_item
        where order_id = #{orderId}
        order by sort_no asc, item_id asc
    </select>

    <select id="selectByOrderIds" resultMap="BizOrderItemResult">
        select item_id, order_id, goods_id, goods_name, goods_spec, goods_image,
               unit_price, quantity, line_amount, sort_no,
               buyer_remark, service_desc, cart_item_id, spec_key
        from biz_order_item
        where order_id in
        <foreach collection="orderIds" item="orderId" open="(" separator="," close=")">
            #{orderId}
        </foreach>
        order by order_id asc, sort_no asc, item_id asc
    </select>

    <insert id="batchInsert">
        insert into biz_order_item (
            order_id, goods_id, goods_name, goods_spec, goods_image,
            unit_price, quantity, line_amount, sort_no,
            buyer_remark, service_desc, cart_item_id, spec_key
        ) values
        <foreach collection="items" item="item" separator=",">
            (
                #{item.orderId}, #{item.goodsId}, #{item.goodsName}, #{item.goodsSpec}, #{item.goodsImage},
                #{item.unitPrice}, #{item.quantity}, #{item.lineAmount}, #{item.sortNo},
                #{item.buyerRemark}, #{item.serviceDesc}, #{item.cartItemId}, #{item.specKey}
            )
        </foreach>
    </insert>
</mapper>
