<?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.common.system.mapper.CoreMapper">
	<!-- 通过字典code获取字典数据 -->
	<select id="queryDictTextByKey" parameterType="String"  resultType="String">
		   select s.item_text from sys_dict_item s
		   where s.dict_id = (select id from sys_dict where dict_code = #{code})
		   and s.item_value = #{key}
		<if test="extendsKey != null and extendsValue != null">
			and s.${extendsKey} = #{extendsValue}
		</if>
	</select>

	<!--通过查询指定table的 text code key 获取字典值-->
	<select id="queryTableDictTextByKey" parameterType="String" resultType="String">
		   select ${text} as "text" from ${table} where ${code}= #{key}
		<if test="extendsKey!=null and extendsValue!=null">
			and ${extendsKey} = #{extendsValue}
		</if>
	</select>
	<select id="queryDataRuleIds" resultType="java.lang.String">
			select data_rule_ids
			from sys_role_permission a
			join sys_permission b on a.permission_id = b.id
			join sys_role c on a.role_id = c.id
			join sys_user_role d on d.role_id = c.id
			join sys_user e on d.user_id = e.id
			where e.username = #{username} and b.id =  #{permissionId}
			<!--update begin Author:lvdandan  Date:20200213 for：加入部门权限 -->
			union
			select data_rule_ids
			from sys_depart_role_permission a
			join sys_permission b on a.permission_id = b.id
			join sys_depart_role c on a.role_id = c.id
			join sys_depart_role_user d on d.drole_id = c.id
			join sys_user e on d.user_id = e.id
			where e.username = #{username} and b.id = #{permissionId}
			<!--update end Author:lvdandan  Date:20200213 for：加入部门权限 -->
	</select>
	<select id="selectSysPermissionDataRuleList"
			resultType="org.jeecg.common.system.entity.SysPermissionDataRule">
		select * from sys_permission_data_rule
		where 1 = 1
		and staus = #{status}
		and id in
		<foreach collection="idList" item="item" separator=","
				 open="(" close=")">
			#{item}
		</foreach>
	</select>
    <select id="queryDictItemsByCode" resultType="org.jeecg.common.system.vo.DictModel">
		select s.item_value as "value",s.item_text as "text" from sys_dict_item s
		where dict_id = (select id from sys_dict where dict_code = #{code})
		order by s.sort_order asc
	</select>
	<select id="queryTableDictItemsByCode" resultType="org.jeecg.common.system.vo.DictModel">
		select ${text} as "text",${code} as "value" from ${table}
	</select>
</mapper>
