<?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="org.dromara.system.mapper.SysTenantMapper">

    <select id="selectVoPageList" resultType="org.dromara.system.domain.vo.SysTenantVo">
        select t.id,
               t.tenant_id,
               t.company_name,
               t.tenant_organization,
               o.organization_name,
               t.contact_phone,
               t.contact_user_name,
               t.status,
               t.package_id,
               t.pc_access_path,
               t.app_access_path,
               t.register,
               t.remark,
               u.userNumber,
               b.caseNumber
        from sys_tenant t
                 left join (select tenant_id, count(1) userNumber
                            from sys_user
                            where del_flag = '0'
                            group by tenant_id) u on t.tenant_id = u.tenant_id
                 LEFT JOIN (select tenant_id, count(1) caseNumber
                            from case_base_info
                            where del_flag = '0'
                            group by tenant_id) b ON t.tenant_id = b.tenant_id
                 left join case_tenant_organization o on t.tenant_organization = o.id
            ${ew.getCustomSqlSegment}
    </select>

    <select id="themeColorList" resultType="org.dromara.system.domain.vo.SysTenantVo">
        select t.id,
               t.tenant_id,
               t.company_name,
               t.status,
               t.pc_access_path,
               t.app_access_path,
               t.theme_color,
               o.organization_name,
               o.organization_logo_str
        from sys_tenant t
                 left join case_tenant_organization o on t.tenant_organization = o.id
            ${ew.getCustomSqlSegment}
    </select>

    <select id="queryByTenantId" resultType="org.dromara.system.domain.vo.SysTenantVo">
        select t.*,
               o.organization_name,
               o.organization_logo_str
        from sys_tenant t
                 left join case_tenant_organization o on t.tenant_organization = o.id
        where t.tenant_id = #{tenantId}
    </select>
</mapper>
