<?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.FsWechatTemplateMapper">
    
    <resultMap type="FsWechatTemplate" id="FsWechatTemplateResult">
        <result property="id"    column="id"    />
        <result property="tempkey"    column="tempkey"    />
        <result property="name"    column="name"    />
        <result property="content"    column="content"    />
        <result property="tempId"    column="temp_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
        <result property="isDel"    column="is_del"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectFsWechatTemplateVo">
        select id, tempkey, name, content, temp_id, create_time, update_time, status, is_del, type from fs_wechat_template
    </sql>

    <select id="selectFsWechatTemplateList" parameterType="FsWechatTemplate" resultMap="FsWechatTemplateResult">
        <include refid="selectFsWechatTemplateVo"/>
        <where>  
            <if test="tempkey != null  and tempkey != ''"> and tempkey = #{tempkey}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="tempId != null  and tempId != ''"> and temp_id = #{tempId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>
    
    <select id="selectFsWechatTemplateById" parameterType="Integer" resultMap="FsWechatTemplateResult">
        <include refid="selectFsWechatTemplateVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsWechatTemplate" parameterType="FsWechatTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into fs_wechat_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tempkey != null and tempkey != ''">tempkey,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="tempId != null">temp_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="type != null">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tempkey != null and tempkey != ''">#{tempkey},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="tempId != null">#{tempId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="type != null">#{type},</if>
         </trim>
    </insert>

    <update id="updateFsWechatTemplate" parameterType="FsWechatTemplate">
        update fs_wechat_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="tempkey != null and tempkey != ''">tempkey = #{tempkey},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsWechatTemplateById" parameterType="Integer">
        delete from fs_wechat_template where id = #{id}
    </delete>

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