<?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.ruoyi.system.mapper.VipUserMapper">
    
    <resultMap type="VipUser" id="VipUserResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="yxtim"    column="yxtim"    />
        <result property="phone"    column="phone"    />
        <result property="name"    column="name"    />
    </resultMap>

    <sql id="selectVipUserVo">
        select id, user_id, yxtim, phone, name from vip_user
    </sql>

    <select id="selectVipUserList" parameterType="VipUser" resultMap="VipUserResult">
        <include refid="selectVipUserVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="yxtim != null "> and yxtim = #{yxtim}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectVipUserById" parameterType="Long" resultMap="VipUserResult">
        <include refid="selectVipUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertVipUser" parameterType="VipUser">
        insert into vip_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="yxtim != null">yxtim,</if>
            <if test="phone != null">phone,</if>
            <if test="name != null">name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="yxtim != null">#{yxtim},</if>
            <if test="phone != null">#{phone},</if>
            <if test="name != null">#{name},</if>
         </trim>
    </insert>

    <update id="updateVipUser" parameterType="VipUser">
        update vip_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="yxtim != null">yxtim = #{yxtim},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="name != null">name = #{name},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteVipUserById" parameterType="Long">
        delete from vip_user where id = #{id}
    </delete>

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