<?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.sunyard.ssp.modules.user.mapper.ScUserRoleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.sunyard.ssp.modules.user.entity.ScUserRole">
        <result column="ID" property="id" />
        <result column="ROLE_ID" property="roleId" />
        <result column="USER_ID" property="userId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ID, ROLE_ID, USER_ID
    </sql>

    <select id="findByUserId" resultType="com.sunyard.ssp.modules.user.entity.ScRole">
      SELECT r.id id, name, r.data_type
      FROM sc_user_role ur
      LEFT JOIN sc_role r
      ON ur.role_id = r.id
      WHERE user_Id = #{userId}
    </select>

    <select id="findDepIdsByUserId" resultType="java.lang.String">
        SELECT DISTINCT rd.department_id
        FROM sc_role_department rd
        WHERE role_id IN
        ( SELECT ur.role_id FROM sc_user_role ur WHERE ur.user_id = #{userId} )
    </select>
</mapper>
