<?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.crm.manager.dao.mapper.SysNodeMapper">

    <select id="getSysNodesByRoleId" resultType="com.crm.rely.backend.core.pojo.view.SysNodeView" parameterType="Long">
        SELECT
        sys_node.id as id,
        `code`,
        `name`,
        pid,
        link,
        icon,
        sub_index,
        <if test="roleId!=null and roleId!=0 and roleId!=-1">
            (CASE WHEN user_role_node.id IS NULL THEN FALSE ELSE TRUE END) `show`
        </if>
        <if test="roleId==-1">
            false as `show`
        </if>
        <if test="roleId==null or roleId==0">
            TRUE as `show`
        </if>
        FROM sys_node
        <if test="roleId!=null and roleId!=0 and roleId!=-1">
            LEFT JOIN user_role_node on sys_node.id = user_role_node.node_id and user_role_node.role_id =
            #{roleId}
        </if>
        WHERE sys_node.valid = 1
        GROUP BY id
        ORDER BY sys_node.sub_index,id
    </select>


    <select id="findAllByRoleId" resultType="com.crm.rely.backend.core.pojo.table.SysNodeTable">
        select  * from  sys_node
    </select>
</mapper>