<?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.RoleMenuMapper">
	<resultMap id="BaseResultMap"
			   type="com.xunhong.erp.turbo.rbac.infrastructure.entity.RoleMenuDO">
		<result column="role_id" property="roleId" jdbcType="BIGINT"/>
		<result column="menu_id" property="menuId" jdbcType="BIGINT"/>

		<association property="menuDO" column="menu_id"
					 javaType="com.xunhong.erp.turbo.rbac.infrastructure.entity.MenuDO"
					 resultMap="com.xunhong.erp.turbo.rbac.infrastructure.mapper.MenuMapper.BaseResultMap"/>
	</resultMap>

	<select id="selectByRoleList"
			resultType="com.xunhong.erp.turbo.rbac.infrastructure.entity.RoleMenuDO"
			resultMap="BaseResultMap">
		select a.*,b.*
		from role_menu as a
		left join menu as b on a.menu_id = b.menu_id
		<where>
			b.is_delete = 0
			<choose>
				<when
					test="query.roleId != null and query.roleId.size() > 0">
					AND a.role_id IN
					<foreach collection="query.roleId" item="item" open="("
							 separator="," close=")">
						#{item}
					</foreach>
				</when>
				<when
					test="query.roleId != null and query.roleId.size() == 0">
					AND 1 = 0
				</when>
			</choose>
			<if test="query.platformId != null">
				AND b.platform_id = #{query.platformId}
			</if>
			ORDER BY b.sort DESC
		</where>
	</select>
</mapper>
