<?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.yonge.cooleshow.auth.dal.dao.SysRoleMenuDao">
	
	<resultMap type="com.yonge.cooleshow.auth.api.entity.SysRoleMenu" id="SysRoleMenu">
		<result column="id_" property="id" />
		<result column="role_id_" property="roleId" />
		<result column="menu_id_" property="menuId" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="SysRoleMenu" parameterType="java.util.Map">
		SELECT * FROM sys_role_menu WHERE role_id_ = #{roleId} AND menu_id_ = #{menuId}
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="SysRoleMenu">
		SELECT * FROM sys_role_menu ORDER BY role_id_,menu_id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.yonge.cooleshow.auth.api.entity.SysRoleMenu" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO sys_role_menu (role_id_,menu_id_) VALUES(#{roleId},#{menuId})
	</insert>
    <insert id="batchAdd">
		INSERT INTO sys_role_menu (role_id_,menu_id_) VALUES
		<foreach collection="menuIds" item="item" index="index" separator=",">
			(#{roleId},#{item})
		</foreach>
	</insert>

    <!-- 根据主键删除一条记录 -->
	<delete id="delete" parameterType="java.util.Map">
		DELETE FROM sys_role_menu WHERE role_id_ = #{roleId} AND menu_id_ = #{menuId}
	</delete>
    <delete id="deleteAllMenu">
		DELETE FROM sys_role_menu WHERE role_id_ = #{roleId}
	</delete>

    <!-- 分页查询 -->
	<select id="queryPage" resultMap="SysRoleMenu" parameterType="map">
		SELECT * FROM sys_role_menu ORDER BY role_id_,menu_id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM sys_role_menu
	</select>
	
	<select id="queryPermissionsByRoleId" resultType="string" parameterType="long">
		SELECT m.permission_ FROM sys_role_menu rm left join sys_menu m on rm.menu_id_ = m.id_ where rm.role_id_ = #{roleId} and m.del_flag_ = 0
	</select>

	<select id="queryMenuIdByRoleId" resultType="integer" parameterType="long">
		SELECT m.id_ FROM sys_role_menu rm left join sys_menu m on rm.menu_id_ = m.id_ where rm.role_id_ = #{roleId} and m.del_flag_ = 0
	</select>
</mapper>
