<?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.goafanti.common.dao.UserRoleMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.UserRole">
    <result column="uid" jdbcType="VARCHAR" property="uid" />
    <result column="rid" jdbcType="VARCHAR" property="rid" />
  </resultMap>
  <insert id="insert" parameterType="com.goafanti.common.model.UserRole">
    insert into user_role (uid, rid)
    values (#{uid,jdbcType=VARCHAR}, #{rid,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.UserRole">
    insert into user_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="uid != null">
        uid,
      </if>
      <if test="rid != null">
        rid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="uid != null">
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="rid != null">
        #{rid,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <delete id="deleteByRoleId" parameterType="java.lang.String">
    delete from user_role
    where rid in 
    <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
	  #{item,jdbcType=VARCHAR}  
    </foreach>
  </delete>
  
  <delete id="deleteByPrimaryKey">
    delete from user_role
    where rid = #{rid,jdbcType=VARCHAR} and uid = #{uid,jdbcType=VARCHAR}
  </delete>
  
  <delete id="deleteByUserId" parameterType="java.lang.String">
    delete from user_role
    where uid = #{userId,jdbcType=VARCHAR}  
  </delete>

  <insert id="insertBatch">
    insert into user_role (uid, rid)
    values 
    <foreach item="item" index="index" collection="roles" separator=",">
      (#{uid,jdbcType=VARCHAR}, #{item,jdbcType=VARCHAR})
    </foreach>
  </insert>
  
  <select id ="findUserIdByRoleId" parameterType="java.lang.String" resultType="java.lang.String">
    select uid from user_role where rid = #{rid, jdbcType=VARCHAR}
  </select>
  
  <select id="findUserIdByRoleIds" parameterType="java.util.List" resultType="java.lang.String">
    select uid from user_role where rid in
     <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
	  #{item,jdbcType=VARCHAR}  
    </foreach>
  </select>
  
  <select id ="listAuditor"  resultType="String">
    select uid from user_role where rid = 3
  </select>
</mapper>