<?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.teachcloud.common.mapper.SysRoleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.common.entity.SysRole">
    <result column="id" property="id" />
        <result column="school_id" property="schoolId" />
        <result column="name" property="name" />
        <result column="enable" property="enable" />
        <result column="type" property="type" />
        <result column="create_id" property="createId" />
        <result column="create_time" property="createTime" />
        <result column="update_id" property="updateId" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        select id, school_id, name, enable, type, create_id, create_time, update_id, update_time from sys_role
    </sql>
    <select id="listRolesByUserId" resultMap="BaseResultMap">
        SELECT distinct
            a.id,
            a.name,
            a.type
        FROM
            sys_role a
                JOIN
            sys_user_role b ON a.id = b.role_id
        WHERE
            b.user_id = #{id}
    </select>
    <select id="listPage" resultMap="BaseResultMap">
        <include refid="Base_Column_List"></include>
        <where>
            <if test="schoolId != null and schoolId != ''">
                and school_id = #{schoolId}
            </if>
            <if test="name != null and name != ''">
                and name like concat('%', #{name}, '%')
            </if>
            <if test="enable != null">
                and enable = #{enable}
            </if>
        </where>
    </select>

</mapper>
