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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.MenuEntity">
        <id column="id" property="id"/>
        <id column="parent_id" property="parentId"/>
        <id column="menu_path" property="menuPath"/>
        <id column="menu_name" property="menuName"/>
        <id column="menu_title" property="menuTitle"/>
        <id column="component" property="component"/>
        <id column="redirect" property="redirect"/>
        <id column="menu_type" property="menuType"/>
        <id column="icon" property="icon"/>
        <id column="order_num" property="orderNum"/>
        <id column="is_external" property="isExternal"/>
        <id column="is_cache" property="isCache"/>
        <id column="is_visible" property="isVisible"/>
        <id column="permission" property="permission"/>
        <id column="status" property="status"/>
        <id column="meta" property="meta"/>
        <id column="remark" property="remark"/>
        <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"/>
        <id column="is_deleted" property="isDeleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        parent_id,menu_path,menu_name,menu_title,component,redirect,menu_type,icon,order_num,is_external,is_cache,is_visible,permission,status,meta,remark,is_deleted,
        create_time, update_time, create_user, update_user, is_deleted
    </sql>

    <!-- 分页查询系统菜单权限内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.MenuVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_menu 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.menuPath != null and dto.menuPath != ''">
                and base.menu_path like CONCAT('%',#{dto.menuPath},'%')
            </if>
            <if test="dto.menuName != null and dto.menuName != ''">
                and base.menu_name like CONCAT('%',#{dto.menuName},'%')
            </if>
            <if test="dto.menuTitle != null and dto.menuTitle != ''">
                and base.menu_title like CONCAT('%',#{dto.menuTitle},'%')
            </if>
            <if test="dto.component != null and dto.component != ''">
                and base.component like CONCAT('%',#{dto.component},'%')
            </if>
            <if test="dto.redirect != null and dto.redirect != ''">
                and base.redirect like CONCAT('%',#{dto.redirect},'%')
            </if>
            <if test="dto.menuType != null and dto.menuType != ''">
                and base.menu_type like CONCAT('%',#{dto.menuType},'%')
            </if>
            <if test="dto.icon != null and dto.icon != ''">
                and base.icon like CONCAT('%',#{dto.icon},'%')
            </if>
            <if test="dto.orderNum != null and dto.orderNum != ''">
                and base.order_num like CONCAT('%',#{dto.orderNum},'%')
            </if>
            <if test="dto.isExternal != null and dto.isExternal != ''">
                and base.is_external like CONCAT('%',#{dto.isExternal},'%')
            </if>
            <if test="dto.isCache != null and dto.isCache != ''">
                and base.is_cache like CONCAT('%',#{dto.isCache},'%')
            </if>
            <if test="dto.isVisible != null and dto.isVisible != ''">
                and base.is_visible like CONCAT('%',#{dto.isVisible},'%')
            </if>
            <if test="dto.permission != null and dto.permission != ''">
                and base.permission like CONCAT('%',#{dto.permission},'%')
            </if>
            <if test="dto.status != null and dto.status != ''">
                and base.status like CONCAT('%',#{dto.status},'%')
            </if>
            <if test="dto.meta != null and dto.meta != ''">
                and base.meta like CONCAT('%',#{dto.meta},'%')
            </if>
            <if test="dto.remark != null and dto.remark != ''">
                and base.remark like CONCAT('%',#{dto.remark},'%')
            </if>
            <if test="dto.isDeleted != null and dto.isDeleted != ''">
                and base.is_deleted like CONCAT('%',#{dto.isDeleted},'%')
            </if>
        </where>
    </select>

</mapper>
