<?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.frame.base.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>

	<!--用户登陆 -->
	<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> 
	

	<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="findByUserId" parameterType="java.lang.String" resultType="com.huatek.frame.base.vo.PermissionVO">
		select 
			<include refid="Base_Permission_Column_List" /> 
		from
			sys_user u
		inner join
			sys_user_role ur
		on
			ur.uid=u.id
		inner join
			sys_role r
		on
			r.id=ur.role_id
		inner join
			sys_role_permission rp
		on
			rp.rid=r.id
		inner join
			sys_permission p
		on
			rp.permission_id =p.id 
		where
			u.id=#{id}
		and 
			p.deleted=#{deleted} 
		and 
			u.deleted=#{deleted}
		group by 
			p.permission
	</select>
</mapper>  