<?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="vip.xiaonuo.exam.mapper.UserTokenMapper">
  <resultMap id="BaseResultMap" type="vip.xiaonuo.exam.domain.UserToken">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="token" jdbcType="VARCHAR" property="token" />
    <result column="user_id" jdbcType="INTEGER" property="userId" />
    <result column="wx_open_id" jdbcType="VARCHAR" property="wxOpenId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="user_name" jdbcType="VARCHAR" property="userName" />
  </resultMap>
  <sql id="Base_Column_List">
    id, token, user_id, wx_open_id, create_time, end_time, user_name
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user_token
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_user_token
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="vip.xiaonuo.exam.domain.UserToken" useGeneratedKeys="true" keyProperty="id">
    insert into t_user_token (id, token, user_id,
      wx_open_id, create_time, end_time,
      user_name)
    values (#{id,jdbcType=INTEGER}, #{token,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER},
      #{wxOpenId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP},
      #{userName,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="vip.xiaonuo.exam.domain.UserToken" useGeneratedKeys="true" keyProperty="id">
    insert into t_user_token
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="token != null">
        token,
      </if>
      <if test="userId != null">
        user_id,
      </if>
      <if test="wxOpenId != null">
        wx_open_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="endTime != null">
        end_time,
      </if>
      <if test="userName != null">
        user_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="token != null">
        #{token,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="wxOpenId != null">
        #{wxOpenId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null">
        #{endTime,jdbcType=TIMESTAMP},
      </if>
      <if test="userName != null">
        #{userName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="vip.xiaonuo.exam.domain.UserToken">
    update t_user_token
    <set>
      <if test="token != null">
        token = #{token,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        user_id = #{userId,jdbcType=INTEGER},
      </if>
      <if test="wxOpenId != null">
        wx_open_id = #{wxOpenId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null">
        end_time = #{endTime,jdbcType=TIMESTAMP},
      </if>
      <if test="userName != null">
        user_name = #{userName,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="vip.xiaonuo.exam.domain.UserToken">
    update t_user_token
    set token = #{token,jdbcType=VARCHAR},
      user_id = #{userId,jdbcType=INTEGER},
      wx_open_id = #{wxOpenId,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      end_time = #{endTime,jdbcType=TIMESTAMP},
      user_name = #{userName,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>





  <select id="getToken" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user_token
    where token = #{token,jdbcType=VARCHAR}
    order by id desc
    limit 1
  </select>


</mapper>
