<?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.FsUserLevelMapper">
    
    <resultMap type="FsUserLevel" id="FsUserLevelResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="levelId"    column="level_id"    />
        <result property="grade"    column="grade"    />
        <result property="validTime"    column="valid_time"    />
        <result property="isForever"    column="is_forever"    />
        <result property="status"    column="status"    />
        <result property="mark"    column="mark"    />
        <result property="remind"    column="remind"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="discount"    column="discount"    />
    </resultMap>

    <sql id="selectFsUserLevelVo">
        select id, user_id, level_id, grade, valid_time, is_forever, status, mark, remind, is_del, create_time, update_time, discount from fs_user_level
    </sql>

    <select id="selectFsUserLevelList" parameterType="FsUserLevel" resultMap="FsUserLevelResult">
        <include refid="selectFsUserLevelVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="levelId != null "> and level_id = #{levelId}</if>
            <if test="grade != null "> and grade = #{grade}</if>
            <if test="validTime != null "> and valid_time = #{validTime}</if>
            <if test="isForever != null "> and is_forever = #{isForever}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="mark != null  and mark != ''"> and mark = #{mark}</if>
            <if test="remind != null "> and remind = #{remind}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="discount != null "> and discount = #{discount}</if>
        </where>
    </select>
    
    <select id="selectFsUserLevelById" parameterType="Long" resultMap="FsUserLevelResult">
        <include refid="selectFsUserLevelVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsUserLevel" parameterType="FsUserLevel" useGeneratedKeys="true" keyProperty="id">
        insert into fs_user_level
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="levelId != null">level_id,</if>
            <if test="grade != null">grade,</if>
            <if test="validTime != null">valid_time,</if>
            <if test="isForever != null">is_forever,</if>
            <if test="status != null">status,</if>
            <if test="mark != null and mark != ''">mark,</if>
            <if test="remind != null">remind,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="discount != null">discount,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="levelId != null">#{levelId},</if>
            <if test="grade != null">#{grade},</if>
            <if test="validTime != null">#{validTime},</if>
            <if test="isForever != null">#{isForever},</if>
            <if test="status != null">#{status},</if>
            <if test="mark != null and mark != ''">#{mark},</if>
            <if test="remind != null">#{remind},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="discount != null">#{discount},</if>
         </trim>
    </insert>

    <update id="updateFsUserLevel" parameterType="FsUserLevel">
        update fs_user_level
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="levelId != null">level_id = #{levelId},</if>
            <if test="grade != null">grade = #{grade},</if>
            <if test="validTime != null">valid_time = #{validTime},</if>
            <if test="isForever != null">is_forever = #{isForever},</if>
            <if test="status != null">status = #{status},</if>
            <if test="mark != null and mark != ''">mark = #{mark},</if>
            <if test="remind != null">remind = #{remind},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="discount != null">discount = #{discount},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsUserLevelById" parameterType="Long">
        delete from fs_user_level where id = #{id}
    </delete>

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