<?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.FsStoreProductTemplateMapper">
    
    <resultMap type="FsStoreProductTemplate" id="FsStoreProductTemplateResult">
        <result property="tempId"    column="temp_id"    />
        <result property="name"    column="name"    />
        <result property="code"    column="code"    />
        <result property="status"    column="status"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectFsStoreProductTemplateVo">
        select temp_id, name, code, status, sort from fs_store_product_template
    </sql>

    <select id="selectFsStoreProductTemplateList" parameterType="FsStoreProductTemplate" resultMap="FsStoreProductTemplateResult">
        <include refid="selectFsStoreProductTemplateVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
    </select>
    
    <select id="selectFsStoreProductTemplateById" parameterType="Long" resultMap="FsStoreProductTemplateResult">
        <include refid="selectFsStoreProductTemplateVo"/>
        where temp_id = #{tempId}
    </select>
        
    <insert id="insertFsStoreProductTemplate" parameterType="FsStoreProductTemplate" useGeneratedKeys="true" keyProperty="tempId">
        insert into fs_store_product_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="code != null">code,</if>
            <if test="status != null">status,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="code != null">#{code},</if>
            <if test="status != null">#{status},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateFsStoreProductTemplate" parameterType="FsStoreProductTemplate">
        update fs_store_product_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="code != null">code = #{code},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where temp_id = #{tempId}
    </update>

    <delete id="deleteFsStoreProductTemplateById" parameterType="Long">
        delete from fs_store_product_template where temp_id = #{tempId}
    </delete>

    <delete id="deleteFsStoreProductTemplateByIds" parameterType="String">
        delete from fs_store_product_template where temp_id in 
        <foreach item="tempId" collection="array" open="(" separator="," close=")">
            #{tempId}
        </foreach>
    </delete>
    
</mapper>