<?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.zsc.edu.gateway.modules.system.repo.RoleRepository">
    <resultMap id="roleMap" type="com.zsc.edu.gateway.modules.system.vo.RoleVo" autoMapping="true">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
        <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
        <result column="create_time" jdbcType="DATE" property="createTime"/>
        <result column="update_time" jdbcType="DATE" property="updateTime"/>
        <result column="enabled" jdbcType="BIT" property="enabled"/>
        <result column="remark" jdbcType="VARCHAR" property="roleRemark"/>
        <collection property="menus" ofType="com.zsc.edu.gateway.modules.system.entity.Menu" autoMapping="true"
                    columnPrefix="menu_">
            <id column="id" jdbcType="BIT" property="id"/>
            <result column="permissions" jdbcType="VARCHAR" property="permissions"/>
            <result column="remark" jdbcType="VARCHAR" property="remark"/>
        </collection>
    </resultMap>

    <select id="selectRoleById" resultMap="roleMap">
        select sr.*,
               sm.id          AS menu_id,
               sm.permissions AS menu_permissions,
               sm.remark      AS menu_remark
        from sys_role sr
                 left join sys_role_menu srm on sr.id = srm.role_id
                 left join sys_menu sm on srm.menu_id = sm.id
        where sr.id=#{roleId}
    </select>

    <select id="getRoleIdByName" resultType="java.lang.Long">
        select sr.id from sys_role sr
        where sr.name=#{roleName}
    </select>

</mapper>
