<?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.FsStoreOrderOfflineItemMapper">

    <resultMap type="FsStoreOrderOfflineItem" id="FsStoreOrderOfflineItemResult">
        <result property="itemId"    column="item_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="productId"    column="product_id"    />
        <result property="jsonInfo"    column="json_info"    />
        <result property="num"    column="num"    />
    </resultMap>

    <sql id="selectFsStoreOrderOfflineItemVo">
        select item_id, order_id, order_code, product_id, json_info, num from fs_store_order_offline_item
    </sql>

    <select id="selectFsStoreOrderOfflineItemList" parameterType="FsStoreOrderOfflineItem" resultMap="FsStoreOrderOfflineItemResult">
        <include refid="selectFsStoreOrderOfflineItemVo"/>
        <where>
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="productId != null  and productId != ''"> and product_id = #{productId}</if>
            <if test="jsonInfo != null  and jsonInfo != ''"> and json_info = #{jsonInfo}</if>
            <if test="num != null "> and num = #{num}</if>
        </where>
    </select>

    <select id="selectFsStoreOrderOfflineItemById" parameterType="Long" resultMap="FsStoreOrderOfflineItemResult">
        <include refid="selectFsStoreOrderOfflineItemVo"/>
        where item_id = #{itemId}
    </select>

    <insert id="insertFsStoreOrderOfflineItem" parameterType="FsStoreOrderOfflineItem" useGeneratedKeys="true" keyProperty="itemId">
        insert into fs_store_order_offline_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="orderCode != null">order_code,</if>
            <if test="productId != null">product_id,</if>
            <if test="jsonInfo != null">json_info,</if>
            <if test="num != null">num,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="productId != null">#{productId},</if>
            <if test="jsonInfo != null">#{jsonInfo},</if>
            <if test="num != null">#{num},</if>
         </trim>
    </insert>

    <update id="updateFsStoreOrderOfflineItem" parameterType="FsStoreOrderOfflineItem">
        update fs_store_order_offline_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="jsonInfo != null">json_info = #{jsonInfo},</if>
            <if test="num != null">num = #{num},</if>
        </trim>
        where item_id = #{itemId}
    </update>

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

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

</mapper>
