<?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.devplatform.admin.modules.sys.dao.SysRoleDao">
  <!-- 查询用户创建的角色ID列表 -->
  <select id="queryRoleIdList" resultType="java.lang.String">
        SELECT role_id
        FROM sys_role
        WHERE deleted = 0 AND create_user_id = #{createUserId}
    </select>

  <!-- 查询用户选择的角色列表 -->
  <select id="queryUserRoleList" resultType="com.devplatform.admin.modules.sys.bean.SysRoleEntity">
        SELECT *
        FROM sys_role t1
                 LEFT JOIN sys_user_role t2 ON t1.role_id = t2.role_id
                 LEFT JOIN sys_user t3 ON t2.user_id = t3.user_id
        WHERE t1.deleted = 0
          AND t3.user_id = #{userId}
    </select>

  <!--删除用户角色关系-->
  <update id="deleteUserRole" parameterType="java.lang.String">
        DELETE
        FROM sys_user_role
        WHERE user_id = #{userId}
    </update>

</mapper>