<?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.platform.dao.SysUserRoleDao">

	<select id="queryList" resultType="com.platform.entity.SysUserRoleEntity">
		select * from sys_user_role 
		<where>
			<if test="userId != null">
				user_id = #{userId}
			</if>
		</where>
	</select>
 
	<insert id="save">
		insert into sys_user_role
		(
			`user_id`, 
			`role_id`
		)
		values
		<foreach collection="roleIdList" item="item" index="index" separator="," >
		(
			#{userId}, 
			#{item}
		)
		</foreach>
	</insert>

	<insert id="saveOne" >
		insert into sys_user_role
		(
		`user_id`,
		`role_id`
		)
		values
		(
			#{userId},
			#{roleId}
		)
	</insert>
	
	<delete id="delete">
		delete from sys_user_role where user_id = #{value}
	</delete>
	
	<select id="queryRoleIdList" resultType="long">
		select role_id from sys_user_role where user_id = #{value}
	</select>
</mapper>