<?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.sys.dao.SysUserMapper" >
  <resultMap id="BaseResultMap" type="com.sys.model.SysUser" >
    <id column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="user_name" property="userName" jdbcType="VARCHAR" />
    <result column="sex" property="sex" jdbcType="VARCHAR" />
    <result column="user_avatar" property="userAvatar" jdbcType="VARCHAR" />
    <result column="user_salt" property="userSalt" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="last_login_date" property="lastLoginDate" jdbcType="TIMESTAMP" />
    <result column="login_count" property="loginCount" jdbcType="INTEGER" />
    <result column="isdel" property="isdel" jdbcType="INTEGER" />
    <result column="role" property="role" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    user_id, password, user_name, sex, user_avatar, user_salt, create_date, last_login_date, 
    login_count,role,isdel
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from sys_user
    where user_id = #{userId,jdbcType=INTEGER}
  </select>
  <select id="selectByUserName" resultMap="BaseResultMap" parameterType="java.lang.String">
    select
    <include refid="Base_Column_List"/>
    from sys_user
    where user_name = #{userName,jdbcType=VARCHAR}
  </select>

  <select id="selectAll" resultMap="BaseResultMap" parameterType="java.lang.Integer">
    SELECT * FROM sys_user
    WHERE 1=1
    and isdel = 0 
    <if test="userName != '' and  userName != null" >
      and user_name like '%${userName}%'
    </if>
    limit #{count,jdbcType=BIGINT}, #{limit,jdbcType=BIGINT}
  </select>
  <select id="selectCount" resultType="java.lang.Long" parameterType="java.lang.Integer" >
    SELECT
    count(*)
    FROM sys_user
    WHERE 1=1
    and isdel = 0 
    <if test="userName != '' and  userName != null" >
      and user_name like '%${userName}%'
    </if>
  </select>


  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from sys_user
    where user_id = #{userId,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.sys.model.SysUser" >
    insert into sys_user (user_id, password, user_name, 
      sex, user_avatar, user_salt, 
      create_date, last_login_date, login_count,isdel
      )
    values (#{userId,jdbcType=INTEGER}, #{password,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, 
      #{sex,jdbcType=VARCHAR}, #{userAvatar,jdbcType=VARCHAR}, #{userSalt,jdbcType=VARCHAR}, 
      #{createDate,jdbcType=TIMESTAMP}, #{lastLoginDate,jdbcType=TIMESTAMP}, #{loginCount,jdbcType=INTEGER},0
      )
  </insert>
  <insert id="insertSelective" parameterType="com.sys.model.SysUser" >
    insert into sys_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        user_id,
      </if>
      <if test="password != null" >
        password,
      </if>
      <if test="userName != null" >
        user_name,
      </if>
      <if test="sex != null" >
        sex,
      </if>
      <if test="userAvatar != null" >
        user_avatar,
      </if>
      <if test="userSalt != null" >
        user_salt,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="lastLoginDate != null" >
        last_login_date,
      </if>
      <if test="loginCount != null" >
        login_count,
      </if>
      <if test="isdel != null" >
        isdel,
      </if>
      <if test="role!=null">
        role,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="password != null" >
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="userName != null" >
        #{userName,jdbcType=VARCHAR},
      </if>
      <if test="sex != null" >
        #{sex,jdbcType=VARCHAR},
      </if>
      <if test="userAvatar != null" >
        #{userAvatar,jdbcType=VARCHAR},
      </if>
      <if test="userSalt != null" >
        #{userSalt,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="lastLoginDate != null" >
        #{lastLoginDate,jdbcType=TIMESTAMP},
      </if>
      <if test="loginCount != null" >
        #{loginCount,jdbcType=INTEGER},
      </if>
      <if test="isdel != null" >
        0,
      </if>
      <if test="role!=null">
        #{role,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.sys.model.SysUser" >
    update sys_user
    <set >
      <if test="password != null" >
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="userName != null" >
        user_name = #{userName,jdbcType=VARCHAR},
      </if>
      <if test="sex != null" >
        sex = #{sex,jdbcType=VARCHAR},
      </if>
      <if test="userAvatar != null" >
        user_avatar = #{userAvatar,jdbcType=VARCHAR},
      </if>
      <if test="userSalt != null" >
        user_salt = #{userSalt,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="lastLoginDate != null" >
        last_login_date = #{lastLoginDate,jdbcType=TIMESTAMP},
      </if>
      <if test="loginCount != null" >
        login_count = #{loginCount,jdbcType=INTEGER},
      </if>
      <if test="isdel != null" >
        isdel = #{isdel,jdbcType=INTEGER},
      </if>
    </set>
    where user_id = #{userId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.sys.model.SysUser" >
    update sys_user
    set password = #{password,jdbcType=VARCHAR},
      user_name = #{userName,jdbcType=VARCHAR},
      sex = #{sex,jdbcType=VARCHAR},
      user_avatar = #{userAvatar,jdbcType=VARCHAR},
      user_salt = #{userSalt,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      last_login_date = #{lastLoginDate,jdbcType=TIMESTAMP},
      login_count = #{loginCount,jdbcType=INTEGER},
      isdel = #{isdel,jdbcType=INTEGER}
    where user_id = #{userId,jdbcType=INTEGER}
  </update>
</mapper>