<?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.ruoyi.system.mapper.SysTenantUsrRelMapper">
    <resultMap type="SysTenantUsrRel" id="SysTenantResult">
        <id property="id" column="id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="usrId" column="user_id"/>
    </resultMap>
    <sql id="selectTenantVo">
        select id, usr_id, tenant_id
        from sys_tenant_usr_rel
    </sql>
    <select id="selectTenantUsrRelList" parameterType="SysTenant" resultMap="SysTenantResult">
        <include refid="selectTenantVo"/>
        <where>
            <if test="tenantId != null and tenantId != ''">
                AND tenant_id = #{tenantId}
            </if>
        </where>
    </select>
    <select id="selectTenantUsrByUsrId" parameterType="Long" resultMap="SysTenantResult">
        select id, usr_id, tenant_id
        from sys_tenant_usr_rel
        where usr_id = #{usrId} limit 1
    </select>
    <insert id="insertTenantUsrRel" parameterType="SysTenant">
        insert into sys_tenant_usr_rel(tenant_id, usr_id)
        values (#{tenantId}, #{usrId})
    </insert>
    <delete id="deleteTenantUsrRelByUsrId" parameterType="Long">
        delete
        from sys_tenant_usr_rel
        where usr_id = #{usrId}
    </delete>
    <delete id="deleteTenantUsrRelByUsrIds" parameterType="Long">
        delete from sys_tenant_usr_rel where usr_id in
        <foreach collection="array" item="usrId" open="(" separator="," close=")">
            #{usrId}
        </foreach>
    </delete>
</mapper> 