<?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.app.admin.framework.system.permission.authorization.dao.SysAdministratorRoleDao">
  <resultMap id="BaseResultMap" type="com.app.admin.framework.system.permission.authorization.model.SysAdministratorRole">
    <id column="oid" jdbcType="BIGINT" property="oid" />
    <result column="user_id" jdbcType="BIGINT" property="userId" />
    <result column="role_id" jdbcType="BIGINT" property="roleId" />
  </resultMap>
  <resultMap id="BaseViewResultMap" type="com.app.admin.framework.system.permission.authorization.view.SysAdministratorRoleView" extends="BaseResultMap">
    <result column="name" property="roleName" jdbcType="VARCHAR" />
  </resultMap>

  <select id="selectByUserId" resultMap="BaseViewResultMap" parameterType="map" >
    select ur.*,r.name from SYS_PERMISSION_ADMINISTRATOR_ROLE ur left join SYS_PERMISSION_ROLE r on r.OID=ur.role_id
    where ur.user_id = #{userId,jdbcType=BIGINT}
    <if test="state != null" >
      and r.STATE = #{state,jdbcType=INTEGER}
    </if>
  </select>

  <select id="getUsernameByRoleId" resultType="string" parameterType="java.lang.Long" >
    SELECT a.username FROM SYS_ADMINISTRATOR a LEFT JOIN SYS_PERMISSION_ADMINISTRATOR_ROLE ar ON ar.user_id=a.oid
    WHERE ar.role_id = #{roleId,jdbcType=BIGINT}
  </select>

</mapper>