<?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.RoleMapper">
	<sql id="Base_Column_List">
		r.deleted as deleted,
		r.comment as comment,
		r.role as role,
		r.id as id,
		r.group_id as groupId,
		g.group_name as groupName
	</sql>

	<select id="selectRolePage" parameterType="com.huatek.frame.base.dto.RoleDTO"
		resultType="com.huatek.frame.base.vo.RoleVO">
		select
		<include refid="Base_Column_List" />
			from
		sys_role r ,sys_group g 
			where r.group_id=g.id
			and r.deleted=#{deleted}
			AND r.group_id  <![CDATA[!=]]>  '13f9e938531a4e6eb9cb2ee9d204ba90'
		<if test="role != null and  role != '' ">
			and r.role like CONCAT('%',#{role},'%')
		</if>

		<if test="comment != null and  comment != '' ">
			and r.comment like CONCAT('%',#{comment},'%')
		</if>
	</select> 
	
	
	
	<select id="findRoles"  resultType="com.huatek.frame.base.vo.RoleUserVO" parameterType="java.util.HashMap">
		select  
			case when (select count(s.uid) 
			from sys_user_role s where s.role_id = role.id 
				and s.uid = #{uid} )>0 
			then 'true' 
				else 'false' 
			end  as checked, 
			role.id as  value  , 
			role.role as title
		from  
			sys_role   role 
		where   
			role.deleted = #{deleted}  
		and 
			role.group_id=#{groupId}
	</select>
	
	<select id="findUserRoles"  resultType="com.huatek.frame.base.vo.RoleVO" parameterType="java.util.HashMap">
		select 
			user.id as  userId,role.id as id ,role.role as role ,role.`comment`  as comment  
		from sys_user user,sys_role role ,sys_user_role ur 
		where ur.role_id=role.id
		and ur.uid=user.id
		and user.deleted= #{deleted}  
		and role.deleted= #{deleted}  
		and user.id= #{id}  
	</select>
</mapper>