<?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.usky.system.mapper.SysPlatformMenuMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.system.domain.SysPlatformMenu">
        <id column="platform_id" property="platformId" />
        <result column="menu_id" property="menuId" />
    </resultMap>

    <select id="getMenuList"  resultType="com.usky.system.domain.SysMenu" >
        SELECT
        a.*
        FROM
        sys_menu AS a
        JOIN sys_platform_menu AS b ON a.menu_id = b.menu_id
        WHERE
            b.platform_id = #{platformId}
        <if test="menuType != null and menuType != ''">
            AND a.menu_type = #{menuType}
        </if>
        order by a.parent_id, a.order_num
    </select>

    <select id="getMobileMenuList"  resultType="com.usky.system.domain.SysMobileMenu" >
        SELECT
        a.*
        FROM
        sys_mobile_menu AS a
        JOIN sys_mobile_platform_menu AS b ON a.menu_id = b.menu_id
        WHERE
        b.platform_id = #{platformId}
        <if test="menuType != null and menuType != ''">
            AND a.menu_type = #{menuType}
        </if>
        order by a.parent_id, a.order_num
    </select>

    <select id="getMenuIdList" resultType="com.usky.system.domain.SysMenu">
        SELECT
        a.*
        FROM
        sys_menu AS a
        JOIN sys_platform_menu AS b ON a.menu_id = b.menu_id
        WHERE
        a.status = 0
        AND a.visible = 0
        AND a.menu_type = #{menuType}
        <if test="menuIds != null and menuIds.length > 0">
            AND a.menu_id IN
            <foreach collection="menuIds" item="item" open="(" separator="," close=")">
                ${item}
            </foreach>
        </if>
        group by a.menu_id
    </select>

    <select id="getMobileMenuIdList" resultType="com.usky.system.domain.SysMobileMenu">
        SELECT
        a.*
        FROM
        sys_mobile_menu AS a
        JOIN sys_mobile_platform_menu AS b ON a.menu_id = b.menu_id
        WHERE
        a.status = 0
        AND a.visible = 0
        AND a.menu_type = #{menuType}
        <if test="menuIds != null and menuIds.length > 0">
            AND a.menu_id IN
            <foreach collection="menuIds" item="item" open="(" separator="," close=")">
                ${item}
            </foreach>
        </if>
        group by a.menu_id
    </select>

    <delete id="deleteTenantMenuBy" parameterType="Long">
        delete from sys_tenant_menu where tenant_id=#{tenantId}
    </delete>

    <delete id="deleteMobileTenantMenuBy" parameterType="Long">
        delete from sys_mobile_tenant_menu where tenant_id=#{tenantId}
    </delete>


    <select id="getMenuListOne"  resultType="com.usky.system.domain.SysTenantMenu" >
        SELECT
        b.*
        FROM
        sys_menu AS a
        JOIN sys_tenant_menu AS b ON a.menu_id = b.menu_id
        WHERE
        b.tenant_id = #{tenantId}
        <if test="menuType != null and menuType != ''">
            AND a.menu_type = #{menuType}
        </if>
    </select>


</mapper>
