RoleMapper.xml 2.98 KB
<?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.reyun.saas.mob.user.dao.RoleMapper">
    <resultMap id="BaseResultMap" type="com.reyun.saas.mob.user.domain.Role">
      <id column="id" jdbcType="BIGINT" property="id" />
      <result column="name" jdbcType="VARCHAR" property="name" />
      <result column="description" jdbcType="VARCHAR" property="description" />
      <result column="seq" jdbcType="INTEGER" property="seq" />
      <result column="status" jdbcType="INTEGER" property="status" />
      <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
      <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    </resultMap>

    <resultMap id="RoleDTOMap" type="com.reyun.saas.mob.user.dto.role.RoleDTO">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="description" jdbcType="VARCHAR" property="description" />
        <result column="seq" jdbcType="INTEGER" property="seq" />
        <result column="status" jdbcType="INTEGER" property="status" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />

       <!--权限列表-->
       <collection property="menus" ofType="com.reyun.saas.mob.user.domain.MenuRight" javaType="java.util.ArrayList">
           <id column="mid" jdbcType="BIGINT" property="id" />
           <result column="mparent_id" jdbcType="BIGINT" property="parentId" />
           <result column="mname" jdbcType="VARCHAR" property="name" />
           <result column="method" jdbcType="VARCHAR" property="method" />
           <result column="url" jdbcType="VARCHAR" property="url" />
           <result column="icon" jdbcType="VARCHAR" property="icon" />
           <result column="grades" jdbcType="INTEGER" property="grades" />
           <result column="mseq" jdbcType="INTEGER" property="seq" />
           <result column="mstatus" jdbcType="INTEGER" property="status" />
           <result column="mcreate_time" jdbcType="TIMESTAMP" property="createTime" />
           <result column="mmodify_time" jdbcType="TIMESTAMP" property="modifyTime" />
       </collection>
    </resultMap>

    <!-- 获取角色和权限信息 -->
    <select id="getMenusByRoleId" resultMap="RoleDTOMap">
       select
        r.*,
        m.id as mid,
        m.parent_id as mparent_id,
        m.name mname,
        m.method,
        m.url,
        m.icon,
        m.status mstatus,
        m.grades,
        m.seq as mseq,
        m.create_time as mcreate_time,
        m.modify_time as mmodify_time
        from role r
        left join role_right rr
            on rr.role_id = r.id
        left join menu_right m
            on rr.menu_id = m.id
        where r.id = #{id}
        and r.status = 1
        order by m.id ASC
    </select>

</mapper>