修复租户端登录和菜单:支持 tenantCode 登录 + gdlib 菜单修正
问题1: 前端登录传 body.tenantCode(如 gdlib),但 Java 后端只从 X-Tenant-Id header 取租户ID 修复: AuthController/AuthService 支持从 tenantCode 查找租户,兼容两种方式 问题2: gdlib 租户菜单错乱(包含了超管端的活动监管/内容管理等) 修复: 重置 gdlib tenant_menus 为正确的18条: 工作台(50) + 活动管理(9+8子) + 数据统计(52+2子) + 系统设置(14+4子:机构信息/用户/角色/日志) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5b5af63f58
commit
fd9c739cf5
@ -26,11 +26,11 @@ public class AuthController {
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "登录")
|
||||
public Result<Map<String, Object>> login(@Valid @RequestBody LoginDto dto, HttpServletRequest request) {
|
||||
// 从请求头获取租户 ID
|
||||
// 优先从请求头获取租户 ID,其次从 body 的 tenantCode 查找
|
||||
String tenantIdHeader = request.getHeader("X-Tenant-Id");
|
||||
Long tenantId = tenantIdHeader != null ? Long.parseLong(tenantIdHeader) : null;
|
||||
Long tenantId = tenantIdHeader != null && !tenantIdHeader.isBlank() ? Long.parseLong(tenantIdHeader) : null;
|
||||
|
||||
return Result.success(authService.login(dto.getUsername(), dto.getPassword(), tenantId));
|
||||
return Result.success(authService.login(dto.getUsername(), dto.getPassword(), tenantId, dto.getTenantCode()));
|
||||
}
|
||||
|
||||
@GetMapping("/user-info")
|
||||
|
||||
@ -15,4 +15,7 @@ public class LoginDto {
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "租户编码(从URL提取,如 gdlib)")
|
||||
private String tenantCode;
|
||||
}
|
||||
|
||||
@ -31,8 +31,19 @@ public class AuthService {
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public Map<String, Object> login(String username, String password, Long tenantId) {
|
||||
log.info("开始登录,用户名:{},租户:{}", username, tenantId);
|
||||
public Map<String, Object> login(String username, String password, Long tenantId, String tenantCode) {
|
||||
log.info("开始登录,用户名:{},租户ID:{},租户编码:{}", username, tenantId, tenantCode);
|
||||
|
||||
// 如果没有 tenantId 但有 tenantCode,通过编码查找租户
|
||||
if (tenantId == null && tenantCode != null && !tenantCode.isBlank()) {
|
||||
SysTenant tenantByCode = tenantService.getOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SysTenant>()
|
||||
.eq(SysTenant::getCode, tenantCode)
|
||||
.eq(SysTenant::getValidState, 1), false);
|
||||
if (tenantByCode != null) {
|
||||
tenantId = tenantByCode.getId();
|
||||
}
|
||||
}
|
||||
|
||||
// 查找用户
|
||||
SysUser user = userService.findByUsername(username, tenantId);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user