<?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.platform.mapper.PlatformTenantMapper">
    
    <resultMap type="com.ruoyi.common.core.domain.platform.vo.PlatformTenantVO" id="PlatformTenantResult">
        <result property="id"    column="id"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="tenantNo"    column="tenant_no"    />
        <result property="logoUrl" column="logo_url" />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />

        <result     property="userId"        column="user_id"         />
        <result property="deptId"        column="dept_id"         />
        <result property="deptName"        column="dept_name"         />
        <result property="loginName"     column="login_name"      />
        <result property="userName"      column="user_name"       />
        <result property="email"         column="email"           />
        <result property="phonenumber"   column="phonenumber"     />
        <result property="sex"           column="sex"             />
        <result property="userStatus"        column="user_status"          />
    </resultMap>

    <select id="selectByTenantId" parameterType="String" resultMap="PlatformTenantResult">
        SELECT
        pt.id, pt.tenant_name, pt.tenant_no, pt.status, pt.start_date, pt.end_date,pt.remark,pt.logo_url,
        su.id AS user_id,su.status as user_status, su.sex, su.phonenumber, su.email, su.user_name, su.login_name,
        sd.id AS dept_id, sd.dept_name
        FROM platform_tenant pt
        LEFT JOIN sys_user su ON pt.id = su.tenant_id AND su.user_type = 'yb'
        LEFT JOIN sys_dept sd ON pt.id = sd.tenant_id AND sd.dept_type = 'yb'
        WHERE pt.id = #{id}
    </select>

</mapper>