<?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.ssm.mapper.system.SysUserLoginLogMapper" >
  <resultMap id="BaseResultMap" type="com.ssm.model.system.SysUserLoginLog" >
    <id column="ID" property="id" jdbcType="INTEGER" />
    <result column="UserID" property="userid" jdbcType="INTEGER" />
    <result column="IpAddress" property="ipaddress" jdbcType="VARCHAR" />
    <result column="Comments" property="comments" jdbcType="VARCHAR" />
    <result column="CreatedDate" property="createddate" jdbcType="TIMESTAMP" />
    <result column="cd" property="cd" jdbcType="VARCHAR" />
    <result column="UserName" property="username" jdbcType="VARCHAR" />
    <result column="startDate" property="startDate" jdbcType="TIMESTAMP" />
    <result column="endDate" property="endDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    ID, IpAddress, Comments, CreatedDate ,UserName
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from SysUserLoginLog
    where ID = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectlog" resultMap="BaseResultMap">
  	select
  	<include refid="Base_Column_List" />
  	
  	 ,date_format(CreatedDate, '%Y-%m-%d %H:%i:%s')  as cd from SysUserLoginLog LEFT JOIN SysUser on SysUserLoginLog.UserID=SysUser.UserID 
  	 where 1 = 1
  	 <if test="username != null and username != '' ">
		and SysUser.UserName like '%${username}%'
	 </if>
	 
	 <if test="startDate != null and startDate != '' ">
		 <![CDATA[ and SysUserLoginLog.CreatedDate >= #{startDate} ]]> 
	 </if>
	 
	 <if test="endDate != null and endDate != '' ">
		<![CDATA[ and SysUserLoginLog.CreatedDate <=  #{endDate} ]]> 
	 </if>
  	 ORDER BY SysUserLoginLog.CreatedDate Desc
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from SysUserLoginLog
    where ID = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.ssm.model.system.SysUserLoginLog" >
    insert into SysUserLoginLog (ID, UserID, IpAddress, 
      Comments, CreatedDate)
    values (#{id,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, #{ipaddress,jdbcType=VARCHAR}, 
      #{comments,jdbcType=VARCHAR}, #{createddate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.ssm.model.system.SysUserLoginLog" >
    insert into SysUserLoginLog
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        ID,
      </if>
      <if test="userid != null" >
        UserID,
      </if>
      <if test="ipaddress != null" >
        IpAddress,
      </if>
      <if test="comments != null" >
        Comments,
      </if>
      <if test="createddate != null" >
        CreatedDate,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userid != null" >
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="ipaddress != null" >
        #{ipaddress,jdbcType=VARCHAR},
      </if>
      <if test="comments != null" >
        #{comments,jdbcType=VARCHAR},
      </if>
      <if test="createddate != null" >
        #{createddate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.ssm.model.system.SysUserLoginLog" >
    update SysUserLoginLog
    <set >
      <if test="userid != null" >
        UserID = #{userid,jdbcType=INTEGER},
      </if>
      <if test="ipaddress != null" >
        IpAddress = #{ipaddress,jdbcType=VARCHAR},
      </if>
      <if test="comments != null" >
        Comments = #{comments,jdbcType=VARCHAR},
      </if>
      <if test="createddate != null" >
        CreatedDate = #{createddate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ID = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ssm.model.system.SysUserLoginLog" >
    update SysUserLoginLog
    set UserID = #{userid,jdbcType=INTEGER},
      IpAddress = #{ipaddress,jdbcType=VARCHAR},
      Comments = #{comments,jdbcType=VARCHAR},
      CreatedDate = #{createddate,jdbcType=TIMESTAMP}
    where ID = #{id,jdbcType=INTEGER}
  </update>
</mapper>