<?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.ics.system.mapper.LoginInfoMapper">

	<resultMap type="com.ics.system.domain.LoginInfo" id="LoginInfoResult">
		<id     property="id"        	 column="id"           		/>
		<result property="loginName"     column="login_name"        />
		<result property="status"        column="status"            />
		<result property="ipaddr"        column="ipaddr"            />
		<result property="loginLocation" column="login_location"    />
		<result property="browser"       column="browser"           />
		<result property="os"            column="os"                />
		<result property="msg"           column="msg"               />
		<result property="loginTime"     column="login_time"        />
	</resultMap>

	<select id="selectLoginInfoList" parameterType="com.ics.system.domain.LoginInfo" resultMap="LoginInfoResult">
		SELECT  id,
				login_name,
				ipaddr,
				login_location,
				browser,
				os,
				status,
				msg,
				login_time
		FROM sys_login_info
		<where>
			<if test="ipaddr != null and ipaddr != ''">
				AND ipaddr LIKE concat('%', #{ipaddr}, '%')
			</if>
			<if test="status != null and status != ''">
				AND status = #{status}
			</if>
			<if test="loginName != null and loginName != ''">
				AND login_name LIKE concat('%', #{loginName}, '%')
			</if>
			<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
				AND date_format(login_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
			</if>
			<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
				AND date_format(login_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
			</if>
		</where>
	</select>

	<insert id="insertLoginInfo" parameterType="com.ics.system.domain.LoginInfo">
		INSERT INTO sys_login_info (
				login_name,
				status,
				ipaddr,
				login_location,
				browser,
				os,
				msg,
				login_time
			)
		VALUES (
				#{loginName},
				#{status},
				#{ipaddr},
				#{loginLocation},
				#{browser},
				#{os},
				#{msg},
				sysdate()
		)
	</insert>

	<delete id="deleteLoginInfoByIds" parameterType="String">
 		DELETE FROM sys_login_info WHERE id IN
 		<foreach collection="array" item="id" open="(" separator="," close=")">
 			#{id}
        </foreach> 
 	</delete>
    
    <update id="cleanLoginInfo">
        TRUNCATE TABLE sys_login_info
    </update>
    
</mapper> 