<?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.qmth.sop.business.mapper.SysRoleMapper">

    <select id="listRolesByUserId" resultType="com.qmth.sop.business.bean.dto.RoleDto">
        SELECT distinct
            a.id,
            a.name,
            a.type,
            a.default_role,
            a.enable
        FROM
            sys_role a
            <if test="userId != null and userId != ''">
                JOIN sys_user_role b ON a.id = b.role_id
            </if>
        <where>
            <if test="userId != null and userId != ''">
                and b.user_id = #{userId}
            </if>
            and a.type <![CDATA[ <> ]]> 'ADMIN'
        </where>
    </select>

    <select id="query" resultType="com.qmth.sop.business.bean.dto.RoleDto">
        select t.id, t.name, t.enable, t.type, t.default_role from sys_role t
        <where>
            <if test="name != null and name != ''">
                and t.name like concat('%', #{name}, '%')
            </if>
            <if test="enable != null and enable != '' or enable == 0">
                and t.enable = #{enable}
            </if>
                and t.type <![CDATA[ <> ]]> 'ADMIN'
        </where>
        ORDER BY t.update_time desc
    </select>
</mapper>
