<?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.pluss.platform.mapper.AppMenuMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.AppMenu">
        <id column="id" property="id" />
        <result column="menu_group" property="menuGroup" />
        <result column="name" property="name" />
        <result column="code" property="code" />
        <result column="icon" property="icon" />
        <result column="nav_code" property="navCode" />
        <result column="nav_name" property="navName" />
        <result column="url" property="url" />
        <result column="sort" property="sort" />
        <result column="visible" property="visible" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="isApplets" property="isApplets"/>
        <result column="isUniapp" property="isUniapp"/>
        <result column="userName" property="userName" />
        <result column="path" property="path" />
        <result column="isAndroidEnabled" property="isAndroidEnabled"/>
        <result column="isIphoneEnabled" property="isIphoneEnabled"/>
    </resultMap>

    <select id="getByNavCodeAll" resultType="cn.pluss.platform.entity.AppMenu">
        SELECT appMenu.id, appMenu.menu_group menuGroup, appMenu.name, appMenu.code, appMenu.icon,
               appMenu.nav_code navCode, appMenu.nav_name navName, appMenu.url, appMenu.sort, appMenu.visible,
               appMenu.create_time createTime, appMenu.update_time updateTime, dict.name menuGroupDesc,
               appMenu.isApplets, appMenu.userName,appMenu.path, appMenu.isUniapp
        FROM tb_pluss_app_menu appMenu
                 LEFT JOIN tb_pluss_dict dict ON appMenu.menu_group = dict.id
                 LEFT JOIN tb_pluss_app_menu_user_type amut ON amut.`name` = appMenu.`name`
        WHERE  appMenu.nav_code = #{navCode} AND amut.dictValue = #{userType}
        ORDER BY dict.sort, appMenu.sort
    </select>

    <select id="getByNavCode" resultType="cn.pluss.platform.entity.AppMenu">
        SELECT appMenu.id, appMenu.menu_group menuGroup, appMenu.name, appMenu.code, appMenu.icon,
            appMenu.nav_code navCode, appMenu.nav_name navName, appMenu.url, appMenu.sort, appMenu.visible,
            appMenu.create_time createTime, appMenu.update_time updateTime, dict.name menuGroupDesc,
            appMenu.isApplets, appMenu.userName,appMenu.path, appMenu.isUniapp
        FROM tb_pluss_app_menu appMenu
        LEFT JOIN tb_pluss_dict dict ON appMenu.menu_group = dict.id
        LEFT JOIN tb_pluss_app_menu_user_type amut ON amut.`name` = appMenu.`name`
        WHERE appMenu.visible = 1 AND appMenu.nav_code = #{navCode} AND amut.dictValue = #{userType}
        <if test="_parameter.containsKey('clientType')">
            <choose>
                <when test="clientType == 1">
                    and appMenu.isAndroidEnabled = '1'
                </when>
                <otherwise>
                    and appMenu.isIphoneEnabled = '1'
                </otherwise>
            </choose>
        </if>
        ORDER BY dict.sort, appMenu.sort
    </select>
</mapper>
