<?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.lantone.security.mapper.MenuMapper">
    <select id="getMenuById" resultType="com.lantone.security.dto.GetMenuByIdDTO">
        SELECT DISTINCT
        m.id,
        sm.software_id softwareId,
        IF (
        sm.software_id = 1,
        '运行质控',
        '终末质控'
        ) softwareName,
        m.parent_id parentId,
        pm.`name` parentName,
        m.`name`,
        m.type,
        m.`code`,
        r.url premission,
        m.order_no orderNo,
        m.menu_describe menuDescribe,
        m.remark,
        m.`status`
        FROM
        sys_software_menu sm,
        `sys_menu` m
        LEFT JOIN sys_menu pm ON pm.id = m.parent_id AND pm.is_deleted = 'N'
        LEFT JOIN sys_menu_resource mr ON mr.menu_id = m.id AND mr.is_deleted = 'N'
        LEFT JOIN sys_resource r ON mr.resource_id = r.id AND r.is_deleted = 'N'
        WHERE
        sm.menu_id = m.id
        AND m.is_deleted = 'N'
        <if test="softwareId != null ">
            AND sm.software_id = #{softwareId}
        </if>
        <if test="id != null ">
            AND m.id = #{id}
        </if>
    </select>
    <select id="getChildMenus" resultType="java.lang.Long">
        SELECT
            m.id
        FROM
            sys_menu m
        WHERE
            m.is_deleted = 'N'
        <if test="status != null and status !=''">
            AND m.`status` = #{status}
        </if>
        <if test="id !=null">
            AND FIND_IN_SET(m.id, getChildMenu(#{id}))
        </if>
    </select>
</mapper>