<?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.ho.user.mapper.SysUserRoleMapper">

  <sql id="Base_Column_List">
    id, user_id, role_id, create_time
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultType="com.ho.user.entity.SysUserRole">
    select 
    <include refid="Base_Column_List" />
    from sys_user_role
    where id = #{id,jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from sys_user_role
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <insert id="insert" parameterType="com.ho.user.entity.SysUserRole">
    insert into sys_user_role (user_id, role_id,
      create_time)
    values (#{userId,jdbcType=VARCHAR}, #{roleId,jdbcType=INTEGER},
      #{createTime,jdbcType=TIMESTAMP})
  </insert>

  <insert id="insertSelective" parameterType="com.ho.user.entity.SysUserRole">
    insert into sys_user_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userId != null">
        user_id,
      </if>
      <if test="roleId != null">
        role_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="roleId != null">
        #{roleId,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <insert id="batchUserRole" parameterType="com.ho.user.entity.SysUserRole">
    INSERT INTO sys_user_role (
    id,
    role_id,
    user_id,
    create_time
    )
    VALUES
    <foreach item="item" collection="list" index="index" separator=",">
      (
      #{item.id},
      #{item.roleId},
      #{item.userId},
      #{item.createTime}
      )
    </foreach>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.ho.user.entity.SysUserRole">
    update sys_user_role
    <set>
      <if test="userId != null">
        user_id = #{userId,jdbcType=VARCHAR},
      </if>
      <if test="roleId != null">
        role_id = #{roleId,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.ho.user.entity.SysUserRole">
    update sys_user_role
    set user_id = #{userId,jdbcType=VARCHAR},
      role_id = #{roleId,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="removeByRoleId">
    DELETE
    FROM
    sys_user_role
    WHERE
    role_id = #{roleId}
  </delete>

  <select id="getRoleIdsByUserId" resultType="java.lang.Integer">
    SELECT role_id
    from sys_user_role
    where user_id =#{userId}
  </select>


  <delete id="removeByUserId">
    delete
    from sys_user_role
    where user_id=#{userId}
  </delete>


    <delete id="removeByUserIds">
      delete
      from sys_user_role
      where  user_id  in
      <foreach collection="list" open="(" close=")" separator="," item="item">
        #{item}
      </foreach>
    </delete>


  <select id="getInfoByUserIdByRoleId" resultType="java.lang.String">
    select user_id
    from sys_user_role
    where   role_id=#{roleId}
  </select>


  <select id="getUserIdsByRoleIds" resultType="java.lang.String">
    select user_id
    from sys_user_role
    where role_id in
    <foreach collection="list" open="(" close=")" separator="," item="item">
      #{item}
    </foreach>
  </select>
</mapper>