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

	<resultMap type="SysLogininfor" id="SysLogininforResult">
		<id     property="infoId"        column="info_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"        />
		<result property="identifier"     column="identifier"        />
	</resultMap>

	<insert id="insertLogininfor" parameterType="SysLogininfor">
	    <selectKey keyProperty="infoId" resultType="long" order="BEFORE">
			SELECT seq_sys_logininfor.NEXTVAL as infoId FROM DUAL
		</selectKey>
		insert into sys_logininfor (info_id, login_name, status, ipaddr, login_location, browser, os, msg, login_time, identifier)
		values (#{infoId}, #{loginName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate, #{identifier})
	</insert>
	
	<select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult">
		select info_id,login_name,ipaddr,login_location,browser,os,status,msg,login_time, identifier from sys_logininfor
		<where>
			<if test="ipaddr != null and ipaddr != ''">
				AND ipaddr like concat(concat('%',#{ipaddr}),'%')
			</if>
			<if test="status != null and status != ''">
				AND status = #{status}
			</if>
			<if test="loginName != null and loginName != ''">
				AND login_name like concat(concat('%',#{loginName}),'%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
				and login_time &gt;= to_date(#{params.beginTime},'yyyy-MM-dd HH24:mi:ss')
			</if>
			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
				and login_time &lt;= to_date(#{params.endTime},'yyyy-MM-dd HH24:mi:ss')
			</if>
		</where>
	</select>

	<select id="selectLogininfors" parameterType="SysLogininfor" resultMap="SysLogininforResult">
		select
			*
		from
			sys_logininfor
		where login_name = #{loginName} and msg = #{msg} order by login_time desc
	</select>

	<select id="selectLogininfor" parameterType="SysLogininfor" resultMap="SysLogininforResult">
		select
			*
		from
			sys_logininfor
		where login_name = #{loginName} and identifier = #{identifier} and msg = #{msg} order by login_time desc
	</select>
	
	<delete id="deleteLogininforByIds" parameterType="String">
 		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>

	<update id="updateSysLogininfor" parameterType="SysLogininfor">
		update sys_logininfor
		<trim prefix="SET" suffixOverrides=",">
			<if test="loginName != null">login_name = #{loginName},</if>
			<if test="ipaddr != null">ipaddr = #{ipaddr},</if>
			<if test="loginLocation != null">login_location = #{loginLocation},</if>
			<if test="browser != null">browser = #{browser},</if>
			<if test="os != null">os = #{os},</if>
			<if test="status != null">status = #{status},</if>
			<if test="msg != null">msg = #{msg},</if>
			<if test="loginTime != null">login_time = #{loginTime},</if>
			<if test="identifier != null">identifier = #{identifier},</if>
		</trim>
		where info_id = #{infoId}
	</update>
    
</mapper> 