<?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.keyware.shandan.system.mapper.SysUserClientMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.keyware.shandan.system.entity.SysUserClient">
        <id column="USER_CLIENT_ID" property="userClientId" />
        <result column="USER_ID" property="userId" />
        <result column="CLIENT_ID" property="clientId" />
        <result column="CREATE_TIME" property="createTime" />
        <result column="MODIFY_TIME" property="modifyTime" />
        <result column="CREATE_USER" property="createUser" />
        <result column="MODIFY_USER" property="modifyUser" />
    </resultMap>

    <resultMap id="fullResultMap" type="com.keyware.shandan.system.entity.SysUserClient" extends="BaseResultMap">
        <association property="user" resultMap="com.keyware.shandan.system.mapper.SysUserMapper.BaseResultMap"/>
        <association property="client" resultMap="com.keyware.shandan.system.mapper.OauthClientDetailsMapper.BaseResultMap"/>
    </resultMap>

    <select id="listByUserId" resultMap="fullResultMap">
        select * from SYS_USER_CLIENT ur
        right join SYS_USER u on ur.USER_ID = u.USER_ID
        right join OAUTH_CLIENT_DETAILS c on ur.CLIENT_ID = c.CLIENT_ID
        where ur.USER_ID = #{userId}
        order by c.SORT asc
    </select>

</mapper>
