<?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="org.jeecg.modules.system.mapper.SysUserMapper">
	<!--id,-->
	<!--username,-->
	<!--realname,-->
	<!--salt,-->
	<!--avatar,-->
	<!--birthday,-->
	<!--sex,-->
	<!--email,-->
	<!--phone,-->
	<!--personnel_id,-->
	<!--`status`,-->
	<!--del_flag,-->
	<!--create_by,-->
	<!--create_time,-->
	<!--update_by,-->
	<!--update_time,-->
	<select id="getPageList" resultType="org.jeecg.modules.system.entity.SysUserSelect">
		SELECT
			su.*,
			fp.name AS personnelName
		FROM
			sys_user su
			left JOIN fd_personnel fp on su.personnel_id=fp.id
			${ew.customSqlSegment}
	</select>

	<!-- 根据用户名查询 -->
	<select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
		select * from  sys_user  where username = #{username}
	</select>

	<!-- 根据用户名查询 -->
	<select id="queryRealNameByUsername" resultType="org.jeecg.modules.system.entity.SysUser">
		SELECT
			realname
		FROM
			sys_user
		WHERE
			username = #{username}
	</select>

	<select id="getUserByPerId" resultType="org.jeecg.modules.system.entity.SysUser">
		select * from sys_user su
		LEFT JOIN fd_personnel fp on su.personnel_id=fp.id
		WHERE fp.id=#{0}
	</select>

	<select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
		SELECT
			su.realname,sd.depart_name
		FROM
			`sys_user_role` sur
			LEFT JOIN sys_user su ON sur.user_id = su.id
			left join fd_personnel fp on su.personnel_id=fp.id
			left join sys_depart sd on fp.pk_depart=sd.id
		WHERE
			su.del_flag='0' AND
			sur.role_id = #{roleId}
	</select>

	<select id="getUserRole" resultType="org.jeecg.modules.system.entity.SysUser">
		SELECT
			sur.user_id as id,
			sr.role_name
		FROM
			sys_user_role sur
			LEFT JOIN sys_role sr ON sur.role_id = sr.id
		WHERE
			sr.del_flag = '0'
	</select>

</mapper>