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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.PermissionEntity">
        <id column="id" property="id"/>
        <id column="parent_id" property="parentId"/>
        <id column="power_code" property="powerCode"/>
        <id column="power_name" property="powerName"/>
        <id column="request_url" property="requestUrl"/>
        <id column="request_method" property="requestMethod"/>
        <id column="is_deleted" property="isDeleted"/>
        <id column="permission_code" property="permissionCode"/>
        <id column="permission_name" property="permissionName"/>
        <id column="permission_type" property="permissionType"/>
        <id column="url" property="url"/>
        <id column="method" property="method"/>
        <id column="permission_level" property="permissionLevel"/>
        <id column="permission_path" property="permissionPath"/>
        <id column="order_num" property="orderNum"/>
        <id column="status" property="status"/>
        <id column="remark" property="remark"/>
        <id column="create_time" property="createTime"/>
        <id column="update_time" property="updateTime"/>
        <id column="create_user" property="createUser"/>
        <id column="update_user" property="updateUser"/>
        <id column="is_deleted" property="isDeleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        parent_id,power_code,power_name,request_url,request_method,is_deleted,permission_code,permission_name,permission_type,url,method,permission_level,permission_path,order_num,status,remark,
        create_time, update_time, create_user, update_user, is_deleted
    </sql>

    <!-- 分页查询系统权限表内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.PermissionVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_permission 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.parentId != null and dto.parentId != ''">
                and base.parent_id like CONCAT('%',#{dto.parentId},'%')
            </if>
            <if test="dto.powerCode != null and dto.powerCode != ''">
                and base.power_code like CONCAT('%',#{dto.powerCode},'%')
            </if>
            <if test="dto.powerName != null and dto.powerName != ''">
                and base.power_name like CONCAT('%',#{dto.powerName},'%')
            </if>
            <if test="dto.requestUrl != null and dto.requestUrl != ''">
                and base.request_url like CONCAT('%',#{dto.requestUrl},'%')
            </if>
            <if test="dto.requestMethod != null and dto.requestMethod != ''">
                and base.request_method like CONCAT('%',#{dto.requestMethod},'%')
            </if>
            <if test="dto.isDeleted != null and dto.isDeleted != ''">
                and base.is_deleted like CONCAT('%',#{dto.isDeleted},'%')
            </if>
            <if test="dto.permissionCode != null and dto.permissionCode != ''">
                and base.permission_code like CONCAT('%',#{dto.permissionCode},'%')
            </if>
            <if test="dto.permissionName != null and dto.permissionName != ''">
                and base.permission_name like CONCAT('%',#{dto.permissionName},'%')
            </if>
            <if test="dto.permissionType != null and dto.permissionType != ''">
                and base.permission_type like CONCAT('%',#{dto.permissionType},'%')
            </if>
            <if test="dto.url != null and dto.url != ''">
                and base.url like CONCAT('%',#{dto.url},'%')
            </if>
            <if test="dto.method != null and dto.method != ''">
                and base.method like CONCAT('%',#{dto.method},'%')
            </if>
            <if test="dto.permissionLevel != null and dto.permissionLevel != ''">
                and base.permission_level like CONCAT('%',#{dto.permissionLevel},'%')
            </if>
            <if test="dto.permissionPath != null and dto.permissionPath != ''">
                and base.permission_path like CONCAT('%',#{dto.permissionPath},'%')
            </if>
            <if test="dto.orderNum != null and dto.orderNum != ''">
                and base.order_num like CONCAT('%',#{dto.orderNum},'%')
            </if>
            <if test="dto.status != null and dto.status != ''">
                and base.status like CONCAT('%',#{dto.status},'%')
            </if>
            <if test="dto.remark != null and dto.remark != ''">
                and base.remark like CONCAT('%',#{dto.remark},'%')
            </if>
        </where>
    </select>

</mapper>
