<?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.fs.store.mapper.FsStoreOrderItemMapper">
    
    <resultMap type="FsStoreOrderItem" id="FsStoreOrderItemResult">
        <result property="itemId"    column="item_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="cartId"    column="cart_id"    />
        <result property="productId"    column="product_id"    />
        <result property="jsonInfo"    column="json_info"    />
        <result property="num"    column="num"    />
        <result property="isAfterSales"    column="is_after_sales"    />
        <result property="isPrescribe"    column="is_prescribe"    />
    </resultMap>

    <sql id="selectFsStoreOrderItemVo">
        select item_id, order_id, order_code, cart_id, product_id, json_info, num, is_after_sales,is_prescribe from fs_store_order_item
    </sql>

    <select id="selectFsStoreOrderItemList" parameterType="FsStoreOrderItem" resultMap="FsStoreOrderItemResult">
        <include refid="selectFsStoreOrderItemVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="cartId != null "> and cart_id = #{cartId}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="jsonInfo != null  and jsonInfo != ''"> and json_info = #{jsonInfo}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="isAfterSales != null "> and is_after_sales = #{isAfterSales}</if>
            <if test="isPrescribe != null "> and is_prescribe = #{isPrescribe}</if>
        </where>
    </select>
    
    <select id="selectFsStoreOrderItemById" parameterType="Long" resultMap="FsStoreOrderItemResult">
        <include refid="selectFsStoreOrderItemVo"/>
        where item_id = #{itemId}
    </select>
        
    <insert id="insertFsStoreOrderItem" parameterType="FsStoreOrderItem" useGeneratedKeys="true" keyProperty="itemId">
        insert into fs_store_order_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="orderCode != null">order_code,</if>
            <if test="cartId != null">cart_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="jsonInfo != null">json_info,</if>
            <if test="num != null">num,</if>
            <if test="isAfterSales != null">is_after_sales,</if>
            <if test="isPrescribe != null">is_prescribe,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="cartId != null">#{cartId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="jsonInfo != null">#{jsonInfo},</if>
            <if test="num != null">#{num},</if>
            <if test="isAfterSales != null">#{isAfterSales},</if>
            <if test="isPrescribe != null">#{isPrescribe},</if>
         </trim>
    </insert>

    <update id="updateFsStoreOrderItem" parameterType="FsStoreOrderItem">
        update fs_store_order_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="cartId != null">cart_id = #{cartId},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="jsonInfo != null">json_info = #{jsonInfo},</if>
            <if test="num != null">num = #{num},</if>
            <if test="isAfterSales != null">is_after_sales = #{isAfterSales},</if>
            <if test="isPrescribe != null">is_prescribe = #{isPrescribe},</if>
        </trim>
        where item_id = #{itemId}
    </update>

    <delete id="deleteFsStoreOrderItemById" parameterType="Long">
        delete from fs_store_order_item where item_id = #{itemId}
    </delete>

    <delete id="deleteFsStoreOrderItemByIds" parameterType="String">
        delete from fs_store_order_item where item_id in 
        <foreach item="itemId" collection="array" open="(" separator="," close=")">
            #{itemId}
        </foreach>
    </delete>
    
</mapper>