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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.system.domain.SysPlatform">
        <id column="id" property="id" />
        <result column="platform_name" property="platformName" />
        <result column="status" property="status" />
        <result column="remark" property="remark" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="tenantKey" property="tenantKey" />
    </resultMap>

    <select id="getPlatformList" resultType="com.usky.system.service.vo.SysPlatformVo">
        SELECT
        a.*, COUNT(b.id) AS tenantCount
        FROM
        sys_platform AS a
        LEFT JOIN sys_tenant AS b ON a.id = b.system_name
        <where>
            and a.status=1
            <if test="platformName != null and platformName != ''">
                and a.platform_name LIKE CONCAT(CONCAT('%', #{platformName}), '%')
            </if>
            <if test="id != null and id != 0 and id != ''">
                and a.id = #{id}
            </if>
            <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
                and a.create_time BETWEEN #{startTime} and #{endTime}
            </if>
        </where>
        GROUP BY
        a.id
        <if test="current != null and size != null and size != 0">
            limit #{current},#{size}
        </if>
    </select>

    <select id="getMenuIdListOne" resultType="com.usky.system.domain.SysMenu">
        SELECT
        *
        FROM
        sys_menu
        WHERE
        status = 0
        AND visible = 0
        AND menu_type = #{menuType}
        AND menu_id IN
        <foreach collection="menuIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

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

    <delete id="deletePlatformMenuBy" parameterType="Long">
        delete from sys_platform_menu where platform_id=#{platformId}
    </delete>

    <delete id="deleteMobilePlatformMenuBy" parameterType="Long">
        delete from sys_mobile_platform_menu where platform_id=#{platformId}
    </delete>


    <select id="getMenuListOne"  resultType="com.usky.system.domain.SysPlatformMenu" >
        SELECT
        b.*
        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>
    </select>

</mapper>
