<?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.bonus.sgzb.system.mapper.SysLogininforMapper">

	<resultMap type="com.bonus.sgzb.system.api.domain.SysLogininfor" id="SysLogininforResult">
		<id     property="infoId"        column="info_id"           />
		<result property="userName"      column="user_name"         />
		<result property="nickName"      column="nick_name"         />
		<result property="status"        column="status"            />
		<result property="ipaddr"        column="ipaddr"            />
		<result property="msg"           column="msg"               />
		<result property="accessTime"    column="access_time"       />
	</resultMap>

	<insert id="insertLogininfor" parameterType="com.bonus.sgzb.system.api.domain.SysLogininfor">
		insert into sys_logininfor (user_name, status, ipaddr, msg, access_time)
		values (#{userName}, #{status}, #{ipaddr}, #{msg}, sysdate())
	</insert>
	
	<select id="selectLogininforList" parameterType="com.bonus.sgzb.system.api.domain.SysLogininfor" resultMap="SysLogininforResult">
		select sl.info_id, sl.user_name, su.nick_name, sl.ipaddr, sl.status, sl.msg, sl.access_time
		from sys_logininfor as sl left join sys_user as su
		on sl.user_name = su.user_name
		    WHERE 1=1
			<if test="ipaddr != null and ipaddr != ''">
				AND sl.ipaddr like concat('%', #{ipaddr}, '%')
			</if>
			<if test="status != null and status != ''">
				AND sl.status = #{status}
			</if>
			<if test="userName != null and userName != ''">
				AND sl.user_name like concat('%', #{userName}, '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
				AND sl.access_time &gt;= #{params.beginTime}
			</if>
			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
				AND sl.access_time &lt;= #{params.endTime}
			</if>
		order by sl.info_id desc
	</select>
	
	<delete id="deleteLogininforByIds" parameterType="Long">
 		delete from sys_logininfor where info_id in
 		<foreach collection="array" item="infoId" open="(" separator="," close=")">
 			#{infoId}
        </foreach> 
 	</delete>
    
    <update id="cleanLogininfor">
        truncate table sys_logininfor
    </update>
    
</mapper> 