<?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.SysRolePermissionMapper">

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

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultType="com.ho.user.entity.SysRolePermission">
        select
        <include refid="Base_Column_List"/>
        from sys_role_permission
        where id = #{id}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from sys_role_permission
    where id = #{id}
  </delete>

    <insert id="insert" parameterType="com.ho.user.entity.SysRolePermission">
    insert into sys_role_permission (role_id, permission_id,
      create_time)
    values (#{roleId}, #{permissionId},
      #{createTime,jdbcType=TIMESTAMP})
  </insert>

    <insert id="insertSelective" parameterType="com.ho.user.entity.SysRolePermission">
        insert into sys_role_permission
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="roleId != null">
                role_id,
            </if>
            <if test="permissionId != null">
                permission_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="roleId != null">
                #{roleId},
            </if>
            <if test="permissionId != null">
                #{permissionId},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.ho.user.entity.SysRolePermission">
        update sys_role_permission
        <set>
            <if test="roleId != null">
                role_id = #{roleId},
            </if>
            <if test="permissionId != null">
                permission_id = #{permissionId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id}
    </update>

    <update id="updateByPrimaryKey" parameterType="com.ho.user.entity.SysRolePermission">
    update sys_role_permission
    set role_id = #{roleId},
      permission_id = #{permissionId},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id}
  </update>

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

    <select id="getPermissionIdsByRoles" resultType="java.lang.Integer">
        SELECT permission_id
        from sys_role_permission
        <where>
            role_id in
            <foreach item="item" collection="roleIds" open="(" separator="," close=")">
                #{item}
            </foreach>

        </where>

    </select>

    <insert id="batchRolePermission" parameterType="com.ho.user.entity.SysRolePermission">
        INSERT INTO sys_role_permission (
        id,
        role_id,
        permission_id,
        create_time
        )
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.id},
            #{item.roleId},
            #{item.permissionId},
            #{item.createTime}
            )
        </foreach>
    </insert>

    <delete id="removeByPermissionId">
     DELETE
    FROM
    sys_role_permission
    WHERE
    permission_id = #{permissionId}
  </delete>

    <delete id="deleteRolePermissions">
        delete
        from  sys_role_permission
        <where>
            permission_id in
            <foreach item="item" collection="vo.permissionIds" open="(" separator="," close=")">
                #{item}
            </foreach>
            and role_id =#{vo.roleId}
        </where>
    </delete>

    <select id="getRoleIds" resultType="java.lang.Integer">
    select role_id
    from sys_role_permission
    where permission_id = #{permissionId}
  </select>

    <select id="getPermissionIdsByRoleId" resultType="java.lang.Integer">
    SELECT permission_id
    from sys_role_permission
    where role_id =#{roleId}
  </select>
</mapper>