refactor(database): 优化租户相关SQL查询逻辑
- 移除嵌套子查询,改用子查询中取最小user_id方式关联管理员用户 - 简化管理员用户相关字段的查询逻辑,提升SQL可读性 - 直接关联sys_user表替代以前复杂多层嵌套结构 - 保持查询结果字段一致,避免影响现有功能使用
This commit is contained in:
@@ -8,11 +8,7 @@
|
|||||||
u.phone,u.username
|
u.phone,u.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 u ON u.tenant_id = a.tenant_id AND u.is_admin = 1
|
LEFT JOIN sys_user u ON u.tenant_id = a.tenant_id AND u.is_admin = 1 AND u.deleted = 0
|
||||||
AND u.user_id = (
|
|
||||||
SELECT MIN(user_id) FROM sys_user
|
|
||||||
WHERE tenant_id = a.tenant_id AND is_admin = 1 AND deleted = 0
|
|
||||||
)
|
|
||||||
<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