<?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.pj.project4sp.role4permission.SpRolePermissionMapper">


	<!-- 增 -->
	<insert id="add" >
		insert into 
		sp_role_permission(role_id, permission_code, create_time) 
		values (#{roleId}, #{pcode}, now())
	</insert>
    <insert id="saveRolePer">
		insert into sp_role_permission(role_id,permission_code,create_time) values
		<foreach collection="list" item="perCode" separator=",">
			(#{roleId},#{perCode},now())
		</foreach>
	</insert>

    <!-- 删除指定角色的所有权限 -->
	<delete id="deleteByRoleId">
		delete from sp_role_permission
		where role_id = #{roleId} 
	</delete>
    <delete id="removeByRoleIds">
        delete  from  sp_role_permission
        where role_id in
        <foreach collection="list" separator="," item="roleId" open="(" close=")">
            #{roleId}
        </foreach>
    </delete>

    <!-- 指定roleId的所有权限码   -->
	<select id="getPcodeByRoleId" resultType="java.lang.String">
		select permission_code from sp_role_permission
		where role_id in
		<foreach collection="list" item="roleId" open="(" close=")" separator=",">
			#{roleId}
		</foreach>
	</select>
	<select id="getAdminPcode" resultType="java.lang.String">
		select permission_code from tb_permission
	</select>


</mapper>
