<?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.xunhong.erp.turbo.rbac.infrastructure.mapper.PermissionMapper">
	<resultMap id="BaseResultMap"
			   type="com.xunhong.erp.turbo.rbac.infrastructure.entity.PermissionDO">
		<result property="permissionId" column="permission_id"/>
		<result property="slug" column="slug"/>
		<result property="name" column="name"/>
		<result property="createdAt" column="created_at"/>
		<result property="updatedAt" column="updated_at"/>
		<result property="isDelete" column="is_delete"/>
		<result property="version" column="version"/>
	</resultMap>
	<select id="listByRoleList"
			resultType="com.xunhong.erp.turbo.rbac.infrastructure.entity.PermissionDO">
		select a.*
		from permission as a
		left join role_permission as b on a.permission_id = b.permission_id
		left join role as c on b.role_id = c.role_id
		<where>
			a.is_delete = 0
			<if test="query.roleSlugList!= null and query.roleSlugList.size() > 0">
				and c.slug in
				<foreach collection="query.roleSlugList" item="item" open="("
						 separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="query.roleIdList!= null and query.roleIdList.size() > 0">
				and c.role_id in
				<foreach collection="query.roleIdList" item="item" open="("
						 separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="query.platformId">
				and c.platform_id = #{query.platformId}
			</if>
		</where>
	</select>
</mapper>
