<?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.lantone.security.mapper.LoginLogMapper">
    <insert id="addLoginLog">
    insert into sys_login_log(login_id,login_name,login_date,login_ip,login_address,login_browser,gmt_create)
    values (#{loginId},#{loginName},#{loginDate},INET_ATON(#{loginIp}),#{loginAddress},#{loginBrowser},#{gmtCreate})
    </insert>

    <select id="getLoginLog" resultType="com.lantone.common.dto.LoginLogDTO">
        select id,
        a.login_id as loginId,
        a.login_name as loginName,
        a.login_date as loginDate,
        INET_NTOA(a.login_ip) as loginIp,
        a.login_address as loginAddress,
        a.login_browser as loginBrowser
        from sys_login_log a
        where
        1 = 1
        <if test="loginName != null and loginName != ''">
            AND a.login_name like CONCAT('%',#{loginName},'%')
        </if>
        <if test="loginIp != null and loginIp != ''">
            AND INET_NTOA(a.login_ip) like CONCAT('%',#{loginIp},'%')
        </if>
        order by a.login_date desc
    </select>

    <select id="getLoginLogNameAndIp" resultType="java.lang.String">
        select
        <if test="mark == 0">
            a.login_name as loginName
        </if>
        <if test="mark == 1">
            INET_NTOA(a.login_ip) as loginIp
        </if>
        from sys_login_log a
        where
        1 = 1
        <if test="loginName != null and loginName != ''">
            AND a.login_name like CONCAT('%',#{loginName},'%')
        </if>
        <if test="loginIp != null and loginIp != ''">
            AND INET_NTOA(a.login_ip) like CONCAT('%',#{loginIp},'%')
        </if>
    </select>
</mapper>