<?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.ym.mec.biz.dal.dao.SysUserTenantDao">
    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.SysUserTenant">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="user_id_" jdbcType="INTEGER" property="userId"/>
        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
        <result column="created_by_" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , user_id_, tenant_id_, created_by_, created_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.ym.mec.biz.dal.entity.SysUserTenant">
        insert into sys_user_tenant(user_id_, tenant_id_, created_by_, created_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.userId}, #{entity.tenantId}, #{entity.createdBy}, #{entity.createdTime})
        </foreach>
    </insert>

    <select id="queryUserTenant" resultType="com.ym.mec.biz.dal.vo.SysUserTenantVo">
        select
            a.id_ as id,
            a.user_id_ as userId,
            b.id_ as tenantId,
            b.name_ as tenantName
        from sys_user_tenant as a
                 left join tenant_info as b on a.tenant_id_ = b.id_
        where a.user_id_ = #{userId}
    </select>

</mapper>
