<?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.auth.dao.base.mapper.v1.LoginLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.LoginLogEntity">
        <id column="id" property="id"/>
        <id column="user_id" property="userId"/>
        <id column="username" property="username"/>
        <id column="login_type" property="loginType"/>
        <id column="login_result" property="loginResult"/>
        <id column="ip_address" property="ipAddress"/>
        <id column="ip_region" property="ipRegion"/>
        <id column="user_agent" property="userAgent"/>
        <id column="device_type" property="deviceType"/>
        <id column="os_type" property="osType"/>
        <id column="browser_type" property="browserType"/>
        <id column="error_msg" property="errorMsg"/>
        <id column="create_time" property="createTime"/>
        <id column="update_time" property="updateTime"/>
        <id column="create_user" property="createUser"/>
        <id column="update_user" property="updateUser"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        user_id,username,login_type,login_result,ip_address,ip_region,user_agent,device_type,os_type,browser_type,error_msg,
        create_time, update_time, create_user, update_user
    </sql>

    <!-- 分页查询系统用户登录日志内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.LoginLogVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_login_log base
        left join sys_user create_user on create_user.id = base.create_user
        left join sys_user update_user on update_user.id = base.update_user
        <where>
            base.is_deleted = 0
            <if test="dto.userId != null and dto.userId != ''">
                and base.user_id like CONCAT('%',#{dto.userId},'%')
            </if>
            <if test="dto.username != null and dto.username != ''">
                and base.username like CONCAT('%',#{dto.username},'%')
            </if>
            <if test="dto.loginType != null and dto.loginType != ''">
                and base.login_type like CONCAT('%',#{dto.loginType},'%')
            </if>
            <if test="dto.loginResult != null and dto.loginResult != ''">
                and base.login_result like CONCAT('%',#{dto.loginResult},'%')
            </if>
            <if test="dto.ipAddress != null and dto.ipAddress != ''">
                and base.ip_address like CONCAT('%',#{dto.ipAddress},'%')
            </if>
            <if test="dto.ipRegion != null and dto.ipRegion != ''">
                and base.ip_region like CONCAT('%',#{dto.ipRegion},'%')
            </if>
            <if test="dto.userAgent != null and dto.userAgent != ''">
                and base.user_agent like CONCAT('%',#{dto.userAgent},'%')
            </if>
            <if test="dto.deviceType != null and dto.deviceType != ''">
                and base.device_type like CONCAT('%',#{dto.deviceType},'%')
            </if>
            <if test="dto.osType != null and dto.osType != ''">
                and base.os_type like CONCAT('%',#{dto.osType},'%')
            </if>
            <if test="dto.browserType != null and dto.browserType != ''">
                and base.browser_type like CONCAT('%',#{dto.browserType},'%')
            </if>
            <if test="dto.errorMsg != null and dto.errorMsg != ''">
                and base.error_msg like CONCAT('%',#{dto.errorMsg},'%')
            </if>
        </where>
    </select>

</mapper>
