refactor(login): 精简登录逻辑并移除冗余角色校验

This commit is contained in:
2026-02-03 19:25:32 +08:00
parent 1d1e45174c
commit 89fe1c2f66
3 changed files with 15 additions and 49 deletions

1
.gitignore vendored
View File

@@ -147,3 +147,4 @@ fabric.properties
/CLAUDE.md /CLAUDE.md
/API_USAGE.md /API_USAGE.md
/.omc/

View File

@@ -1,5 +1,7 @@
package com.yupi.springbootinit.model.vo.user; package com.yupi.springbootinit.model.vo.user;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
@@ -37,4 +39,12 @@ public class SystemUsersVO {
private Date aiExpireTime; private Date aiExpireTime;
private Byte aiReplay; private Byte aiReplay;
private Byte crawl;
private Byte bigBrother;
private Byte aiChat;
private Byte webAi;
} }

View File

@@ -76,9 +76,7 @@ public class LoginService {
// 1. 校验用户名、密码、状态、租户过期 // 1. 校验用户名、密码、状态、租户过期
SystemUsers user = validateUser(dto); SystemUsers user = validateUser(dto);
// 2. 按场景校验角色权限 // 2. 按场景校验角色权限
checkRole(scene, user.getId()); // checkRole(scene, user.getId());
// 3. AI_CHAT 场景专属逻辑:缓存登录状态并动态创建 RabbitMQ 队列 // 3. AI_CHAT 场景专属逻辑:缓存登录状态并动态创建 RabbitMQ 队列
if (scene.equals(LoginSceneEnum.AI_CHAT)) { if (scene.equals(LoginSceneEnum.AI_CHAT)) {
// 记录该用户已登录 AI_CHAT // 记录该用户已登录 AI_CHAT
@@ -95,44 +93,11 @@ public class LoginService {
.match(); .match();
rabbitAdmin.declareBinding(binding); rabbitAdmin.declareBinding(binding);
} }
// 3. 大哥场景专属逻辑:缓存登录状态并动态创建 RabbitMQ 队列
if (scene.equals(LoginSceneEnum.BIG_BROTHER)) {
// 记录该用户已登录 BIG_BROTHER
redisTemplate.opsForValue().set("bigbrother_login:" + user.getTenantId() + ":" + user.getId(), true);
String queueName = "b.tenant." + user.getTenantId();
// 若该租户队列尚未创建,则创建队列并绑定到 HeadersExchange
Queue queue = QueueBuilder.durable(queueName).build();
rabbitAdmin.declareQueue(queue);
Map<String, Object> headers = Map.of("tenantId", user.getTenantId(), "x-match", "all");
Binding binding = BindingBuilder
.bind(queue)
.to(bigBrotherHeadersExchange) // 使用大哥专用交换机
.whereAll(headers)
.match();
rabbitAdmin.declareBinding(binding);
}
if (scene.equals(LoginSceneEnum.WEB_AI)) {
redisTemplate.opsForValue().set("webAI_login:" + user.getTenantId() + ":" + user.getId(), true);
String queueName = "w.tenant." + user.getTenantId();
// 若该租户队列尚未创建,则创建队列并绑定到 HeadersExchange
Queue queue = QueueBuilder.durable(queueName).build();
rabbitAdmin.declareQueue(queue);
Map<String, Object> headers = Map.of("tenantId", user.getTenantId(), "x-match", "all");
Binding binding = BindingBuilder
.bind(queue)
.to(webAiHeadersExchange) // 使用webAi专用交换机
.whereAll(headers)
.match();
rabbitAdmin.declareBinding(binding);
}
SystemTenant systemTenant = tenantMapper.selectById(user.getTenantId()); SystemTenant systemTenant = tenantMapper.selectById(user.getTenantId());
// 封装返回数据 // 封装返回数据
SystemUsersVO vo = new SystemUsersVO(); SystemUsersVO vo = new SystemUsersVO();
BeanUtil.copyProperties(user, vo); BeanUtil.copyProperties(user, vo);
vo.setTokenName(StpUtil.getTokenName());
vo.setTokenValue(StpUtil.getTokenValue());
// 5. Sa-Token 登录 // 5. Sa-Token 登录
StpUtil.login(user.getId(), scene.getSaMode()); StpUtil.login(user.getId(), scene.getSaMode());
switch (scene) { switch (scene) {
@@ -144,25 +109,15 @@ public class LoginService {
vo.setAiExpireTime(systemTenant.getAiExpireTime()); vo.setAiExpireTime(systemTenant.getAiExpireTime());
return vo; return vo;
case HOST: case HOST:
StpUtil.renewTimeout(DateUtils.dateBetween(systemTenant.getExpireTime(),DateUtil.date()));
BeanUtil.copyProperties(user, vo); BeanUtil.copyProperties(user, vo);
vo.setTokenName(StpUtil.getTokenName()); vo.setTokenName(StpUtil.getTokenName());
vo.setTokenValue(StpUtil.getTokenValue()); vo.setTokenValue(StpUtil.getTokenValue());
vo.setExpireTime(systemTenant.getExpireTime()); vo.setExpireTime(systemTenant.getExpireTime());
return vo;
case BIG_BROTHER:
StpUtil.renewTimeout(DateUtils.dateBetween(systemTenant.getBrotherExpireTime(),DateUtil.date()));
BeanUtil.copyProperties(user, vo);
vo.setTokenName(StpUtil.getTokenName());
vo.setTokenValue(StpUtil.getTokenValue());
vo.setBrotherExpireTime(systemTenant.getBrotherExpireTime()); vo.setBrotherExpireTime(systemTenant.getBrotherExpireTime());
return vo;
case WEB_AI:
StpUtil.renewTimeout(DateUtils.dateBetween(systemTenant.getAiExpireTime(),DateUtil.date()));
BeanUtil.copyProperties(user, vo);
vo.setTokenName(StpUtil.getTokenName());
vo.setTokenValue(StpUtil.getTokenValue());
vo.setAiExpireTime(systemTenant.getAiExpireTime()); vo.setAiExpireTime(systemTenant.getAiExpireTime());
vo.setCrawl(user.getCrawl());
vo.setAiChat(user.getAiChat());
vo.setBigBrother(user.getBigBrother());
return vo; return vo;
} }
return null; return null;