<?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.ZuserTokenMapper">

    <resultMap type="ZuserToken" id="ZuserTokenResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="token"    column="token"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectZuserTokenVo">
        select id, user_id, user_name, token, update_time from zuser_token
    </sql>

    <select id="selectZuserTokenList" parameterType="ZuserToken" resultMap="ZuserTokenResult">
        <include refid="selectZuserTokenVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
        </where>
    </select>

    <select id="selectTopZuserTokenList" parameterType="ZuserToken" resultMap="ZuserTokenResult">
        <include refid="selectZuserTokenVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
            <if test="userIds != null"> and user_id in <foreach item="userId" collection="userIds" open="(" separator="," close=")">#{userId}</foreach></if>
        </where>
        order by id desc
    </select>

    <select id="selectZuserTokenById" parameterType="Integer" resultMap="ZuserTokenResult">
        <include refid="selectZuserTokenVo"/>
        where id = #{id}
    </select>

    <select id="selectZuserTokenByUserId" parameterType="Long" resultMap="ZuserTokenResult">
        <include refid="selectZuserTokenVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertZuserToken" parameterType="ZuserToken" useGeneratedKeys="true" keyProperty="id">
        insert into zuser_token
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="token != null">token,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="token != null">#{token},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateZuserToken" parameterType="ZuserToken">
        update zuser_token
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="token != null">token = #{token},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteZuserTokenById" parameterType="Long">
        delete from zuser_token where id = #{id}
    </delete>

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