fix (farm): 大屏

- 大屏模拟数据维护
This commit is contained in:
达富斌
2025-11-21 00:06:16 +08:00
parent c99967d0b9
commit e430062aa5
14 changed files with 320 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.diy.LoginForTenantReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.diy.TenantRespVO;
@@ -42,6 +43,7 @@ import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 认证")
@@ -86,11 +88,13 @@ public class AuthController {
@PermitAll
@Operation(summary = "登出系统")
public CommonResult<Boolean> logout(HttpServletRequest request) {
log.info("logout 之前: tenantId ==> {}", TenantContextHolder.getTenantId() );
String token = SecurityFrameworkUtils.obtainAuthorization(request,
securityProperties.getTokenHeader(), securityProperties.getTokenParameter());
if (StrUtil.isNotBlank(token)) {
authService.logout(token, LoginLogTypeEnum.LOGOUT_SELF.getType());
}
log.info("logout 之后: tenantId ==> {}", TenantContextHolder.getTenantId() );
return success(true);
}
@@ -166,8 +170,12 @@ public class AuthController {
@PostMapping("/login-by-tenant")
@Operation(summary = "登录 (切换租户之后调用)")
public CommonResult<AuthLoginRespVO> getPhoneNumber4Login(@RequestBody @Valid TenantTokenReqVO reqVO) {
// 强行清楚 本地线程 中的租户ID , 请设置为当前将要登录的租户ID
TenantContextHolder.clear();
TenantContextHolder.setTenantId(Long.valueOf(reqVO.getTenantId()));
AuthLoginRespVO login = authService.getPhoneNumber4Login(reqVO);
if (login != null) {
// log.info("tenantId ===> {}", getLoginUser().getTenantId());
return success(login);
} else {
return error(405, "该手机号不是平台用户");

View File

@@ -251,8 +251,9 @@ public class AdminAuthServiceImpl implements AdminAuthService {
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
// 确保租户上下文中有正确的租户ID
ensureTenantContext(userId);
// ensureTenantContext(userId);
ensureTenantContextPlus(userId);
// 创建访问令牌
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, getUserType().getValue(),
OAuth2ClientConstants.CLIENT_ID_DEFAULT, null);
@@ -274,7 +275,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
} catch (Exception e) {
log.debug("[ensureTenantContext][无法获取当前请求,跳过从请求头提取租户ID]");
}
// 如果还是为空,从用户信息中获取
if (currentTenantId == null) {
AdminUserDO user = userService.getUser(userId);
@@ -283,7 +284,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
log.info("[ensureTenantContext][从用户({})信息中获取租户ID: {}]", userId, currentTenantId);
}
}
// 设置到租户上下文中
if (currentTenantId != null) {
TenantContextHolder.setTenantId(currentTenantId);
@@ -294,6 +295,19 @@ public class AdminAuthServiceImpl implements AdminAuthService {
}
}
private void ensureTenantContextPlus(Long userId) {
// 如果TenantContextHolder中没有租户ID,尝试从用户信息中获取并设置
Long currentTenantId = TenantContextHolder.getTenantId();
// 设置到租户上下文中
if (currentTenantId != null) {
TenantContextHolder.setTenantId(currentTenantId);
log.info("[ensureTenantContext][设置租户上下文: {}]", currentTenantId);
} else {
log.warn("[ensureTenantContext][用户({}) 无法获取租户ID,可能导致登录后无法获取租户信息]", userId);
}
}
@Override
public AuthLoginRespVO refreshToken(String refreshToken) {
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT);

View File

@@ -694,6 +694,9 @@ public class AdminUserServiceImpl implements AdminUserService {
.collect(Collectors.toList());
Set<Long> userIds = permissionService.getUserRoleIdListByRoleId(roleIds);
if (null == userIds || userIds.size() == 0) {
return Collections.EMPTY_LIST;
}
List<AdminUserDO> userList = userMapper.selectByIds(userIds);
return userList;