<?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.boman.system.mapper.SysUserRoleMapper">

	<resultMap type="com.boman.system.domain.SysUserRole" id="SysUserRoleResult">
		<result property="userId"     column="user_id"      />
		<result property="roleId"     column="role_id"      />
	</resultMap>

	<resultMap type="com.boman.domain.SysUser" id="SysUserResult">
		<id     property="id"       column="id"      />
		<result property="deptId"       column="dept_id"      />
		<result property="userName"     column="user_name"    />
		<result property="nickName"     column="nick_name"    />
		<result property="email"        column="email"        />
		<result property="phonenumber"  column="phonenumber"  />
		<result property="sex"          column="sex"          />
		<result property="avatar"       column="avatar"       />
		<result property="password"     column="password"     />
		<result property="status"       column="status"       />
		<result property="delFlag"      column="del_flag"     />
		<result property="loginIp"      column="login_ip"     />
		<result property="loginDate"    column="login_date"   />
		<result property="createBy"     column="create_by"    />
		<result property="createTime"   column="create_time"  />
		<result property="updateBy"     column="update_by"    />
		<result property="updateTime"   column="update_time"  />
		<result property="remark"       column="remark"       />
	</resultMap>
	<delete id="deleteUserRoleByUserId" parameterType="Long">
		delete from sys_user_role where user_id=#{userId}
	</delete>

	<select id="countUserRoleByRoleId" resultType="java.lang.Integer">
	    select count(1) from sys_user_role where role_id=#{roleId}
	</select>

	<delete id="deleteUserRole" parameterType="Long">
 		delete from sys_user_role where user_id in
 		<foreach collection="array" item="userId" open="(" separator="," close=")">
 			#{userId}
        </foreach>
 	</delete>

	<insert id="batchUserRole">
		insert into sys_user_role(user_id, role_id) values
		<foreach item="item" index="index" collection="list" separator=",">
			(#{item.userId},#{item.roleId})
		</foreach>
	</insert>

	<delete id="deleteUserRoleInfo" parameterType="com.boman.system.domain.SysUserRole">
		delete from sys_user_role where user_id=#{userId} and role_id=#{roleId}
	</delete>

	<delete id="deleteUserRoleInfos">
	    delete from sys_user_role where role_id=#{id} and user_id in
 	    <foreach collection="ids" item="userId" open="(" separator="," close=")">
 	        #{userId}
        </foreach>
	</delete>

	<select id="selectUserIdsByRoleId" resultType="Long">
		select user_id from sys_user_role where role_id = #{roleId}
	</select>

</mapper> 