<?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.FsUserTuiMoneyRankMapper">
    
    <resultMap type="FsUserTuiMoneyRank" id="FsUserTuiMoneyRankResult">
        <result property="id"    column="id"    />
        <result property="sort"    column="sort"    />
        <result property="type"    column="type"    />
        <result property="userId"    column="user_id"    />
        <result property="nickname"    column="nickname"    />
        <result property="phone"    column="phone"    />
        <result property="tuiMoney"    column="tui_money"    />
        <result property="avatar"    column="avatar"    />
    </resultMap>

    <sql id="selectFsUserTuiMoneyRankVo">
        select id, sort, type, user_id, nickname, phone, tui_money, avatar from fs_user_tui_money_rank
    </sql>

    <select id="selectFsUserTuiMoneyRankList" parameterType="FsUserTuiMoneyRank" resultMap="FsUserTuiMoneyRankResult">
        <include refid="selectFsUserTuiMoneyRankVo"/>
        <where>  
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="nickname != null  and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="tuiMoney != null "> and tui_money = #{tuiMoney}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
        </where>
    </select>
    
    <select id="selectFsUserTuiMoneyRankById" parameterType="Long" resultMap="FsUserTuiMoneyRankResult">
        <include refid="selectFsUserTuiMoneyRankVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsUserTuiMoneyRank" parameterType="FsUserTuiMoneyRank" useGeneratedKeys="true" keyProperty="id">
        insert into fs_user_tui_money_rank
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sort != null">sort,</if>
            <if test="type != null">type,</if>
            <if test="userId != null">user_id,</if>
            <if test="nickname != null">nickname,</if>
            <if test="phone != null">phone,</if>
            <if test="tuiMoney != null">tui_money,</if>
            <if test="avatar != null">avatar,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sort != null">#{sort},</if>
            <if test="type != null">#{type},</if>
            <if test="userId != null">#{userId},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="phone != null">#{phone},</if>
            <if test="tuiMoney != null">#{tuiMoney},</if>
            <if test="avatar != null">#{avatar},</if>
         </trim>
    </insert>

    <update id="updateFsUserTuiMoneyRank" parameterType="FsUserTuiMoneyRank">
        update fs_user_tui_money_rank
        <trim prefix="SET" suffixOverrides=",">
            <if test="sort != null">sort = #{sort},</if>
            <if test="type != null">type = #{type},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="nickname != null">nickname = #{nickname},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="tuiMoney != null">tui_money = #{tuiMoney},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsUserTuiMoneyRankById" parameterType="Long">
        delete from fs_user_tui_money_rank where id = #{id}
    </delete>

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