<?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="io.renren.modules.sys.dao.SysUserDao">
	<!-- 查询用户的所有权限 -->
	<select id="queryAllPerms" resultType="string">
		select m.perms from sys_user_role ur 
			LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id 
			LEFT JOIN sys_menu m on rm.menu_id = m.menu_id 
		where ur.user_id = #{userId}
	</select>
	
	<!-- 查询用户的所有菜单ID --> 
	<select id="queryAllMenuId" resultType="long">
		select distinct rm.menu_id from sys_user_role ur 
			LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id 
		where ur.user_id = #{userId}
	</select>
	
	<select id="queryByUserName" resultType="io.renren.modules.sys.entity.SysUserEntity">
		select * from sys_user where username = #{username}
	</select>


	<select id="page" resultType="io.renren.modules.sys.entity.vo.SysUserVo">
		SELECT
			sys_user.user_id,
			sys_user.username,
			sys_user.sex,
			sys_user.birthday,
			sys_user.email,
			sys_user.mobile,
			sys_user.status,
			sys_department.department_code,
			sys_department.department_name,
			sys_user.farm_id,
			sys_job.job_code,
			sys_job.job_name,
			sys_user.address,
			sys_user.remarks
		FROM  sys_user
			LEFT JOIN sys_department ON sys_user.department_code = sys_department.department_code
			LEFT JOIN sys_job ON sys_user.job_code = sys_job.job_code
		${ew.customSqlSegment}
	</select>

</mapper>