<?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.AuthLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.AuthLogEntity">
        <id column="id" property="id"/>
        <id column="event_type" property="eventType"/>
        <id column="username" property="username"/>
        <id column="user_id" property="userId"/>
        <id column="request_ip" property="requestIp"/>
        <id column="request_method" property="requestMethod"/>
        <id column="request_uri" property="requestUri"/>
        <id column="class_name" property="className"/>
        <id column="method_name" property="methodName"/>
        <id column="method_params" property="methodParams"/>
        <id column="required_authority" property="requiredAuthority"/>
        <id column="user_authorities" property="userAuthorities"/>
        <id column="decision_reason" property="decisionReason"/>
        <id column="exception_message" property="exceptionMessage"/>
        <id column="is_deleted" property="isDeleted"/>
        <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, event_type,username,user_id,request_ip,request_method,request_uri,class_name,method_name,method_params,required_authority,user_authorities,decision_reason,exception_message,is_deleted, create_time, update_time, create_user, update_user
    </sql>

    <!-- 分页查询系统授权日志表内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.AuthLogVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_auth_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.eventType != null and dto.eventType != ''">
                and base.event_type like CONCAT('%',#{dto.eventType},'%')
            </if>
            <if test="dto.username != null and dto.username != ''">
                and base.username like CONCAT('%',#{dto.username},'%')
            </if>
            <if test="dto.userId != null and dto.userId != ''">
                and base.user_id like CONCAT('%',#{dto.userId},'%')
            </if>
            <if test="dto.requestIp != null and dto.requestIp != ''">
                and base.request_ip like CONCAT('%',#{dto.requestIp},'%')
            </if>
            <if test="dto.requestMethod != null and dto.requestMethod != ''">
                and base.request_method like CONCAT('%',#{dto.requestMethod},'%')
            </if>
            <if test="dto.requestUri != null and dto.requestUri != ''">
                and base.request_uri like CONCAT('%',#{dto.requestUri},'%')
            </if>
            <if test="dto.className != null and dto.className != ''">
                and base.class_name like CONCAT('%',#{dto.className},'%')
            </if>
            <if test="dto.methodName != null and dto.methodName != ''">
                and base.method_name like CONCAT('%',#{dto.methodName},'%')
            </if>
            <if test="dto.methodParams != null and dto.methodParams != ''">
                and base.method_params like CONCAT('%',#{dto.methodParams},'%')
            </if>
            <if test="dto.requiredAuthority != null and dto.requiredAuthority != ''">
                and base.required_authority like CONCAT('%',#{dto.requiredAuthority},'%')
            </if>
            <if test="dto.userAuthorities != null and dto.userAuthorities != ''">
                and base.user_authorities like CONCAT('%',#{dto.userAuthorities},'%')
            </if>
            <if test="dto.decisionReason != null and dto.decisionReason != ''">
                and base.decision_reason like CONCAT('%',#{dto.decisionReason},'%')
            </if>
            <if test="dto.exceptionMessage != null and dto.exceptionMessage != ''">
                and base.exception_message like CONCAT('%',#{dto.exceptionMessage},'%')
            </if>
            <if test="dto.isDeleted != null and dto.isDeleted != ''">
                and base.is_deleted like CONCAT('%',#{dto.isDeleted},'%')
            </if>
        </where>
    </select>

</mapper>
