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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.OperationLogEntity">
        <id column="id" property="id"/>
        <id column="module" property="module"/>
        <id column="operation_type" property="operationType"/>
        <id column="operation_desc" property="operationDesc"/>
        <id column="request_method" property="requestMethod"/>
        <id column="request_url" property="requestUrl"/>
        <id column="request_params" property="requestParams"/>
        <id column="response_result" property="responseResult"/>
        <id column="user_id" property="userId"/>
        <id column="username" property="username"/>
        <id column="ip_address" property="ipAddress"/>
        <id column="ip_region" property="ipRegion"/>
        <id column="user_agent" property="userAgent"/>
        <id column="status" property="status"/>
        <id column="error_msg" property="errorMsg"/>
        <id column="execute_time" property="executeTime"/>
        <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,
        module,operation_type,operation_desc,request_method,request_url,request_params,response_result,user_id,username,ip_address,ip_region,user_agent,status,error_msg,execute_time,
        create_time, update_time, create_user, update_user
    </sql>

    <!-- 分页查询系统操作日志内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.OperationLogVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_operation_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.module != null and dto.module != ''">
                and base.module like CONCAT('%',#{dto.module},'%')
            </if>
            <if test="dto.operationType != null and dto.operationType != ''">
                and base.operation_type like CONCAT('%',#{dto.operationType},'%')
            </if>
            <if test="dto.operationDesc != null and dto.operationDesc != ''">
                and base.operation_desc like CONCAT('%',#{dto.operationDesc},'%')
            </if>
            <if test="dto.requestMethod != null and dto.requestMethod != ''">
                and base.request_method like CONCAT('%',#{dto.requestMethod},'%')
            </if>
            <if test="dto.requestUrl != null and dto.requestUrl != ''">
                and base.request_url like CONCAT('%',#{dto.requestUrl},'%')
            </if>
            <if test="dto.requestParams != null and dto.requestParams != ''">
                and base.request_params like CONCAT('%',#{dto.requestParams},'%')
            </if>
            <if test="dto.responseResult != null and dto.responseResult != ''">
                and base.response_result like CONCAT('%',#{dto.responseResult},'%')
            </if>
            <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.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.status != null and dto.status != ''">
                and base.status like CONCAT('%',#{dto.status},'%')
            </if>
            <if test="dto.errorMsg != null and dto.errorMsg != ''">
                and base.error_msg like CONCAT('%',#{dto.errorMsg},'%')
            </if>
            <if test="dto.executeTime != null and dto.executeTime != ''">
                and base.execute_time like CONCAT('%',#{dto.executeTime},'%')
            </if>
        </where>
    </select>

</mapper>
