<?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.FsLevelMapper">
    
    <resultMap type="FsLevel" id="FsLevelResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="money"    column="money"    />
        <result property="validDate"    column="valid_date"    />
        <result property="isForever"    column="is_forever"    />
        <result property="isPay"    column="is_pay"    />
        <result property="isShow"    column="is_show"    />
        <result property="grade"    column="grade"    />
        <result property="discount"    column="discount"    />
        <result property="image"    column="image"    />
        <result property="icon"    column="icon"    />
        <result property="explain"    column="explain"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsLevelVo">
        select id, name, money, valid_date, is_forever, is_pay, is_show, grade, discount, image, icon, explain, create_time, update_time, is_del from fs_level
    </sql>

    <select id="selectFsLevelList" parameterType="FsLevel" resultMap="FsLevelResult">
        <include refid="selectFsLevelVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="money != null "> and money = #{money}</if>
            <if test="validDate != null "> and valid_date = #{validDate}</if>
            <if test="isForever != null "> and is_forever = #{isForever}</if>
            <if test="isPay != null "> and is_pay = #{isPay}</if>
            <if test="isShow != null "> and is_show = #{isShow}</if>
            <if test="grade != null "> and grade = #{grade}</if>
            <if test="discount != null "> and discount = #{discount}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="icon != null  and icon != ''"> and icon = #{icon}</if>
            <if test="explain != null  and explain != ''"> and explain = #{explain}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectFsLevelById" parameterType="Long" resultMap="FsLevelResult">
        <include refid="selectFsLevelVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsLevel" parameterType="FsLevel" useGeneratedKeys="true" keyProperty="id">
        insert into fs_level
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="money != null">money,</if>
            <if test="validDate != null">valid_date,</if>
            <if test="isForever != null">is_forever,</if>
            <if test="isPay != null">is_pay,</if>
            <if test="isShow != null">is_show,</if>
            <if test="grade != null">grade,</if>
            <if test="discount != null">discount,</if>
            <if test="image != null and image != ''">image,</if>
            <if test="icon != null and icon != ''">icon,</if>
            <if test="explain != null and explain != ''">explain,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="money != null">#{money},</if>
            <if test="validDate != null">#{validDate},</if>
            <if test="isForever != null">#{isForever},</if>
            <if test="isPay != null">#{isPay},</if>
            <if test="isShow != null">#{isShow},</if>
            <if test="grade != null">#{grade},</if>
            <if test="discount != null">#{discount},</if>
            <if test="image != null and image != ''">#{image},</if>
            <if test="icon != null and icon != ''">#{icon},</if>
            <if test="explain != null and explain != ''">#{explain},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsLevel" parameterType="FsLevel">
        update fs_level
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="money != null">money = #{money},</if>
            <if test="validDate != null">valid_date = #{validDate},</if>
            <if test="isForever != null">is_forever = #{isForever},</if>
            <if test="isPay != null">is_pay = #{isPay},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
            <if test="grade != null">grade = #{grade},</if>
            <if test="discount != null">discount = #{discount},</if>
            <if test="image != null and image != ''">image = #{image},</if>
            <if test="icon != null and icon != ''">icon = #{icon},</if>
            <if test="explain != null and explain != ''">explain = #{explain},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsLevelById" parameterType="Long">
        delete from fs_level where id = #{id}
    </delete>

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