<?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.fuzamei.mapperInterface.UserAuthoricationMapper"> 
	
	<!-- 查询出一个userId号下的用户所有详细信息包括基本信息，还有角色，权限信息 -->
	<select id="queryUserDetailInformation" resultMap="UserDetailRM">
		select 
			tu.id,
			tu.user_id,
			tu.account,
			tu.password,
			tu.random,
			tu.public_key,
			tu.private_key,
			tu.organization_name,
			tu.person_name,
			tu.account_balance,
			tu.update_time,
			tu.create_time,
			tr.role_name,
			tp.authority_name,
			ai.id as id2,
			ai.account_id,
			ai.account_name,
			ai.account_type,
			ai.money
		from 
			(select 
				*
			from 
				t_user
			where 
				user_id=#{userId}) tu
		left join 
			user_role ur
		on 
			tu.user_id=ur.user_id
		left join 
			t_role tr
		on 
			ur.role_id=tr.role_id
		left join 
			role_permission rp 
		on 
			rp.role_id = tr.role_id
		left join 
			t_permission tp
		on 
			tp.authority_id=rp.authority_id
		left join 
			user_account ua
		on 
			tu.user_id=ua.user_id
		left join 
			account_info ai
		on 
			ai.account_id=ua.account_id
	</select>
	<!-- 专门针对queryUserDetailInformation返回值结果用的 -->
	<resultMap type="com.fuzamei.entity.UserDetail" id="UserDetailRM" autoMapping="true">
		<id column="id" property="id"/>
		<collection property="role_name" ofType="java.lang.String" javaType="java.util.ArrayList">
			<constructor>
				<arg column="role_name"/>
			</constructor>
		</collection>
		<collection property="authority_name" ofType="java.lang.String" javaType="java.util.ArrayList">
			<constructor>
				<arg column="authority_name"/>
			</constructor>
		</collection>
		<collection property="account_info_list" resultMap="AccountInfoRM"></collection>
	</resultMap>
	
	<resultMap type="com.fuzamei.entity.AccountInfo" id="AccountInfoRM" autoMapping="true">
		<id column="id2" property="id"/>
	</resultMap>
	
</mapper>
