<?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.UserRoleMapper">
	<resultMap id="BaseResultMap"
			   type="com.xunhong.erp.turbo.rbac.infrastructure.entity.UserRoleDO">
		<result property="userId" column="user_id"/>
		<result property="roleId" column="role_id"/>
		<association property="roleDO" column="role_id"
					 javaType="com.xunhong.erp.turbo.rbac.infrastructure.entity.RoleDO"
					 resultMap="com.xunhong.erp.turbo.rbac.infrastructure.mapper.RoleMapper.BaseResultMap"/>
	</resultMap>
	<select id="getByUserId"
			resultType="com.xunhong.erp.turbo.rbac.infrastructure.entity.UserRoleDO">
		SELECT *
		FROM user_role
		WHERE user_id = #{userId}
	</select>
	<select id="listByUserId"
			resultType="com.xunhong.erp.turbo.rbac.infrastructure.entity.UserRoleDO"
			resultMap="BaseResultMap">
		SELECT a.*, b.*
		FROM user_role as a
		LEFT JOIN role as b ON a.role_id = b.role_id
		WHERE a.user_id = #{userId}
		and b.is_delete = 0
	</select>
	<select id="selectList"
			resultType="com.xunhong.erp.turbo.rbac.infrastructure.entity.UserRoleDO"
			resultMap="BaseResultMap">
		SELECT a.user_id, b.*
		FROM user_role as a
		LEFT JOIN role as b ON a.role_id = b.role_id
		<where>
			and b.is_delete = 0
			<if test="ew!= null">
				<if test="ew.nonEmptyOfWhere">
					AND
				</if>
				${ew.sqlSegment}
			</if>
		</where>
	</select>
</mapper>
