<?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.cab.dao.UserMapper">
  <resultMap id="BaseResultMap" type="com.cab.model.User">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="username" jdbcType="VARCHAR" property="username" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="login_type" jdbcType="VARCHAR" property="threeLoginType" />
    <result column="openid" jdbcType="VARCHAR" property="openid" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="last_login" jdbcType="TIMESTAMP" property="lastLogin" />
    <result column="regist_ip" jdbcType="VARCHAR" property="registIp" />
    <result column="avatar" jdbcType="VARCHAR" property="avatar" />
    <result column="age" jdbcType="VARCHAR" property="age" />
    <result column="is_female" jdbcType="INTEGER" property="isFemale" />
    <result column="fully_registered" jdbcType="INTEGER" property="fullyRegistered" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="real_name" jdbcType="VARCHAR" property="realName" />
    <result column="city_id" jdbcType="VARCHAR" property="cityId" />
    <result column="province_id" jdbcType="VARCHAR" property="provinceId" />
    <result column="area_id" jdbcType="VARCHAR" property="areaId" />
    <result column="cardId" jdbcType="VARCHAR" property="cardId" />
    <result column="payPassWord" jdbcType="VARCHAR" property="payPassWord" />
    <result column="randomCode" jdbcType="VARCHAR" property="randomCode" />
    <result column="code_time" jdbcType="TIMESTAMP" property="codeTime" />
  </resultMap>
  <resultMap id="BaseJoinMap" type="com.cab.model.User">
    <id column="user_id" jdbcType="BIGINT" property="id" />
    <result column="avatar" jdbcType="VARCHAR" property="avatar" />
    <result column="name" jdbcType="VARCHAR" property="name" />
  </resultMap>
  
  <resultMap id="ContentFollowFromJoinMap" type="com.cab.model.User">
    <id column="from_id" jdbcType="BIGINT" property="id" />
    <result column="avatar_from" jdbcType="VARCHAR" property="avatar" />
    <result column="name_from" jdbcType="VARCHAR" property="name" />
  </resultMap>
  
  <resultMap id="ContentFollowToJoinMap" type="com.cab.model.User">
    <id column="to_id" jdbcType="BIGINT" property="id" />
    <result column="avatar_to" jdbcType="VARCHAR" property="avatar" />
    <result column="name_to" jdbcType="VARCHAR" property="name" />
  </resultMap>
  
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.cab.model.User">
    <result column="cku_info" jdbcType="LONGVARCHAR" property="ckuInfo" />
  </resultMap>
  <sql id="Base_Column_List">
    id, username, password, phone, login_type, openid, email, last_login, regist_ip, 
    avatar, age, is_female, fully_registered, name ,real_name,city_id,province_id,area_id,
    cardId,payPassWord,randomCode,code_time
  </sql>
  <sql id="Blob_Column_List">
    cku_info
  </sql>
  <select id="selectByPrimaryId" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from cab_users
    where id = #{id}
  </select>
  <select id="selectByUsername" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from cab_users
    where username = #{username,jdbcType=VARCHAR}
  </select>
  <select id="selectAll" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from cab_users
  </select>
  <select id="selectByUserPhone" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from cab_users
    where phone = #{phone,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from cab_users
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.cab.model.User">
    insert into cab_users (id, username, password, 
      phone, login_type, openid, 
      email, last_login, regist_ip, 
      avatar, age, is_female, 
      fully_registered, name, cku_info
      )
    values (#{id,jdbcType=BIGINT}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{threeLoginType,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR}, 
      #{email,jdbcType=VARCHAR}, #{lastLogin,jdbcType=TIMESTAMP}, #{registIp,jdbcType=VARCHAR}, 
      #{avatar,jdbcType=VARCHAR}, #{age,jdbcType=VARCHAR}, #{isFemale,jdbcType=INTEGER}, 
      #{fullyRegistered,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{ckuInfo,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.cab.model.User" useGeneratedKeys="true" keyProperty="id">
    insert into cab_users
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="username != null">
        username,
      </if>
      <if test="password != null">
        password,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="threeLoginType != null">
        login_type,
      </if>
      <if test="openid != null">
        openid,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="lastLogin != null">
        last_login,
      </if>
      <if test="registIp != null">
        regist_ip,
      </if>
      <if test="avatar != null">
        avatar,
      </if>
      <if test="age != null">
        age,
      </if>
      <if test="isFemale != null">
        is_female,
      </if>
      <if test="fullyRegistered != null">
        fully_registered,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="ckuInfo != null">
        cku_info,
      </if>
      <if test="realName != null">
        real_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="threeLoginType != null">
        #{threeLoginType,jdbcType=VARCHAR},
      </if>
      <if test="openid != null">
        #{openid,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="lastLogin != null">
        #{lastLogin,jdbcType=TIMESTAMP},
      </if>
      <if test="registIp != null">
        #{registIp,jdbcType=VARCHAR},
      </if>
      <if test="avatar != null">
        #{avatar,jdbcType=VARCHAR},
      </if>
      <if test="age != null">
        #{age,jdbcType=VARCHAR},
      </if>
      <if test="isFemale != null">
        #{isFemale,jdbcType=INTEGER},
      </if>
      <if test="fullyRegistered != null">
        #{fullyRegistered,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="ckuInfo != null">
        #{ckuInfo,jdbcType=LONGVARCHAR},
      </if>
      <if test="realName != null">
        #{realName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.cab.model.User">
    update cab_users
    <set>
      <if test="username != null">
        username = #{username,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="threeLoginType != null">
        login_type = #{threeLoginType,jdbcType=VARCHAR},
      </if>
      <if test="openid != null">
        openid = #{openid,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="lastLogin != null">
        last_login = #{lastLogin,jdbcType=TIMESTAMP},
      </if>
      <if test="registIp != null">
        regist_ip = #{registIp,jdbcType=VARCHAR},
      </if>
      <if test="avatar != null">
        avatar = #{avatar,jdbcType=VARCHAR},
      </if>
      <if test="age != null">
        age = #{age,jdbcType=VARCHAR},
      </if>
      <if test="isFemale != null">
        is_female = #{isFemale,jdbcType=INTEGER},
      </if>
      <if test="fullyRegistered != null">
        fully_registered = #{fullyRegistered,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="ckuInfo != null">
        cku_info = #{ckuInfo,jdbcType=LONGVARCHAR},
      </if>
      <if test="realName != null">
      	real_name = #{realName,jdbcType=VARCHAR},
      </if>
      <if test="areaId != null or provinceId != null or cityId != null">
      	area_id = #{areaId,jdbcType=INTEGER},
      	province_id = #{provinceId,jdbcType=INTEGER},
      	city_id = #{cityId,jdbcType=INTEGER},
      </if>
      <if test="cardId != null">
      	cardId = #{cardId},
      </if>
      <if test="payPassWord != null">
     	 payPassWord = #{payPassWord},
      </if>
      <if test="randomCode != null">
      	randomCode = #{randomCode},
      </if>
      <if test="codeTime != null">
      	code_time = #{codeTime},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.cab.model.User">
    update cab_users
    set username = #{username,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      login_type = #{threeLoginType,jdbcType=VARCHAR},
      openid = #{openid,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      last_login = #{lastLogin,jdbcType=TIMESTAMP},
      regist_ip = #{registIp,jdbcType=VARCHAR},
      avatar = #{avatar,jdbcType=VARCHAR},
      age = #{age,jdbcType=VARCHAR},
      is_female = #{isFemale,jdbcType=INTEGER},
      fully_registered = #{fullyRegistered,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR},
      cku_info = #{ckuInfo,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.cab.model.User">
    update cab_users
    set username = #{username,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      login_type = #{threeLoginType,jdbcType=VARCHAR},
      openid = #{openid,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      last_login = #{lastLogin,jdbcType=TIMESTAMP},
      regist_ip = #{registIp,jdbcType=VARCHAR},
      avatar = #{avatar,jdbcType=VARCHAR},
      age = #{age,jdbcType=VARCHAR},
      is_female = #{isFemale,jdbcType=INTEGER},
      fully_registered = #{fullyRegistered,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>

</mapper>