refactor(tenant): 优化租户管理员用户查询逻辑
- 修改TenantMapper中sys_user的关联查询方式 - 使用ROW_NUMBER窗口函数获取每个租户的第一个管理员用户 - 过滤出is_admin为1且未删除的用户,提高查询准确性 - 避免直接按照user_id关联带来的潜在数据错误 - 保持查询结果结构不变,确保兼容现有业务逻辑
This commit is contained in:
@@ -7,7 +7,16 @@
|
|||||||
SELECT a.*,b.company_name,b.company_logo as logo,b.admin_url,b.domain,b.free_domain,c.phone,c.username
|
SELECT a.*,b.company_name,b.company_logo as logo,b.admin_url,b.domain,b.free_domain,c.phone,c.username
|
||||||
FROM sys_tenant a
|
FROM sys_tenant a
|
||||||
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
|
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
|
||||||
LEFT JOIN sys_user c ON a.user_id = c.user_id
|
LEFT JOIN (
|
||||||
|
SELECT tenant_id, phone, username
|
||||||
|
FROM (
|
||||||
|
SELECT tenant_id, phone, username,
|
||||||
|
ROW_NUMBER() OVER(PARTITION BY tenant_id ORDER BY user_id) AS rn
|
||||||
|
FROM sys_user
|
||||||
|
WHERE is_admin = 1 AND deleted = 0
|
||||||
|
) t
|
||||||
|
WHERE rn = 1
|
||||||
|
) c ON a.tenant_id = c.tenant_id
|
||||||
<where>
|
<where>
|
||||||
<if test="param.tenantId != null">
|
<if test="param.tenantId != null">
|
||||||
AND a.tenant_id = #{param.tenantId}
|
AND a.tenant_id = #{param.tenantId}
|
||||||
|
|||||||
Reference in New Issue
Block a user