<?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.kmall.common.dao.SysRoleDeptDao">

	<insert id="save">
		insert into sys_role_dept
		(
			`role_id`, 
			`dept_id`
		)
		values
		<foreach collection="deptIdList" item="item" index="index" separator="," >
		(
			#{roleId}, 
			#{item} 
		)
		</foreach>
	</insert>
	
	<delete id="delete">
		delete from sys_role_dept where role_id = #{value}
	</delete>
	
	<select id="queryDeptIdList" resultType="long">
		select dept_id from sys_role_dept where role_id = #{value}
	</select>

	<select id="queryDeptIdListByUserId" resultType="long">
		select dept_id from sys_role_dept where role_id IN (SELECT role_id FROM SYS_USER_ROLE WHERE user_id =  #{value})
	</select>
</mapper>