<?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.SysPermissionDataRuleMapper">

	<!--  查询权限 TODO 这里是不是可以不关联查找 sys_role 表 -->
	<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} and a.data_rule_ids is not null and a.data_rule_ids !=''
	</select>

	<!--添加数据规则-->
	<update id="updateDataRule" parameterType="org.jeecg.modules.system.entity.SysRolePermission">
		update sys_role_permission set data_rule_ids=#{dataRuleIds} where permission_id=#{permissionId} and role_id=#{roleId}
	</update>

	<!--查询已经授权的数据规则-->
	<select id="getDataRule" resultType="org.jeecg.modules.system.entity.SysRolePermission" parameterType="org.jeecg.modules.system.entity.SysRolePermission">
		select data_rule_ids as dataRuleIds from sys_role_permission where permission_id=#{permissionId} and role_id=#{roleId}

	</select>
</mapper>
