Compare commits

..

4 Commits

Author SHA1 Message Date
f7e3cad931 feat(system): 支持分页查询租户时根据all参数控制范围
- 新增TenantParam中的all字段用于控制是否查询全部租户
- page接口根据all参数判断是否自动设置当前登录用户userId作为过滤条件
- 保持mask参数逻辑不变,支持脱敏控制
- 改进分页查询功能,增强查询灵活性和权限控制
2026-04-27 09:32:36 +08:00
6a48299e12 fix(system): 修复超级管理员用户名设置错误
- 将超级管理员用户名从随机UUID改为固定的"superAdmin"
- 确保超级管理员账户标识一致性
- 便于后续权限管理和系统维护
2026-04-27 09:25:36 +08:00
ed9d500e5d fix(system): 修正超级管理员标识及关联查询逻辑
- 将 TenantMapper.xml 中用户表连接更新为使用 gxwebsoft_core.sys_user
- 修改关联查询条件,使用 is_super_admin 替代 is_admin 标识
- 调整 User 实体中 isSuperAdmin 字段,移除@TableField注解以确保正确映射
2026-04-27 09:07:16 +08:00
64e9674d0e refactor(database): 优化租户相关SQL查询逻辑
- 移除嵌套子查询,改用子查询中取最小user_id方式关联管理员用户
- 简化管理员用户相关字段的查询逻辑,提升SQL可读性
- 直接关联sys_user表替代以前复杂多层嵌套结构
- 保持查询结果字段一致,避免影响现有功能使用
2026-04-27 07:26:47 +08:00
5 changed files with 14 additions and 10 deletions

View File

@@ -53,6 +53,15 @@ public class TenantController extends BaseController {
@Operation(summary = "分页查询租户") @Operation(summary = "分页查询租户")
@GetMapping("/page") @GetMapping("/page")
public ApiResult<PageResult<Tenant>> page(TenantParam param) { public ApiResult<PageResult<Tenant>> page(TenantParam param) {
// 如果传了 all=true查询全部租户否则自动用当前登录用户的 userId
if (param.getAll() == null || !param.getAll()) {
if (param.getUserId() == null) {
final User loginUser = getLoginUser();
if (loginUser != null && loginUser.getUserId() != null) {
param.setUserId(loginUser.getUserId());
}
}
}
PageResult<Tenant> result = tenantService.pageRel(param); PageResult<Tenant> result = tenantService.pageRel(param);
// 如果传入 mask=false设置不脱敏 // 如果传入 mask=false设置不脱敏
if (param.getMask() != null && !param.getMask()) { if (param.getMask() != null && !param.getMask()) {

View File

@@ -197,7 +197,6 @@ public class User implements UserDetails {
private Integer isOrganizationAdmin; private Integer isOrganizationAdmin;
@Schema(description = "是否超级管理员") @Schema(description = "是否超级管理员")
@TableField(exist = false)
private Boolean isSuperAdmin; private Boolean isSuperAdmin;
@Schema(description = "租户管理员ID") @Schema(description = "租户管理员ID")

View File

@@ -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 gxwebsoft_core.sys_user u ON u.tenant_id = a.tenant_id AND u.is_super_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}

View File

@@ -1,13 +1,10 @@
package com.gxwebsoft.common.system.param; package com.gxwebsoft.common.system.param;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.gxwebsoft.common.core.annotation.QueryField; import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType; import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam; import com.gxwebsoft.common.core.web.BaseParam;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@@ -56,4 +53,7 @@ public class TenantParam extends BaseParam {
@QueryField(type = QueryType.EQ) @QueryField(type = QueryType.EQ)
private Boolean mask; private Boolean mask;
@Schema(description = "查询全部租户true时忽略userId条件")
private Boolean all;
} }

View File

@@ -105,7 +105,7 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
// 添加超级管理员 // 添加超级管理员
User superAdmin = new User(); User superAdmin = new User();
superAdmin.setUsername(CommonUtil.randomUUID16()); // 使用随机用户名 superAdmin.setUsername("superAdmin");
superAdmin.setNickname(company.getShortName()); superAdmin.setNickname(company.getShortName());
superAdmin.setPhone(company.getPhone()); superAdmin.setPhone(company.getPhone());
superAdmin.setEmail(company.getEmail()); superAdmin.setEmail(company.getEmail());