<?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.qmth.teachcloud.common.mapper.BasicOperationLogMapper">

    <select id="findOperationLogPage"
            resultType="com.qmth.teachcloud.common.bean.result.BasicOperationLogResult">
        SELECT
            bol.id,
            bol.detail,
            bol.user_id userId,
            su.login_name loginName,
            su.real_name realName,
            bol.ip,
            bol.operation_type AS operationType,
            bol.create_time AS createTime,
            bol.run_status runStatus,
            case bol.privilege_id when '99990111' then '首页' else sp.name end privilegeName,
            bol.args
        FROM
            basic_operation_log  bol
                left join sys_user su on bol.user_id = su.id
                left join sys_privilege sp on bol.privilege_id = sp.id
        <where>
            <if test="schoolId != null">
                AND bol.school_id = #{schoolId}
            </if>
            <if test="operationType != null">
                AND bol.operation_type = #{operationType}
            </if>
            <if test="startTime != null">
                AND bol.create_time >= #{startTime}
            </if>
            <if test="endTime != null">
                AND #{endTime} >= bol.create_time
            </if>
            <if test="operatorName != null and operatorName != ''">
                AND (su.real_name LIKE CONCAT('%',#{operatorName},'%') OR su.login_name LIKE CONCAT('%',#{operatorName},'%'))
            </if>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND bol.user_id = #{dpr.requestUserId}
                </if>
                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
                    AND su.org_id IN
                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
        ORDER BY bol.create_time DESC
    </select>
</mapper>