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

	<resultMap type="com.vctgo.system.api.domain.SysLogininfor" id="SysLogininforResult">
		<id     property="infoId"        column="info_id"           />
		<result property="userName"      column="user_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" >
		insert into sys_logininfor (user_name, status, ipaddr, msg, access_time,tenant_id)
		values (#{userName}, #{status}, #{ipaddr}, #{msg}, sysdate(),#{tenantId})
	</insert>

	<select id="selectLogininforList"  resultMap="SysLogininforResult">
		select info_id, user_name, ipaddr, status, msg, access_time from sys_logininfor
		<where>
			<if test="query.ipaddr != null and query.ipaddr != ''">
				AND ipaddr like concat('%', #{query.ipaddr}, '%')
			</if>
			<if test="query.status != null and query.status != ''">
				AND status = #{query.status}
			</if>
			<if test="query.userName != null and query.userName != ''">
				AND user_name like concat('%', #{query.userName}, '%')
			</if>
			<if test="query.params.beginTime != null and query.params.beginTime != ''">
				AND access_time &gt;= #{query.params.beginTime}
			</if>
			<if test="query.params.endTime != null and query.params.endTime != ''">
				AND access_time &lt;= #{query.params.endTime}
			</if>
		</where>
		order by info_id desc
	</select>
    <select id="countLogininfo" resultType="java.lang.Object">
		select count(info_id) from sys_logininfor where status =0 and msg='登录成功'
	</select>
	<select id="countRegister" resultType="java.lang.Object">
		select count(user_id) from sys_user
	</select>
    <select id="countTenant" resultType="java.lang.Object">
		select count(id) from sys_tenant;
	</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>
