<?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.FsStoreProductDetailsMapper">
    
    <resultMap type="FsStoreProductDetails" id="FsStoreProductDetailsResult">
        <result property="detailsId"    column="details_id"    />
        <result property="productId"    column="product_id"    />
        <result property="tempId"    column="temp_id"    />
        <result property="name"    column="name"    />
        <result property="code"    column="code"    />
        <result property="content"    column="content"    />
    </resultMap>

    <sql id="selectFsStoreProductDetailsVo">
        select details_id, product_id, temp_id, name, code, content from fs_store_product_details
    </sql>

    <select id="selectFsStoreProductDetailsList" parameterType="FsStoreProductDetails" resultMap="FsStoreProductDetailsResult">
        <include refid="selectFsStoreProductDetailsVo"/>
        <where>  
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="tempId != null "> and temp_id = #{tempId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
        </where>
    </select>
    
    <select id="selectFsStoreProductDetailsById" parameterType="Long" resultMap="FsStoreProductDetailsResult">
        <include refid="selectFsStoreProductDetailsVo"/>
        where details_id = #{detailsId}
    </select>
        
    <insert id="insertFsStoreProductDetails" parameterType="FsStoreProductDetails">
        insert into fs_store_product_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="detailsId != null">details_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="tempId != null">temp_id,</if>
            <if test="name != null">name,</if>
            <if test="code != null">code,</if>
            <if test="content != null">content,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="detailsId != null">#{detailsId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="tempId != null">#{tempId},</if>
            <if test="name != null">#{name},</if>
            <if test="code != null">#{code},</if>
            <if test="content != null">#{content},</if>
         </trim>
    </insert>

    <update id="updateFsStoreProductDetails" parameterType="FsStoreProductDetails">
        update fs_store_product_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="productId != null">product_id = #{productId},</if>
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="code != null">code = #{code},</if>
            <if test="content != null">content = #{content},</if>
        </trim>
        where details_id = #{detailsId}
    </update>

    <delete id="deleteFsStoreProductDetailsById" parameterType="Long">
        delete from fs_store_product_details where details_id = #{detailsId}
    </delete>

    <delete id="deleteFsStoreProductDetailsByIds" parameterType="String">
        delete from fs_store_product_details where details_id in 
        <foreach item="detailsId" collection="array" open="(" separator="," close=")">
            #{detailsId}
        </foreach>
    </delete>
    
</mapper>