<?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.UserMapper">
	<sql id="Base_Column_List">

		u.id as id,
		u.user_name as userName,
		u.user_code as userCode,
		u.user_email as
		userEmail,
		u.user_phone as userPhone,
		u.user_mobile as userMobile,
		u.leader as leader,
		u.create_time as createTime,
		u.comment as comment		
	</sql>

	<select id="selectUserPage" parameterType="com.huatek.frame.base.dto.UserDTO"
		resultType="com.huatek.frame.base.vo.UserVO">
		SELECT
		<include refid="Base_Column_List" />,
		(SELECT sys_group.group_name FROM sys_group  WHERE sys_group.id =u.group_id) AS groupName,
		(SELECT GROUP_CONCAT(r.role) AS roles FROM sys_role r LEFT JOIN sys_user_role ur ON r.`id` = ur.`role_id` WHERE ur.`uid` = u.id) AS roles
	    FROM sys_user u 
		WHERE
	    u.deleted=#{deleted} 
	    AND u.user_name  <![CDATA[!=]]> 'superadmin'
		<if test="userMobile != null and userMobile != '' ">
			and u.user_mobile like concat('%',#{userMobile},'%')
		</if>
		<if test="userEmail != null and userEmail != '' ">
			and u.user_email like concat('%',#{userEmail},'%')
		</if>
		<if test="userCode != null and userCode != '' ">
			and u.user_code like concat('%',#{userCode},'%')
		</if>
		order by
		u.create_time desc
	</select>
	
	<select id="getUserByRoleId"  resultType="com.huatek.frame.base.vo.UserVO" parameterType="java.util.HashMap">
		select 
			user.id as id , user.user_name as userName,user.user_code as userCode from sys_user user,sys_user_role ur  
		where  ur.uid=user.id
		and user.deleted=#{deleted}  
		and ur.role_id=  #{roleId}  
	</select>

</mapper>