<?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="cn.ey.biz.module.system.dal.mapper.permission.MenuMapper">

    <!-- 自定义ORM映射规则 -->
    <resultMap id="MenuDO" type="cn.ey.biz.module.system.controller.admin.permission.vo.menu.MenuRespVO">
        <result column="menu_id" property="id"/>
        <result column="name" property="name"/>
        <result column="permission" property="permission"/>
        <result column="type" property="type"/>
        <result column="sort" property="sort"/>
        <result column="parent_id" property="parentId"/>
        <result column="path" property="path"/>
        <result column="icon" property="icon"/>
        <result column="component" property="component"/>
        <result column="status" property="status"/>
        <result column="visible" property="visible"/>
        <result column="keep_alive" property="keepAlive"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <!-- 当关联属性为集合时用collection标签来描
             ofType是关联属性集合中装的实体类的全类名 -->
        <collection property="langs" ofType="cn.ey.biz.module.system.controller.admin.i18n.vo.I18nRespVO">
            <result property="label" column="label"/>
        </collection>
    </resultMap>
    <select id="getMenusList" resultMap="MenuDO">
        SELECT
        sm.menu_id,
        sm.app_code,
        sm.permission,
        sm.type,
        sm.sort,
        sm.parent_id,
        sm.icon,
        sm.component,
        sm.`status`,
        sm.keep_alive,
        sm.create_time,
        sm.update_time,
        i.label as name
        FROM
        system_menu sm
        LEFT JOIN infra_i18n i ON i.`key` = sm.menu_id AND i.deleted = 0 AND i.type = 'menu' AND i.lang
        =#{m.acceptLanguage}
        WHERE
        sm.deleted = 0
        <if test="m.name != null  and m.name != ''">
            AND i.label like concat('%', #{m.name},'%')
        </if>
        <if test="m.status != null">
            AND sm.status = #{m.status}
        </if>
        <if test="m.app != null  and m.app != ''">
            AND sm.app_code = #{m.app}
        </if>
    </select>

    <select id="checkNameRepetition"
            resultType="cn.ey.biz.module.system.controller.admin.category.vo.CategoryDataRespVO">
        SELECT
        sm.menu_id,
        sm.app_code,
        sm.permission,
        sm.type,
        sm.sort,
        sm.parent_id,
        sm.icon,
        sm.component,
        sm.`status`,
        sm.keep_alive,
        sm.create_time,
        sm.update_time,
        i.label as name
        FROM
        system_menu sm
        LEFT JOIN infra_i18n i ON i.`key` = sm.menu_id
        WHERE
        sm.deleted = 0
        AND sm.app_code = #{m.app}
        AND i.deleted = 0
        AND sm.menu_id = i.key
        AND i.type = 'menu'
        AND sm.parent_id = #{m.parentId}
        AND i.lang = #{i.lang}
        AND i.label = #{i.label}
        <if test="id != null and id != ''">
            AND i.key != #{id}
        </if>
    </select>
</mapper>

