<?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.xhkjedu.suser.mapper.system.RoleModuleMapper">

    <!-- 角色下所有模块 -->
    <select id="listRoleModules" resultType="com.xhkjedu.suser.vo.system.RoleModuleVo">
        SELECT rm.moduleid,rm.belongcode,m.modulename,m.moduleurl,m.moduleico,m.modulepid,m.minout,m.mclass,m.level
        FROM t_role_module rm LEFT JOIN t_module m ON rm.moduleid=m.moduleid
        WHERE rm.roleid=#{roleid} and m.display=1 ORDER BY m.level,m.morder,m.moduleid
    </select>

    <!-- 批量保存角色模块信息 -->
    <insert id="saveBathRoleModule">
        INSERT INTO t_role_module (roleid,moduleid,belongcode,createid,createtime,schoolid) VALUES
        <foreach collection ="list" item="rm" index= "index" separator =",">
            (#{rm.roleid},#{rm.moduleid},#{rm.belongcode},#{rm.createid},#{rm.createtime},#{rm.schoolid})
        </foreach>
    </insert>

    <!-- 根据角色删除模块信息 -->
    <delete id="deleteByRoleid" parameterType="java.lang.Integer">
        delete from t_role_module where roleid=#{roleid}
    </delete>

    <!--获取用户拥有的所有模块-->
    <select id="listModulesByUserid" resultType="com.xhkjedu.suser.vo.system.RoleModuleVo">
        SELECT DISTINCT rm.moduleid,m.modulename,m.moduleurl,m.moduleico,m.modulepid,m.morder,m.minout,
        m.mclass,m.level,m.mabbrevname
        FROM t_role_module rm LEFT JOIN t_module m ON rm.moduleid=m.moduleid
        LEFT JOIN t_user_role ur ON rm.roleid=ur.roleid
        WHERE userid=#{userid} and m.display=1
        <if test="belongcode!=null and belongcode == 1">and rm.belongcode in (1,3)</if>
        <if test="belongcode!=null and belongcode == 2">and rm.belongcode in (2,3)</if>
        ORDER BY m.level,m.morder,m.moduleid
    </select>
</mapper>
