<?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.huatek.busi.mapper.LoginMapper"> 
	<sql id="Base_User_Column_List">
		id, user_name as userName, password, user_code as userCode,  user_email as userEmail, user_phone as userPhone , 
		user_mobile as userMobile,password_salt as passwordSalt,deleted,leader,comment,group_id as groupId,
		language_type as languageType
	</sql>

	<sql id="Base_Permission_Column_List">
		p.id as id, 
		p.pname as pname, 
		p.resource_type as resourceType,
		p.permission as permission,
		p.parent_id as parentId,
		p.level as level,
		p.url as url,
		p.i_frame as iFrame,
		p.ico ico
	</sql>

	<!--用户登陆 -->
	<select id="login" parameterType="com.huatek.frame.base.dto.UserDTO" resultType="com.huatek.frame.base.vo.UserVO">
		
		select 
		<include refid="Base_User_Column_List" /> 
		from 
			sys_user 
		where 
			user_name=#{userName}
		or  
			user_email=#{userName}
		or  
			user_mobile=#{userName}
        
	</select>
	<!-- 获取用户组织 -->
	<select id="findByUserGroup" parameterType="java.lang.String" resultType="java.lang.String">
		select 
			g.group_name as groupName 
		from
			sys_user u
		left join sys_group g on u.group_id = g.id
		where u.id = #{id}
	</select>
	<!-- 获取用户角色名称 -->
	<select id="findByUserRoles" parameterType="java.lang.String" resultType="java.lang.String">
		select 
			group_concat(r.role) as roleName 
		from
			sys_user_role ur
		left join sys_role r on ur.role_id = r.id
		where ur.uid = #{id}
	</select>
</mapper>  