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

    <resultMap type="FsStoreProduct" id="FsStoreProductResult">
        <result property="productId"    column="product_id"    />
        <result property="image"    column="image"    />
        <result property="sliderImage"    column="slider_image"    />
        <result property="productName"    column="product_name"    />
        <result property="productInfo"    column="product_info"    />
        <result property="keyword"    column="keyword"    />
        <result property="barCode"    column="bar_code"    />
        <result property="cateId"    column="cate_id"    />
        <result property="price"    column="price"    />
        <result property="vipPrice"    column="vip_price"    />
        <result property="otPrice"    column="ot_price"    />
        <result property="postage"    column="postage"    />
        <result property="unitName"    column="unit_name"    />
        <result property="sort"    column="sort"    />
        <result property="sales"    column="sales"    />
        <result property="stock"    column="stock"    />
        <result property="isShow"    column="is_show"    />
        <result property="isHot"    column="is_hot"    />
        <result property="isBenefit"    column="is_benefit"    />
        <result property="isBest"    column="is_best"    />
        <result property="isNew"    column="is_new"    />
        <result property="description"    column="description"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isPostage"    column="is_postage"    />
        <result property="isDel"    column="is_del"    />
        <result property="giveIntegral"    column="give_integral"    />
        <result property="cost"    column="cost"    />
        <result property="isGood"    column="is_good"    />
        <result property="browse"    column="browse"    />
        <result property="codePath"    column="code_path"    />
        <result property="tempId"    column="temp_id"    />
        <result property="specType"    column="spec_type"    />
        <result property="isIntegral"    column="is_integral"    />
        <result property="integral"    column="integral"    />
        <result property="productType"    column="product_type"    />
        <result property="prescribeCode"    column="prescribe_code"    />
        <result property="prescribeSpec"    column="prescribe_spec"    />
        <result property="prescribeFactory"    column="prescribe_factory"    />
        <result property="prescribeName"    column="prescribe_name"    />
        <result property="isDisplay"    column="is_display"    />
        <result property="tuiCateId"    column="tui_cate_id"    />
    </resultMap>

    <sql id="selectFsStoreProductVo">
        select product_id, image, slider_image, product_name, product_info, keyword, bar_code, cate_id, price, vip_price, ot_price, postage, unit_name, sort, sales, stock, is_show, is_hot, is_benefit, is_best, is_new, description, create_time, update_time, is_postage, is_del, give_integral, cost, is_good, browse, code_path, temp_id, spec_type, is_integral, integral, product_type, prescribe_code, prescribe_spec, prescribe_factory, prescribe_name,is_display,tui_cate_id,warehouse_id,warehouse_code from fs_store_product
    </sql>

    <select id="selectFsStoreProductList" parameterType="FsStoreProduct" resultMap="FsStoreProductResult">
        <include refid="selectFsStoreProductVo"/>
        <where>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="sliderImage != null  and sliderImage != ''"> and slider_image = #{sliderImage}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="productInfo != null  and productInfo != ''"> and product_info = #{productInfo}</if>
            <if test="keyword != null  and keyword != ''"> and keyword = #{keyword}</if>
            <if test="barCode != null  and barCode != ''"> and bar_code = #{barCode}</if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="vipPrice != null "> and vip_price = #{vipPrice}</if>
            <if test="otPrice != null "> and ot_price = #{otPrice}</if>
            <if test="postage != null "> and postage = #{postage}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="sales != null "> and sales = #{sales}</if>
            <if test="stock != null "> and stock = #{stock}</if>
            <if test="isShow != null "> and is_show = #{isShow}</if>
            <if test="isHot != null "> and is_hot = #{isHot}</if>
            <if test="isBenefit != null "> and is_benefit = #{isBenefit}</if>
            <if test="isBest != null "> and is_best = #{isBest}</if>
            <if test="isNew != null "> and is_new = #{isNew}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="isPostage != null "> and is_postage = #{isPostage}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="giveIntegral != null "> and give_integral = #{giveIntegral}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="isGood != null "> and is_good = #{isGood}</if>
            <if test="browse != null "> and browse = #{browse}</if>
            <if test="codePath != null  and codePath != ''"> and code_path = #{codePath}</if>
            <if test="tempId != null "> and temp_id = #{tempId}</if>
            <if test="specType != null "> and spec_type = #{specType}</if>
            <if test="isIntegral != null "> and is_integral = #{isIntegral}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="productType != null "> and product_type = #{productType}</if>
            <if test="prescribeCode != null  and prescribeCode != ''"> and prescribe_code = #{prescribeCode}</if>
            <if test="prescribeSpec != null  and prescribeSpec != ''"> and prescribe_spec = #{prescribeSpec}</if>
            <if test="prescribeFactory != null  and prescribeFactory != ''"> and prescribe_factory = #{prescribeFactory}</if>
            <if test="prescribeName != null  and prescribeName != ''"> and prescribe_name like concat('%', #{prescribeName}, '%')</if>
            <if test="isDisplay != null "> and is_display = #{isDisplay}</if>
            <if test="warehouseId != null"> and warehouse_id = #{warehouseId}</if>
            <if test="warehouseCode != null"> and warehouse_code = #{warehouseCode}</if>
        </where>
    </select>

    <select id="selectFsStoreProductById" parameterType="Long" resultMap="FsStoreProductResult">
        <include refid="selectFsStoreProductVo"/>
        where product_id = #{productId}
    </select>

    <insert id="insertFsStoreProduct" parameterType="FsStoreProduct" useGeneratedKeys="true" keyProperty="productId">
        insert into fs_store_product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="image != null and image != ''">image,</if>
            <if test="sliderImage != null and sliderImage != ''">slider_image,</if>
            <if test="productName != null and productName != ''">product_name,</if>
            <if test="productInfo != null and productInfo != ''">product_info,</if>
            <if test="keyword != null and keyword != ''">keyword,</if>
            <if test="barCode != null">bar_code,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="price != null">price,</if>
            <if test="vipPrice != null">vip_price,</if>
            <if test="otPrice != null">ot_price,</if>
            <if test="postage != null">postage,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="sort != null">sort,</if>
            <if test="sales != null">sales,</if>
            <if test="stock != null">stock,</if>
            <if test="isShow != null">is_show,</if>
            <if test="isHot != null">is_hot,</if>
            <if test="isBenefit != null">is_benefit,</if>
            <if test="isBest != null">is_best,</if>
            <if test="isNew != null">is_new,</if>
            <if test="description != null">description,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isPostage != null">is_postage,</if>
            <if test="isDel != null">is_del,</if>
            <if test="giveIntegral != null">give_integral,</if>
            <if test="cost != null">cost,</if>
            <if test="isGood != null">is_good,</if>
            <if test="browse != null">browse,</if>
            <if test="codePath != null and codePath != ''">code_path,</if>
            <if test="tempId != null">temp_id,</if>
            <if test="specType != null">spec_type,</if>
            <if test="isIntegral != null">is_integral,</if>
            <if test="integral != null">integral,</if>
            <if test="productType != null">product_type,</if>
            <if test="prescribeCode != null">prescribe_code,</if>
            <if test="prescribeSpec != null">prescribe_spec,</if>
            <if test="prescribeFactory != null">prescribe_factory,</if>
            <if test="prescribeName != null">prescribe_name,</if>
            <if test="isDisplay != null">is_display,</if>
            <if test="tuiCateId != null">tui_cate_id,</if>
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="warehouseCode != null">warehouse_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="image != null and image != ''">#{image},</if>
            <if test="sliderImage != null and sliderImage != ''">#{sliderImage},</if>
            <if test="productName != null and productName != ''">#{productName},</if>
            <if test="productInfo != null and productInfo != ''">#{productInfo},</if>
            <if test="keyword != null and keyword != ''">#{keyword},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="price != null">#{price},</if>
            <if test="vipPrice != null">#{vipPrice},</if>
            <if test="otPrice != null">#{otPrice},</if>
            <if test="postage != null">#{postage},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="sort != null">#{sort},</if>
            <if test="sales != null">#{sales},</if>
            <if test="stock != null">#{stock},</if>
            <if test="isShow != null">#{isShow},</if>
            <if test="isHot != null">#{isHot},</if>
            <if test="isBenefit != null">#{isBenefit},</if>
            <if test="isBest != null">#{isBest},</if>
            <if test="isNew != null">#{isNew},</if>
            <if test="description != null">#{description},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isPostage != null">#{isPostage},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="giveIntegral != null">#{giveIntegral},</if>
            <if test="cost != null">#{cost},</if>
            <if test="isGood != null">#{isGood},</if>
            <if test="browse != null">#{browse},</if>
            <if test="codePath != null and codePath != ''">#{codePath},</if>
            <if test="tempId != null">#{tempId},</if>
            <if test="specType != null">#{specType},</if>
            <if test="isIntegral != null">#{isIntegral},</if>
            <if test="integral != null">#{integral},</if>
            <if test="productType != null">#{productType},</if>
            <if test="prescribeCode != null">#{prescribeCode},</if>
            <if test="prescribeSpec != null">#{prescribeSpec},</if>
            <if test="prescribeFactory != null">#{prescribeFactory},</if>
            <if test="prescribeName != null">#{prescribeName},</if>
            <if test="isDisplay != null">#{isDisplay},</if>
            <if test="tuiCateId != null">#{tuiCateId},</if>
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="warehouseCode != null">#{warehouseCode},</if>
         </trim>
    </insert>

    <update id="updateFsStoreProduct" parameterType="FsStoreProduct">
        update fs_store_product
        <trim prefix="SET" suffixOverrides=",">
            <if test="image != null and image != ''">image = #{image},</if>
            <if test="sliderImage != null and sliderImage != ''">slider_image = #{sliderImage},</if>
            <if test="productName != null and productName != ''">product_name = #{productName},</if>
            <if test="productInfo != null and productInfo != ''">product_info = #{productInfo},</if>
            <if test="keyword != null and keyword != ''">keyword = #{keyword},</if>
            <if test="barCode != null">bar_code = #{barCode},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="price != null">price = #{price},</if>
            <if test="vipPrice != null">vip_price = #{vipPrice},</if>
            <if test="otPrice != null">ot_price = #{otPrice},</if>
            <if test="postage != null">postage = #{postage},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="sales != null">sales = #{sales},</if>
            <if test="stock != null">stock = #{stock},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
            <if test="isHot != null">is_hot = #{isHot},</if>
            <if test="isBenefit != null">is_benefit = #{isBenefit},</if>
            <if test="isBest != null">is_best = #{isBest},</if>
            <if test="isNew != null">is_new = #{isNew},</if>
            <if test="description != null">description = #{description},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isPostage != null">is_postage = #{isPostage},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="giveIntegral != null">give_integral = #{giveIntegral},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="isGood != null">is_good = #{isGood},</if>
            <if test="browse != null">browse = #{browse},</if>
            <if test="codePath != null and codePath != ''">code_path = #{codePath},</if>
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="specType != null">spec_type = #{specType},</if>
            <if test="isIntegral != null">is_integral = #{isIntegral},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="productType != null">product_type = #{productType},</if>
            <if test="prescribeCode != null">prescribe_code = #{prescribeCode},</if>
            <if test="prescribeSpec != null">prescribe_spec = #{prescribeSpec},</if>
            <if test="prescribeFactory != null">prescribe_factory = #{prescribeFactory},</if>
            <if test="prescribeName != null">prescribe_name = #{prescribeName},</if>
            <if test="isDisplay != null">is_display = #{isDisplay},</if>
            <if test="tuiCateId != null">tui_cate_id = #{tuiCateId},</if>
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
            <if test="warehouseCode != null">warehouse_code = #{warehouseCode},</if>
        </trim>
        where product_id = #{productId}
    </update>

    <delete id="deleteFsStoreProductById" parameterType="Long">
        delete from fs_store_product where product_id = #{productId}
    </delete>

    <delete id="deleteFsStoreProductByIds" parameterType="String">
        delete from fs_store_product where product_id in
        <foreach item="productId" collection="array" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </delete>
    <select id="selectFsStoreProductByProductIds" resultType="com.fs.store.domain.FsStoreProduct">
        select * from fs_store_product where product_id in
           <foreach item="productId" collection="productIds" open="(" separator="," close=")">
               #{productId}
           </foreach>
    </select>
    <select id="selectWarehouseCodeByProductIds" resultType="com.fs.store.domain.FsStoreProduct">
        select product_id,warehouse_code from fs_store_product where product_id in
        <foreach item="productId" collection="productIds" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </select>

</mapper>
